mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
Merge pull request #179 from stvleung/master
Added cleanup capability for 9p shared folders
This commit is contained in:
commit
9d83c32452
@ -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
|
||||
|
@ -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
|
||||
|
@ -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: |-
|
||||
|
Loading…
Reference in New Issue
Block a user