[DRE-commits] [vagrant-libvirt] 04/17: Cleanup nfs config for Vagrant 1.4+

Antonio Terceiro terceiro at moszumanska.debian.org
Sun Apr 24 13:56:16 UTC 2016


This is an automated email from the git hooks/post-receive script.

terceiro pushed a commit to annotated tag 0.0.15
in repository vagrant-libvirt.

commit 25fe1ea2c206bcc621c185f994104d38b56eda63
Author: Jason DeTiberus <jdetiber at redhat.com>
Date:   Thu Jan 23 13:46:44 2014 -0500

    Cleanup nfs config for Vagrant 1.4+
    
    Fix checks if a synced_folder should be nfs or not
    
    Reorder up and start actions
---
 lib/vagrant-libvirt/action.rb                      | 23 ++++++++++++++--------
 lib/vagrant-libvirt/action/prepare_nfs_settings.rb | 22 +++++++++++----------
 .../action/prepare_nfs_valid_ids.rb                | 17 ++++++++++++++++
 lib/vagrant-libvirt/action/share_folders.rb        |  5 +----
 lib/vagrant-libvirt/action/sync_folders.rb         |  2 +-
 5 files changed, 46 insertions(+), 23 deletions(-)

diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb
index 164476b..6e752ed 100644
--- a/lib/vagrant-libvirt/action.rb
+++ b/lib/vagrant-libvirt/action.rb
@@ -1,10 +1,12 @@
 require 'vagrant/action/builder'
+require 'log4r'
 
 module VagrantPlugins
   module ProviderLibvirt
     module Action
       # Include the built-in modules so we can use them as top-level things.
       include Vagrant::Action::Builtin
+      @logger = Log4r::Logger.new('vagrant_libvirt::action') 
 
       # This action is called to bring the box up from nothing.
       def self.action_up
@@ -25,9 +27,13 @@ module VagrantPlugins
               b2.use CreateNetworks
               b2.use CreateNetworkInterfaces
 
+              b2.use StartDomain
+              b2.use WaitTillUp
+
               if Vagrant::VERSION < "1.4.0"
                 b2.use NFS
               else
+                b2.use PrepareNFSValidIds
                 b2.use SyncedFolderCleanup
                 b2.use SyncedFolders
               end
@@ -35,8 +41,6 @@ module VagrantPlugins
               b2.use PrepareNFSSettings
               b2.use ShareFolders
               b2.use SetHostname
-              b2.use StartDomain
-              b2.use WaitTillUp
               b2.use SyncFolders
             else
               b2.use action_start
@@ -68,22 +72,24 @@ module VagrantPlugins
               # Ensure networks are created and active
               b3.use CreateNetworks
 
+              # Start it..
+              b3.use StartDomain
+
+              # Machine should gain IP address when comming up,
+              # so wait for dhcp lease and store IP into machines data_dir.
+              b3.use WaitTillUp
+
               # Handle shared folders
               if Vagrant::VERSION < "1.4.0"
                 b3.use NFS
               else
+                b3.use PrepareNFSValidIds
                 b3.use SyncedFolderCleanup
                 b3.use SyncedFolders
               end
               b3.use PrepareNFSSettings
               b3.use ShareFolders
 
-              # Start it..
-              b3.use StartDomain
-
-              # Machine should gain IP address when comming up,
-              # so wait for dhcp lease and store IP into machines data_dir.
-              b3.use WaitTillUp
             end
           end
         end
@@ -308,6 +314,7 @@ module VagrantPlugins
       autoload :MessageNotRunning, action_root.join('message_not_running')
       autoload :MessageNotSuspended, action_root.join('message_not_suspended')
       autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
+      autoload :PrepareNFSValidIds, action_root.join('prepare_nfs_valid_ids')
       autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
       autoload :ReadSSHInfo, action_root.join('read_ssh_info')
       autoload :ReadState, action_root.join('read_state')
diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb
index 75a2e75..7b28d60 100644
--- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb
+++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb
@@ -9,25 +9,27 @@ module VagrantPlugins
         end
 
         def call(env)
+          @machine = env[:machine]
           @app.call(env)
 
-          using_nfs = false
-          env[:machine].config.vm.synced_folders.each do |id, opts|
-            if opts[:nfs]
-              using_nfs = true
-              break
-            end
-          end
-
-          if using_nfs
+          if using_nfs?
             @logger.info("Using NFS, preparing NFS settings by reading host IP and machine IP")
             env[:nfs_host_ip]    = read_host_ip(env[:machine],env)
             env[:nfs_machine_ip] = env[:machine].ssh_info[:host]
 
-            raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip]
+            @logger.info("host IP: #{env[:nfs_host_ip]} machine IP: #{env[:nfs_machine_ip]}")
+
+            raise Vagrant::Errors::NFSNoHostonlyNetwork if !env[:nfs_machine_ip] || !env[:nfs_host_ip]
           end
         end
 
+        # We're using NFS if we have any synced folder with NFS configured. If
+        # we are not using NFS we don't need to do the extra work to
+        # populate these fields in the environment.
+        def using_nfs?
+          @machine.config.vm.synced_folders.any? { |_, opts| opts[:type] == :nfs }
+        end
+
         # Returns the IP address of the first host only network adapter
         #
         # @param [Machine] machine
diff --git a/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb b/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb
new file mode 100644
index 0000000..0eaf69d
--- /dev/null
+++ b/lib/vagrant-libvirt/action/prepare_nfs_valid_ids.rb
@@ -0,0 +1,17 @@
+module VagrantPlugins
+  module ProviderLibvirt
+    module Action
+      class PrepareNFSValidIds
+        def initialize(app, env)
+          @app = app
+          @logger = Log4r::Logger.new("vagrant::action::vm::nfs")
+        end
+
+        def call(env)
+          env[:nfs_valid_ids] = env[:libvirt_compute].servers.all.map(&:id)
+          @app.call(env)
+        end
+      end
+    end
+  end
+end
diff --git a/lib/vagrant-libvirt/action/share_folders.rb b/lib/vagrant-libvirt/action/share_folders.rb
index 027451a..71b25ce 100644
--- a/lib/vagrant-libvirt/action/share_folders.rb
+++ b/lib/vagrant-libvirt/action/share_folders.rb
@@ -26,10 +26,7 @@ module VagrantPlugins
           {}.tap do |result|
             @env[:machine].config.vm.synced_folders.each do |id, data|
               # Ignore NFS shared folders
-              next if !data[:nfs]
-
-              # convert to NFS share
-              #data[:nfs] = true
+              next if !data[:type] == :nfs
 
               # This to prevent overwriting the actual shared folders data
               result[id] = data.dup
diff --git a/lib/vagrant-libvirt/action/sync_folders.rb b/lib/vagrant-libvirt/action/sync_folders.rb
index 0ba0c60..862622b 100644
--- a/lib/vagrant-libvirt/action/sync_folders.rb
+++ b/lib/vagrant-libvirt/action/sync_folders.rb
@@ -18,7 +18,7 @@ module VagrantPlugins
           ssh_info = env[:machine].ssh_info
 
           env[:machine].config.vm.synced_folders.each do |id, data|
-            next if data[:nfs]
+            next if data[:type] == :nfs
             proxycommand = "-o ProxyCommand='#{ssh_info[:proxy_command]}'" if ssh_info[:proxy_command]
             hostpath  = File.expand_path(data[:hostpath], env[:root_path])
             guestpath = data[:guestpath]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git



More information about the Pkg-ruby-extras-commits mailing list