diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb index 4dea598..d6f73e5 100644 --- a/lib/vagrant-libvirt/action.rb +++ b/lib/vagrant-libvirt/action.rb @@ -187,7 +187,7 @@ module VagrantPlugins b2.use Call, DestroyConfirm do |env2, b3| if env2[:result] b3.use ClearForwardedPorts - # b3.use PruneNFSExports + b3.use PruneNFSExports b3.use DestroyDomain b3.use DestroyNetworks b3.use ProvisionerCleanup diff --git a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb index b07543e..5828595 100644 --- a/lib/vagrant-libvirt/action/prepare_nfs_settings.rb +++ b/lib/vagrant-libvirt/action/prepare_nfs_settings.rb @@ -6,7 +6,7 @@ module VagrantPlugins module ProviderLibvirt module Action class PrepareNFSSettings - include Vagrant::Action::Builtin::MixinSyncedFolders + include VagrantPlugins::ProviderLibvirt::Util::Nfs def initialize(app, _env) @app = app @@ -28,13 +28,6 @@ module VagrantPlugins 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? - !!synced_folders(@machine)[:nfs] - end - # Returns the IP address of the host # # @param [Machine] machine diff --git a/lib/vagrant-libvirt/action/prune_nfs_exports.rb b/lib/vagrant-libvirt/action/prune_nfs_exports.rb index 2dc577a..4061681 100644 --- a/lib/vagrant-libvirt/action/prune_nfs_exports.rb +++ b/lib/vagrant-libvirt/action/prune_nfs_exports.rb @@ -3,20 +3,27 @@ module VagrantPlugins module ProviderLibvirt module Action class PruneNFSExports + include VagrantPlugins::ProviderLibvirt::Util::Nfs + def initialize(app, _env) @app = app end def call(env) - if env[:host] - uuid = env[:machine].id - # get all uuids - uuids = env[:machine].provider.driver.connection.servers.all.map(&:id) - # not exiisted in array will removed from nfs - uuids.delete(uuid) - env[:host].capability( - :nfs_prune, env[:machine].ui, uuids - ) + @machine = env[:machine] + + if using_nfs? + @logger.info('Using NFS, prunning NFS settings from host') + if env[:host] + uuid = env[:machine].id + # get all uuids + uuids = env[:machine].provider.driver.connection.servers.all.map(&:id) + # not exiisted in array will removed from nfs + uuids.delete(uuid) + env[:host].capability( + :nfs_prune, env[:machine].ui, uuids + ) + end end @app.call(env) diff --git a/lib/vagrant-libvirt/util/nfs.rb b/lib/vagrant-libvirt/util/nfs.rb new file mode 100644 index 0000000..d4857c0 --- /dev/null +++ b/lib/vagrant-libvirt/util/nfs.rb @@ -0,0 +1,17 @@ +module VagrantPlugins + module ProviderLibvirt + module Util + module Nfs + include Vagrant::Action::Builtin::MixinSyncedFolders + + # 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? + !!synced_folders(@machine)[:nfs] + end + end + end + end +end +