From 16cccd504a05ad2effd9b1da9851cf7f81bcd2f5 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 10 Dec 2019 11:05:22 -0800 Subject: [PATCH] Add virtualbox driver method for obtaining vm information --- .../providers/virtualbox/cap/configure_disks.rb | 9 ++++++--- plugins/providers/virtualbox/driver/base.rb | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/providers/virtualbox/cap/configure_disks.rb b/plugins/providers/virtualbox/cap/configure_disks.rb index f45f24b4e..2074d1a55 100644 --- a/plugins/providers/virtualbox/cap/configure_disks.rb +++ b/plugins/providers/virtualbox/cap/configure_disks.rb @@ -8,6 +8,7 @@ module VagrantPlugins # @param [VagrantPlugins::Kernel_V2::VagrantConfigDisk] defined_disks def self.configure_disks(machine, defined_disks) return nil if defined_disks.empty? + disks = current_vm_disks(machine) end protected @@ -15,13 +16,15 @@ module VagrantPlugins # Maybe move these into the virtualbox driver?? # Versioning might be an issue :shrug: - def current_vm_disks(driver) + def self.current_vm_disks(machine) + disks = {} + info = machine.provider.driver.show_vm_info(machine.id) end - def vmdk_to_vdi(driver) + def self.vmdk_to_vdi(driver) end - def vdi_to_vmdk(driver) + def self.vdi_to_vmdk(driver) end end end diff --git a/plugins/providers/virtualbox/driver/base.rb b/plugins/providers/virtualbox/driver/base.rb index 8f07c4bac..23f29cd6d 100644 --- a/plugins/providers/virtualbox/driver/base.rb +++ b/plugins/providers/virtualbox/driver/base.rb @@ -368,6 +368,21 @@ module VagrantPlugins def vm_exists?(uuid) end + # Returns a hash of information about a given virtual machine + # + # @param [String] uuid + # @return [Hash] info + def show_vm_info(uuid) + info = {} + execute('showvminfo', uuid, '--machinereadable', retryable: true).split("\n").each do |line| + parts = line.partition('=') + key = parts.first.gsub('"', '') + value = parts.last.gsub('"', '') + info[key] = value + end + info + end + # Execute the given subcommand for VBoxManage and return the output. def execute(*command, &block) # Get the options hash if it exists