From bde81a15a22a49b6e6362ba8352750a0e422258d Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 28 Apr 2020 16:22:34 +0100 Subject: [PATCH] Remove NFS exports on domain destroy (#781) Uncomment NFS prune action If the user has not configured NFS for any of the synced folders, then it is likely they are not expecting to be asked for a sudo password on destroy. Move the test for using NFS to a common module and include in both the preparing and pruning actions. Co-authored-by: Darragh Bailey --- lib/vagrant-libvirt/action.rb | 2 +- .../action/prepare_nfs_settings.rb | 9 +------ .../action/prune_nfs_exports.rb | 25 ++++++++++++------- lib/vagrant-libvirt/util/nfs.rb | 17 +++++++++++++ 4 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 lib/vagrant-libvirt/util/nfs.rb 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 +