Make export in general VBoxManage friendly

This commit is contained in:
Mitchell Hashimoto 2011-12-26 19:06:44 -08:00
parent fbe984b32d
commit 7e4d652702
5 changed files with 37 additions and 19 deletions

View File

@ -28,6 +28,9 @@ module Vagrant
@env = env @env = env
raise Errors::PackageOutputExists if File.exist?(tar_path) raise Errors::PackageOutputExists if File.exist?(tar_path)
raise Errors::PackageRequiresDirectory if !env["package.directory"] ||
!File.directory?(env["package.directory"])
compress compress
@app.call(env) @app.call(env)
@ -46,7 +49,12 @@ module Vagrant
# to the temporary directory so they are included in a sub-folder within # to the temporary directory so they are included in a sub-folder within
# the actual box # the actual box
def copy_include_files def copy_include_files
env["package.files"].each do |from, to| include_directory = Pathname.new(@env["package.directory"]).join("include")
@env["package.files"].each do |from, dest|
# We place the file in the include directory
to = include_directory.join(dest)
@env[:ui].info I18n.t("vagrant.actions.general.package.packaging", :file => from) @env[:ui].info I18n.t("vagrant.actions.general.package.packaging", :file => from)
FileUtils.mkdir_p(to.parent) FileUtils.mkdir_p(to.parent)

View File

@ -14,7 +14,7 @@ module Vagrant
def call(env) def call(env)
@env = env @env = env
raise Errors::VMPowerOffToPackage if !@env["vm"].vm.powered_off? raise Errors::VMPowerOffToPackage if @env["vm"].state != :poweroff
setup_temp_dir setup_temp_dir
export export
@ -38,7 +38,7 @@ module Vagrant
def export def export
@env[:ui].info I18n.t("vagrant.actions.vm.export.exporting") @env[:ui].info I18n.t("vagrant.actions.vm.export.exporting")
@env["vm"].vm.export(ovf_path) do |progress| @env["vm"].driver.export(ovf_path) do |progress|
@env[:ui].report_progress(progress.percent, 100, false) @env[:ui].report_progress(progress.percent, 100, false)
end end
end end

View File

@ -26,7 +26,7 @@ module Vagrant
def create_vagrantfile def create_vagrantfile
File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f| File.open(File.join(@env["export.temp_dir"], "Vagrantfile"), "w") do |f|
f.write(TemplateRenderer.render("package_Vagrantfile", { f.write(TemplateRenderer.render("package_Vagrantfile", {
:base_mac => @env["vm"].vm.network_adapters.first.mac_address :base_mac => @env["vm"].driver.read_mac_address
})) }))
end end
end end

View File

@ -14,13 +14,6 @@ module Vagrant
end end
def call(env) def call(env)
raise Errors::PackageRequiresDirectory if !env["package.directory"] ||
!File.directory?(env["package.directory"])
# Create a pathname to the directory that will store the files
# we wish to include with the box.
include_directory = Pathname.new(env["package.directory"]).join("include")
files = {} files = {}
env["package.include"].each do |file| env["package.include"].each do |file|
source = Pathname.new(file) source = Pathname.new(file)
@ -31,9 +24,9 @@ module Vagrant
# include directory. Kind of strange, but seems to match what people # include directory. Kind of strange, but seems to match what people
# expect based on history. # expect based on history.
if source.relative? if source.relative?
dest = include_directory.join(source) dest = source
else else
dest = include_directory.join(source.basename) dest = source.basename
end end
# Assign the mapping # Assign the mapping
@ -42,7 +35,7 @@ module Vagrant
if env["package.vagrantfile"] if env["package.vagrantfile"]
# Vagrantfiles are treated special and mapped to a specific file # Vagrantfiles are treated special and mapped to a specific file
files[env["package.vagrantfile"]] = include_directory.join("_Vagrantfile") files[env["package.vagrantfile"]] = "_Vagrantfile"
end end
# Verify the mapping # Verify the mapping

View File

@ -116,11 +116,6 @@ module Vagrant
execute("discardstate", @uuid) execute("discardstate", @uuid)
end end
# Executes a raw command.
def execute_command(command)
raw(*command)
end
# Enables network adapters on this virtual machine. # Enables network adapters on this virtual machine.
def enable_adapters(adapters) def enable_adapters(adapters)
args = [] args = []
@ -141,6 +136,19 @@ module Vagrant
execute("modifyvm", @uuid, *args) execute("modifyvm", @uuid, *args)
end end
# Executes a raw command.
def execute_command(command)
raw(*command)
end
# Exports the virtual machine to the given path.
#
# @param [String] path Path to the OVF file.
def export(path)
# TODO: Progress
execute("export", @uuid, "--output", path.to_s)
end
# Forwards a set of ports for a VM. # Forwards a set of ports for a VM.
# #
# This will not affect any previously set forwarded ports, # This will not affect any previously set forwarded ports,
@ -298,6 +306,15 @@ module Vagrant
end end
end end
# Reads the MAC address of the first network interface.
def read_mac_address
execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line|
return $1.to_s if line =~ /^macaddress1="(.+?)"$/
end
nil
end
# This reads the folder where VirtualBox places it's VMs. # This reads the folder where VirtualBox places it's VMs.
def read_machine_folder def read_machine_folder
execute("list", "systemproperties").split("\n").each do |line| execute("list", "systemproperties").split("\n").each do |line|