providers/virtualbox: snapshot restore
This commit is contained in:
parent
c635352b89
commit
8c0e38b397
|
@ -252,6 +252,25 @@ module VagrantPlugins
|
|||
end
|
||||
end
|
||||
|
||||
# This is the action that is primarily responsible for saving a snapshot
|
||||
def self.action_snapshot_restore
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use CheckVirtualbox
|
||||
b.use Call, Created do |env, b2|
|
||||
if !env[:result]
|
||||
b2.use MessageNotCreated
|
||||
next
|
||||
end
|
||||
|
||||
b2.use CheckAccessible
|
||||
b2.use EnvSet, force_halt: true
|
||||
b2.use action_halt
|
||||
b2.use SnapshotRestore
|
||||
b2.use action_start
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This is the action that is primarily responsible for saving a snapshot
|
||||
def self.action_snapshot_save
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
|
|
|
@ -11,7 +11,14 @@ module VagrantPlugins
|
|||
"vagrant.actions.vm.snapshot.restoring",
|
||||
name: env[:snapshot_name]))
|
||||
env[:machine].provider.driver.restore_snapshot(
|
||||
env[:machine].id, env[:snapshot_name])
|
||||
env[:machine].id, env[:snapshot_name]) do |progress|
|
||||
env[:ui].clear_line
|
||||
env[:ui].report_progress(progress, 100, false)
|
||||
end
|
||||
|
||||
# Clear the line one last time since the progress meter doesn't disappear
|
||||
# immediately.
|
||||
env[:ui].clear_line
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
|
|
@ -130,7 +130,31 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def restore_snapshot(machine_id, snapshot_name)
|
||||
execute("snapshot", machine_id, "restore", snapshot_name)
|
||||
# Start with 0%
|
||||
last = 0
|
||||
total = ""
|
||||
yield 0 if block_given?
|
||||
|
||||
execute("snapshot", machine_id, "restore", snapshot_name) do |type, data|
|
||||
if type == :stderr
|
||||
# Append the data so we can see the full view
|
||||
total << data.gsub("\r", "")
|
||||
|
||||
# Break up the lines. We can't get the progress until we see an "OK"
|
||||
lines = total.split("\n")
|
||||
|
||||
# The progress of the import will be in the last line. Do a greedy
|
||||
# regular expression to find what we're looking for.
|
||||
match = /.+(\d{2})%/.match(lines.last)
|
||||
if match
|
||||
current = match[1].to_i
|
||||
if current > last
|
||||
last = current
|
||||
yield current if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def delete
|
||||
|
|
|
@ -1770,6 +1770,8 @@ en:
|
|||
Deleting the snapshot '%{name}'...
|
||||
deleted: |-
|
||||
Snapshot deleted!
|
||||
restoring: |-
|
||||
Restoring the snapshot '%{name}'...
|
||||
saving: |-
|
||||
Snapshotting the machine as '%{name}'...
|
||||
saved: |-
|
||||
|
|
Loading…
Reference in New Issue