Drivers now take a UUID

This commit is contained in:
Mitchell Hashimoto 2011-12-18 22:43:20 -08:00
parent a8e4e62264
commit c59defa7e8
5 changed files with 24 additions and 20 deletions

View File

@ -12,7 +12,7 @@ module Vagrant
def call(env)
# Use the raw interface for now, while the virtualbox gem
# doesn't support guest properties (due to cross platform issues)
version = env[:vm].driver.guest_additions_version(env[:vm].uuid)
version = env[:vm].driver.read_guest_additions_version
if !version
env[:ui].warn I18n.t("vagrant.actions.vm.check_guest_additions.not_detected")
else

View File

@ -8,7 +8,7 @@ module Vagrant
def call(env)
env[:ui].info I18n.t("vagrant.actions.vm.destroy.destroying")
env[:vm].driver.delete(env[:vm].uuid)
env[:vm].driver.delete
env[:vm].uuid = nil
@app.call(env)

View File

@ -11,8 +11,7 @@ module Vagrant
# Create the proc which we want to use to modify the virtual machine
env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching")
env[:vm].driver.set_mac_address(env[:vm].uuid,
env[:vm].config.vm.base_mac)
env[:vm].driver.set_mac_address(env[:vm].config.vm.base_mac)
@app.call(env)
end

View File

@ -10,7 +10,9 @@ module Vagrant
# The version of virtualbox that is running.
attr_reader :version
def initialize
def initialize(uuid)
@uuid = uuid
# Read and assign the version of VirtualBox we know which
# specific driver to instantiate.
begin
@ -35,21 +37,21 @@ module Vagrant
end
# This deletes the VM with the given name.
def delete(uuid)
execute("unregistervm", uuid, "--delete")
def delete
execute("unregistervm", @uuid, "--delete")
end
# This reads the guest additions version for a VM.
def guest_additions_version(uuid)
output = execute("guestproperty", "get", uuid, "/VirtualBox/GuestAdd/Version")
def read_guest_additions_version
output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version")
return $1.to_s if output =~ /^Value: (.+?)$/
return nil
end
# This reads the state for the given UUID. The state of the VM
# will be returned as a symbol.
def read_state(uuid)
output = execute("showvminfo", uuid, "--machinereadable")
def read_state
output = execute("showvminfo", @uuid, "--machinereadable")
if output =~ /^name="<inaccessible>"$/
return :inaccessible
elsif output =~ /^VMState="(.+?)"$/
@ -60,8 +62,8 @@ module Vagrant
end
# This sets the MAC address for a network adapter.
def set_mac_address(uuid, mac)
execute("modifyvm", uuid, "--macaddress1", mac)
def set_mac_address(mac)
execute("modifyvm", @uuid, "--macaddress1", mac)
end
protected

View File

@ -20,12 +20,13 @@ module Vagrant
@env = env
@config = config
@box = env.boxes.find(config.vm.box)
@driver = Driver::VirtualBox.new
# Look for the VM if it exists
# Load the UUID if its saved.
active = env.local_data[:active] || {}
@uuid = active[@name.to_s]
# @vm = VirtualBox::VM.find(@uuid) if @uuid
# Reload ourselves to get the state
reload!
# Load the associated guest.
load_guest!
@ -78,7 +79,7 @@ module Vagrant
# @return [Symbol]
def state
return :not_created if !@uuid
state = @driver.read_state(@uuid)
state = @driver.read_state
return :not_created if !state
return state
end
@ -96,8 +97,6 @@ module Vagrant
# to persist the VM. Otherwise, it will remove itself from the
# local data (if it exists).
def uuid=(value)
@uuid = value
env.local_data[:active] ||= {}
if value
env.local_data[:active][name.to_s] = value
@ -108,10 +107,14 @@ module Vagrant
# Commit the local data so that the next time vagrant is initialized,
# it realizes the VM exists
env.local_data.commit
# Store the uuid and reload the instance
@uuid = value
reload!
end
def reload!
@vm = VirtualBox::VM.find(@vm.uuid)
@driver = Driver::VirtualBox.new(@uuid)
end
def package(options=nil)