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]
|
properly created if they don't exist. [GH-667]
|
||||||
- Fix the precedence for Arch, Ubuntu, and FreeBSD host classes so
|
- Fix the precedence for Arch, Ubuntu, and FreeBSD host classes so
|
||||||
they are properly detected. [GH-683]
|
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)
|
## 0.9.3 (January 24, 2012)
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ module Vagrant
|
||||||
autoload :ClearNetworkInterfaces, 'vagrant/action/vm/clear_network_interfaces'
|
autoload :ClearNetworkInterfaces, 'vagrant/action/vm/clear_network_interfaces'
|
||||||
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'
|
||||||
|
|
|
@ -85,6 +85,7 @@ module Vagrant
|
||||||
use VM::CheckBox
|
use VM::CheckBox
|
||||||
use VM::Import
|
use VM::Import
|
||||||
use VM::CheckGuestAdditions
|
use VM::CheckGuestAdditions
|
||||||
|
use VM::DefaultName
|
||||||
use VM::MatchMACAddress
|
use VM::MatchMACAddress
|
||||||
use registry.get(:start)
|
use registry.get(:start)
|
||||||
end
|
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)
|
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, name) do |progress|
|
env[:vm].uuid = env[:vm].driver.import(ovf_file) do |progress|
|
||||||
env[:ui].clear_line
|
env[:ui].clear_line
|
||||||
env[:ui].report_progress(progress, 100, false)
|
env[:ui].report_progress(progress, 100, false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -94,6 +94,7 @@ module Vagrant
|
||||||
:read_used_ports,
|
:read_used_ports,
|
||||||
:read_vms,
|
:read_vms,
|
||||||
:set_mac_address,
|
:set_mac_address,
|
||||||
|
:set_name,
|
||||||
:share_folders,
|
:share_folders,
|
||||||
:ssh_port,
|
:ssh_port,
|
||||||
:start,
|
:start,
|
||||||
|
|
|
@ -9,7 +9,7 @@ module Vagrant
|
||||||
def initialize(uuid)
|
def initialize(uuid)
|
||||||
super()
|
super()
|
||||||
|
|
||||||
@logger = Log4r::Logger.new("vagrant::driver::virtualbox_4_1")
|
@logger = Log4r::Logger.new("vagrant::driver::virtualbox_4_0")
|
||||||
@uuid = uuid
|
@uuid = uuid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -147,11 +147,15 @@ module Vagrant
|
||||||
execute("controlvm", @uuid, "poweroff")
|
execute("controlvm", @uuid, "poweroff")
|
||||||
end
|
end
|
||||||
|
|
||||||
def import(ovf, name)
|
def import(ovf)
|
||||||
|
output = ""
|
||||||
total = ""
|
total = ""
|
||||||
last = 0
|
last = 0
|
||||||
execute("import", ovf, "--vsys", "0", "--vmname", name) do |type, data|
|
execute("import", ovf) do |type, data|
|
||||||
if type == :stderr
|
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
|
# Append the data so we can see the full view
|
||||||
total << data
|
total << data
|
||||||
|
|
||||||
|
@ -171,6 +175,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
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")
|
output = execute("list", "vms")
|
||||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
||||||
return $1.to_s
|
return $1.to_s
|
||||||
|
@ -274,7 +286,7 @@ module Vagrant
|
||||||
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
elsif line =~ /^NetworkMask:\s+(.+?)$/
|
||||||
info[:netmask] = $1.to_s
|
info[:netmask] = $1.to_s
|
||||||
elsif line =~ /^Status:\s+(.+?)$/
|
elsif line =~ /^Status:\s+(.+?)$/
|
||||||
info[:status] = $1.to_s
|
info[:status] = $1.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -374,6 +386,10 @@ module Vagrant
|
||||||
execute("modifyvm", @uuid, "--macaddress1", mac)
|
execute("modifyvm", @uuid, "--macaddress1", mac)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_name(name)
|
||||||
|
execute("modifyvm", @uuid, "--name", name)
|
||||||
|
end
|
||||||
|
|
||||||
def share_folders(folders)
|
def share_folders(folders)
|
||||||
folders.each do |folder|
|
folders.each do |folder|
|
||||||
execute("sharedfolder", "add", @uuid, "--name",
|
execute("sharedfolder", "add", @uuid, "--name",
|
||||||
|
|
|
@ -147,11 +147,15 @@ module Vagrant
|
||||||
execute("controlvm", @uuid, "poweroff")
|
execute("controlvm", @uuid, "poweroff")
|
||||||
end
|
end
|
||||||
|
|
||||||
def import(ovf, name)
|
def import(ovf)
|
||||||
|
output = ""
|
||||||
total = ""
|
total = ""
|
||||||
last = 0
|
last = 0
|
||||||
execute("import", ovf, "--vsys", "0", "--vmname", name) do |type, data|
|
execute("import", ovf) do |type, data|
|
||||||
if type == :stderr
|
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
|
# Append the data so we can see the full view
|
||||||
total << data
|
total << data
|
||||||
|
|
||||||
|
@ -171,6 +175,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
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")
|
output = execute("list", "vms")
|
||||||
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
if output =~ /^"#{Regexp.escape(name)}" \{(.+?)\}$/
|
||||||
return $1.to_s
|
return $1.to_s
|
||||||
|
@ -374,6 +386,10 @@ module Vagrant
|
||||||
execute("modifyvm", @uuid, "--macaddress1", mac)
|
execute("modifyvm", @uuid, "--macaddress1", mac)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_name(name)
|
||||||
|
execute("modifyvm", @uuid, "--name", name)
|
||||||
|
end
|
||||||
|
|
||||||
def share_folders(folders)
|
def share_folders(folders)
|
||||||
folders.each do |folder|
|
folders.each do |folder|
|
||||||
execute("sharedfolder", "add", @uuid, "--name",
|
execute("sharedfolder", "add", @uuid, "--name",
|
||||||
|
|
|
@ -133,9 +133,8 @@ module Vagrant
|
||||||
# Imports the VM from an OVF file.
|
# Imports the VM from an OVF file.
|
||||||
#
|
#
|
||||||
# @param [String] ovf Path to the OVF file.
|
# @param [String] ovf Path to the OVF file.
|
||||||
# @param [String] name Name of the VM.
|
|
||||||
# @return [String] UUID of the imported VM.
|
# @return [String] UUID of the imported VM.
|
||||||
def import(ovf, name)
|
def import(ovf)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a list of forwarded ports for a VM.
|
# Returns a list of forwarded ports for a VM.
|
||||||
|
|
Loading…
Reference in New Issue