From cb3cc42dce5af1621e241d8ecd6ffa180f93e097 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 17 Jan 2020 15:03:17 -0800 Subject: [PATCH] Determine primary disk through vm_info rather than list_hdds --- plugins/providers/virtualbox/cap/configure_disks.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/providers/virtualbox/cap/configure_disks.rb b/plugins/providers/virtualbox/cap/configure_disks.rb index e2845a48c..ae5fcee57 100644 --- a/plugins/providers/virtualbox/cap/configure_disks.rb +++ b/plugins/providers/virtualbox/cap/configure_disks.rb @@ -51,11 +51,17 @@ module VagrantPlugins # @param [Hash] - disk_metadata def self.handle_configure_disk(machine, disk, all_disks) disk_metadata = {} + # Grab the existing configured disk, if it exists current_disk = nil if disk.primary - # TODO: This instead might need to be determined through the show_vm_info data instead - current_disk = all_disks.first + # Ensure we grab the proper primary disk + # We can't rely on the order of `all_disks`, as they will not + # always come in port order, but primary is always Port 0 Device 0. + vm_info = machine.provider.driver.show_vm_info + primary_uuid = vm_info["SATA Controller-ImageUUID-0-0"] + + current_disk = all_disks.select { |d| d["UUID"] == primary_uuid }.first else current_disk = all_disks.select { |d| d["Disk Name"] == disk.name}.first end