Scan storage controllers for DVD cleanup

This commit is contained in:
Jeff Bonhag 2020-05-28 11:37:31 -04:00
parent 8739c04aa9
commit 2e879aa06f
No known key found for this signature in database
GPG Key ID: 32966F3FB5AC1129

View File

@ -26,8 +26,8 @@ module VagrantPlugins
# @param [VagrantPlugins::Kernel_V2::VagrantConfigDisk] defined_disks
# @param [Hash] disk_meta - A hash of all the previously defined disks from the last configure_disk action
def self.handle_cleanup_disk(machine, defined_disks, disk_meta)
storage_controller = machine.provider.driver.storage_controllers.detect { |c| c[:type] == "IntelAhci" }
primary_disk = storage_controller[:attachments].detect { |a| a[:port] == "0" && a[:device] == "0" }[:uuid]
sata_controller = machine.provider.driver.storage_controllers.detect { |c| c[:type] == "IntelAhci" }
primary_disk = sata_controller[:attachments].detect { |a| a[:port] == "0" && a[:device] == "0" }[:uuid]
unless disk_meta.nil?
disk_meta.each do |d|
@ -43,6 +43,7 @@ module VagrantPlugins
if disk_info.empty?
LOGGER.warn("Disk '#{d["name"]}' not attached to guest, but still exists.")
else
# TODO: write test for sata controller with another name
machine.provider.driver.remove_disk(disk_info[:port], disk_info[:device])
end
@ -56,8 +57,7 @@ module VagrantPlugins
# @param [VagrantPlugins::Kernel_V2::VagrantConfigDisk] defined_dvds
# @param [Hash] dvd_meta - A hash of all the previously defined dvds from the last configure_disk action
def self.handle_cleanup_dvd(machine, defined_dvds, dvd_meta)
controller = "IDE Controller"
vm_info = machine.provider.driver.show_vm_info
ide_controller = machine.provider.driver.storage_controllers.detect { |c| c[:type] == "PIIX4" }
unless dvd_meta.nil?
dvd_meta.each do |d|
@ -66,13 +66,10 @@ module VagrantPlugins
next
else
LOGGER.warn("Found dvd not in Vagrantfile config: '#{d["name"]}'. Removing dvd from guest #{machine.name}")
(0..1).each do |port|
(0..1).each do |device|
if d["uuid"] == vm_info["#{controller}-ImageUUID-#{port}-#{device}"]
machine.ui.warn("DVD '#{d["name"]}' no longer exists in Vagrant config. Removing medium from guest...", prefix: true)
machine.provider.driver.remove_disk(port.to_s, device.to_s, controller)
end
end
attachments = ide_controller[:attachments].select { |a| a[:uuid] == d["uuid"] }
attachments.each do |attachment|
machine.ui.warn("DVD '#{d["name"]}' no longer exists in Vagrant config. Removing medium from guest...", prefix: true)
machine.provider.driver.remove_disk(attachment[:port].to_s, attachment[:device].to_s, ide_controller[:name])
end
end
end