[DRE-commits] [vagrant-libvirt] 43/77: Added cleanup capability for 9p mounts

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


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

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

commit bf79f2a76df950fb93aa6a85072a22d508a15611
Author: Steven Leung <sleung at iparadigms.com>
Date:   Wed Apr 30 17:17:18 2014 -0700

    Added cleanup capability for 9p mounts
    
    This will allow proper halting, and reloading
---
 lib/vagrant-libvirt/cap/synced_folder.rb | 30 +++++++++++++++++++++++++-----
 lib/vagrant-libvirt/errors.rb            |  4 ++++
 locales/en.yml                           |  2 ++
 3 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/lib/vagrant-libvirt/cap/synced_folder.rb b/lib/vagrant-libvirt/cap/synced_folder.rb
index 17ccb93..0bc285e 100644
--- a/lib/vagrant-libvirt/cap/synced_folder.rb
+++ b/lib/vagrant-libvirt/cap/synced_folder.rb
@@ -1,5 +1,6 @@
 require "log4r"
 require 'ostruct'
+require 'nokogiri'
 
 
 require "vagrant/util/subprocess"
@@ -35,8 +36,8 @@ module VagrantPlugins
           # loop through folders
           folders.each do |id, folder_opts|
             folder_opts.merge!({ :accessmode => "passthrough",
-                                :readonly => true })
-            # machine.ui.info "================\nMachine id: #{machine.id}Should be mounting folders\n #{id}, opts: #{folder_opts}"
+                                :readonly => nil })
+            machine.ui.info "================\nMachine id: #{machine.id}\nShould be mounting folders\n #{id}, opts: #{folder_opts}"
 
             xml =  to_xml('filesystem', folder_opts )
             # puts "<<<<< XML:\n #{xml}\n >>>>>"
@@ -44,7 +45,7 @@ module VagrantPlugins
 
           end 
         rescue => e
-          # machine.ui.error("could not attach device because: #{e}")
+          machine.ui.error("could not attach device because: #{e}")
           raise VagrantPlugins::ProviderLibvirt::Errors::AttachDeviceError,:error_message => e.message
         end
       end
@@ -67,9 +68,28 @@ module VagrantPlugins
             :mount_p9_shared_folder, mount_folders, common_opts)
       end
 
-      def cleanup(machine, opts)
-        # driver(machine).clear_shared_folders if machine.id && machine.id != ""
+      def cleanup(machine, _opts)
+
+        raise Vagrant::Errors::Error("No libvirt connection") if ProviderLibvirt.libvirt_connection.nil?
+
+        @conn = ProviderLibvirt.libvirt_connection.client
+ 
+        begin
+          if machine.id && machine.id != ""
+            dom = @conn.lookup_domain_by_uuid(machine.id)
+            Nokogiri::XML(dom.xml_desc).xpath('/domain/devices/filesystem').each do |xml|
+              dom.detach_device(xml.to_s)
+
+              machine.ui.info "Cleaned up shared folders"
+            end
+          end
+        rescue => e
+          machine.ui.error("could not detach device because: #{e}")
+          raise VagrantPlugins::ProviderLibvirt::Errors::DetachDeviceError,:error_message => e.message
+        end
+
       end
+
     end
   end
 end
diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb
index 2121f90..6f2ae82 100644
--- a/lib/vagrant-libvirt/errors.rb
+++ b/lib/vagrant-libvirt/errors.rb
@@ -122,6 +122,10 @@ module VagrantPlugins
         error_key(:attach_device_error)
       end
 
+      class DetachDeviceError < VagrantLibvirtError
+        error_key(:detach_device_error)
+      end
+
       class NoIpAddressError < VagrantLibvirtError
         error_key(:no_ip_address_error)
       end
diff --git a/locales/en.yml b/locales/en.yml
index 71035ce..9aa3534 100644
--- a/locales/en.yml
+++ b/locales/en.yml
@@ -99,6 +99,8 @@ en:
         No domain found. %{error_message}
       attach_device_error: |-
         Error while attaching new device to domain. %{error_message}
+      detach_device_error: |-
+        Error while detaching device from domain. %{error_message}
       no_ip_address_error: |-
         No IP address found.
       management_network_error: |-

-- 
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