Import progress works again
This commit is contained in:
parent
85e16f981c
commit
698ad0af7e
|
@ -14,7 +14,7 @@ module Vagrant
|
||||||
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, name) do |progress|
|
||||||
env[:ui].clear_line
|
env[:ui].clear_line
|
||||||
env[:ui].report_progress(progress.percent, 100, false)
|
env[:ui].report_progress(progress, 100, false)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clear the line one last time since the progress meter doesn't disappear
|
# Clear the line one last time since the progress meter doesn't disappear
|
||||||
|
|
|
@ -163,7 +163,29 @@ 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, name)
|
def import(ovf, name)
|
||||||
execute("import", ovf, "--vsys", "0", "--vmname", name)
|
total = ""
|
||||||
|
last = 0
|
||||||
|
execute("import", ovf, "--vsys", "0", "--vmname", name) do |type, data|
|
||||||
|
if type == :stderr
|
||||||
|
# Append the data so we can see the full view
|
||||||
|
total << data
|
||||||
|
|
||||||
|
# Break up the lines. We can't get the progress until we see an "OK"
|
||||||
|
lines = total.split("\n")
|
||||||
|
if lines.include?("OK.")
|
||||||
|
# The progress of the import will be in the last line. Do a greedy
|
||||||
|
# regular expression to find what we're looking for.
|
||||||
|
if lines.last =~ /.+(\d{2})%/
|
||||||
|
current = $1.to_i
|
||||||
|
if current > last
|
||||||
|
last = current
|
||||||
|
yield current
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
output = execute("list", "vms")
|
output = execute("list", "vms")
|
||||||
if output =~ /^"#{name}" {(.+?)}$/
|
if output =~ /^"#{name}" {(.+?)}$/
|
||||||
return $1.to_s
|
return $1.to_s
|
||||||
|
@ -350,9 +372,9 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Execute the given subcommand for VBoxManage and return the output.
|
# Execute the given subcommand for VBoxManage and return the output.
|
||||||
def execute(*command)
|
def execute(*command, &block)
|
||||||
# Execute the command
|
# Execute the command
|
||||||
r = raw(*command)
|
r = raw(*command, &block)
|
||||||
|
|
||||||
# If the command was a failure, then raise an exception that is
|
# If the command was a failure, then raise an exception that is
|
||||||
# nicely handled by Vagrant.
|
# nicely handled by Vagrant.
|
||||||
|
@ -365,8 +387,8 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
# Executes a command and returns the raw result object.
|
# Executes a command and returns the raw result object.
|
||||||
def raw(*command)
|
def raw(*command, &block)
|
||||||
Subprocess.execute("VBoxManage", *command)
|
Subprocess.execute("VBoxManage", *command, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,7 +73,7 @@ module Vagrant
|
||||||
next if data.empty?
|
next if data.empty?
|
||||||
|
|
||||||
io_name = r == stdout ? :stdout : :stderr
|
io_name = r == stdout ? :stdout : :stderr
|
||||||
@logger.debug(data)
|
@logger.debug("#{io_name}: #{data}")
|
||||||
|
|
||||||
if io_name == :stderr && io_data[r] == "" && data =~ /Errno::ENOENT/
|
if io_name == :stderr && io_data[r] == "" && data =~ /Errno::ENOENT/
|
||||||
# This is how we detect that a process failed to start on
|
# This is how we detect that a process failed to start on
|
||||||
|
|
Loading…
Reference in New Issue