Set the name as a separate step. [GH-669]
This commit is contained in:
parent
195a0d6999
commit
8d6a33584f
|
@ -10,6 +10,8 @@
|
|||
properly created if they don't exist. [GH-667]
|
||||
- Fix the precedence for Arch, Ubuntu, and FreeBSD host classes so
|
||||
they are properly detected. [GH-683]
|
||||
- Fix issue where VM import sometimes made strange VirtualBox folder
|
||||
layouts. [GH-669]
|
||||
|
||||
## 0.9.3 (January 24, 2012)
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ module Vagrant
|
|||
autoload :ClearNetworkInterfaces, 'vagrant/action/vm/clear_network_interfaces'
|
||||
autoload :ClearSharedFolders, 'vagrant/action/vm/clear_shared_folders'
|
||||
autoload :Customize, 'vagrant/action/vm/customize'
|
||||
autoload :DefaultName, 'vagrant/action/vm/default_name'
|
||||
autoload :Destroy, 'vagrant/action/vm/destroy'
|
||||
autoload :DestroyUnusedNetworkInterfaces, 'vagrant/action/vm/destroy_unused_network_interfaces'
|
||||
autoload :DiscardState, 'vagrant/action/vm/discard_state'
|
||||
|
|
|
@ -85,6 +85,7 @@ module Vagrant
|
|||
use VM::CheckBox
|
||||
use VM::Import
|
||||
use VM::CheckGuestAdditions
|
||||
use VM::DefaultName
|
||||
use VM::MatchMACAddress
|
||||
use registry.get(:start)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
require 'log4r'
|
||||
|
||||
module Vagrant
|
||||
module Action
|
||||
module VM
|
||||
class DefaultName
|
||||
def initialize(app, env)
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::defaultname")
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@logger.info("Setting the default name of the VM")
|
||||
name = env[:root_path].basename.to_s + "_#{Time.now.to_i}"
|
||||
env[:vm].driver.set_name(name)
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,9 +10,8 @@ module Vagrant
|
|||
env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => env[:vm].box.name)
|
||||
|
||||
# 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
|
||||
env[:vm].uuid = env[:vm].driver.import(ovf_file, name) do |progress|
|
||||
env[:vm].uuid = env[:vm].driver.import(ovf_file) do |progress|
|
||||
env[:ui].clear_line
|
||||
env[:ui].report_progress(progress, 100, false)
|
||||
end
|
||||
|
|
|
@ -94,6 +94,7 @@ module Vagrant
|
|||
:read_used_ports,
|
||||
:read_vms,
|
||||
:set_mac_address,
|
||||
:set_name,
|
||||
:share_folders,
|
||||
:ssh_port,
|
||||
:start,
|
||||
|
|
|
@ -9,7 +9,7 @@ module Vagrant
|
|||
def initialize(uuid)
|
||||
super()
|
||||
|
||||
@logger = Log4r::Logger.new("vagrant::driver::virtualbox_4_1")
|
||||
@logger = Log4r::Logger.new("vagrant::driver::virtualbox_4_0")
|
||||
@uuid = uuid
|
||||
end
|
||||
|
||||
|
@ -147,11 +147,15 @@ module Vagrant
|
|||
execute("controlvm", @uuid, "poweroff")
|
||||
end
|
||||
|
||||
def import(ovf, name)
|
||||
def import(ovf)
|
||||
output = ""
|
||||
total = ""
|
||||
last = 0
|
||||
execute("import", ovf, "--vsys", "0", "--vmname", name) do |type, data|
|
||||
if type == :stderr
|
||||
execute("import", ovf) do |type, data|
|
||||
if type == :stdout
|
||||
# Keep track of the stdout so that we can get the VM name
|
||||
output << data
|
||||
elsif type == :stderr
|
||||
# Append the data so we can see the full view
|
||||
total << data
|
||||
|
||||
|
@ -171,6 +175,14 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# Find the name of the VM name
|
||||
if output !~ /Suggested VM name "(.+?)"/
|
||||
@logger.error("Couldn't find VM name in the output.")
|
||||
return nil
|
||||
end
|
||||
|
||||
name = $1.to_s
|
||||
|
||||
output = execute("list", "vms")
|
||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
||||
return $1.to_s
|
||||
|
@ -374,6 +386,10 @@ module Vagrant
|
|||
execute("modifyvm", @uuid, "--macaddress1", mac)
|
||||
end
|
||||
|
||||
def set_name(name)
|
||||
execute("modifyvm", @uuid, "--name", name)
|
||||
end
|
||||
|
||||
def share_folders(folders)
|
||||
folders.each do |folder|
|
||||
execute("sharedfolder", "add", @uuid, "--name",
|
||||
|
|
|
@ -147,11 +147,15 @@ module Vagrant
|
|||
execute("controlvm", @uuid, "poweroff")
|
||||
end
|
||||
|
||||
def import(ovf, name)
|
||||
def import(ovf)
|
||||
output = ""
|
||||
total = ""
|
||||
last = 0
|
||||
execute("import", ovf, "--vsys", "0", "--vmname", name) do |type, data|
|
||||
if type == :stderr
|
||||
execute("import", ovf) do |type, data|
|
||||
if type == :stdout
|
||||
# Keep track of the stdout so that we can get the VM name
|
||||
output << data
|
||||
elsif type == :stderr
|
||||
# Append the data so we can see the full view
|
||||
total << data
|
||||
|
||||
|
@ -171,6 +175,14 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# Find the name of the VM name
|
||||
if output !~ /Suggested VM name "(.+?)"/
|
||||
@logger.error("Couldn't find VM name in the output.")
|
||||
return nil
|
||||
end
|
||||
|
||||
name = $1.to_s
|
||||
|
||||
output = execute("list", "vms")
|
||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
||||
return $1.to_s
|
||||
|
@ -374,6 +386,10 @@ module Vagrant
|
|||
execute("modifyvm", @uuid, "--macaddress1", mac)
|
||||
end
|
||||
|
||||
def set_name(name)
|
||||
execute("modifyvm", @uuid, "--name", name)
|
||||
end
|
||||
|
||||
def share_folders(folders)
|
||||
folders.each do |folder|
|
||||
execute("sharedfolder", "add", @uuid, "--name",
|
||||
|
|
|
@ -133,9 +133,8 @@ module Vagrant
|
|||
# Imports the VM from an OVF file.
|
||||
#
|
||||
# @param [String] ovf Path to the OVF file.
|
||||
# @param [String] name Name of the VM.
|
||||
# @return [String] UUID of the imported VM.
|
||||
def import(ovf, name)
|
||||
def import(ovf)
|
||||
end
|
||||
|
||||
# Returns a list of forwarded ports for a VM.
|
||||
|
|
Loading…
Reference in New Issue