Make more things VBoxManage compatible

This commit is contained in:
Mitchell Hashimoto 2011-12-18 22:12:21 -08:00
parent 96868e5d29
commit a8e4e62264
7 changed files with 16 additions and 43 deletions

View File

@ -34,7 +34,6 @@ module Vagrant
autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports' autoload :ClearNFSExports, 'vagrant/action/vm/clear_nfs_exports'
autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders' autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders'
autoload :Customize, 'vagrant/action/vm/customize' autoload :Customize, 'vagrant/action/vm/customize'
autoload :DefaultName, 'vagrant/action/vm/default_name'
autoload :Destroy, 'vagrant/action/vm/destroy' autoload :Destroy, 'vagrant/action/vm/destroy'
autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces' autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces'
autoload :DiscardState, 'vagrant/action/vm/discard_state' autoload :DiscardState, 'vagrant/action/vm/discard_state'

View File

@ -83,7 +83,6 @@ module Vagrant
use VM::Import use VM::Import
use VM::MatchMACAddress use VM::MatchMACAddress
use VM::CheckGuestAdditions use VM::CheckGuestAdditions
use VM::DefaultName
use registry.get(:start) use registry.get(:start)
end end
end end

View File

@ -13,7 +13,7 @@ module Vagrant
# Use the raw interface for now, while the virtualbox gem # Use the raw interface for now, while the virtualbox gem
# doesn't support guest properties (due to cross platform issues) # doesn't support guest properties (due to cross platform issues)
version = env[:vm].driver.guest_additions_version(env[:vm].uuid) version = env[:vm].driver.guest_additions_version(env[:vm].uuid)
if version.empty? if !version
env[:ui].warn I18n.t("vagrant.actions.vm.check_guest_additions.not_detected") env[:ui].warn I18n.t("vagrant.actions.vm.check_guest_additions.not_detected")
else else
# Strip the -OSE/_OSE off from the guest additions and the virtual box # Strip the -OSE/_OSE off from the guest additions and the virtual box

View File

@ -1,24 +0,0 @@
module Vagrant
module Action
module VM
# This action sets the default name of a virtual machine. The default
# name is the CWD of the environment plus a timestamp.
class DefaultName
def initialize(app, env)
@app = app
end
def call(env)
# Create the proc to setup the default name
proc = lambda do |vm|
vm.name = File.basename(env[:vm].env.cwd) + "_#{Time.now.to_i}"
end
env["vm.modify"].call(proc)
@app.call(env)
end
end
end
end
end

View File

@ -10,8 +10,9 @@ module Vagrant
env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => env[:vm].box.name) env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => env[:vm].box.name)
# Import the virtual machine # Import the virtual machine
name = File.basename(env[:vm].env.cwd) + "_#{Time.now.to_i}"
ovf_file = env[:vm].box.directory.join("box.ovf").to_s ovf_file = env[:vm].box.directory.join("box.ovf").to_s
env[:vm].uuid = env[:vm].driver.import(ovf_file) do |progress| env[:vm].uuid = env[:vm].driver.import(ovf_file, name) do |progress|
env[:ui].clear_line env[:ui].clear_line
env[:ui].report_progress(progress.percent, 100, false) env[:ui].report_progress(progress.percent, 100, false)
end end

View File

@ -10,13 +10,9 @@ module Vagrant
raise Errors::VMBaseMacNotSpecified if !env[:vm].config.vm.base_mac raise Errors::VMBaseMacNotSpecified if !env[:vm].config.vm.base_mac
# Create the proc which we want to use to modify the virtual machine # Create the proc which we want to use to modify the virtual machine
proc = lambda do |vm| env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching")
env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching") env[:vm].driver.set_mac_address(env[:vm].uuid,
vm.network_adapters.first.mac_address = env[:vm].config.vm.base_mac env[:vm].config.vm.base_mac)
end
# Add the proc to the modification chain
env["vm.modify"].call(proc)
@app.call(env) @app.call(env)
end end

View File

@ -24,14 +24,11 @@ module Vagrant
# Imports the VM with the given path to the OVF file. It returns # Imports the VM with the given path to the OVF file. It returns
# the UUID as a string. # the UUID as a string.
def import(ovf) def import(ovf, name)
output = execute("import", ovf) execute("import", ovf, "--vsys", "0", "--vmname", name)
if output =~ /VM name "(.+?)"/ output = execute("list", "vms")
name = $1.to_s if output =~ /^"#{name}" {(.+?)}$/
output = execute("list", "vms") return $1.to_s
if output =~ /^"#{name}" {(.+?)}$/
return $1.to_s
end
end end
nil nil
@ -62,6 +59,11 @@ module Vagrant
nil nil
end end
# This sets the MAC address for a network adapter.
def set_mac_address(uuid, mac)
execute("modifyvm", uuid, "--macaddress1", mac)
end
protected protected
# This returns the version of VirtualBox that is running. # This returns the version of VirtualBox that is running.