commands/snapshot: push now uses caps to be more resilient
This commit is contained in:
parent
7480b65e9d
commit
0abc17eaed
|
@ -24,40 +24,31 @@ module VagrantPlugins
|
|||
|
||||
# Save the snapshot. This will raise an exception if it fails.
|
||||
machine.action(:snapshot_save, snapshot_name: snapshot_name)
|
||||
|
||||
# Success! Write the resulting stack out
|
||||
modify_snapshot_stack(machine) do |stack|
|
||||
stack << snapshot_name
|
||||
end
|
||||
end
|
||||
|
||||
def pop(machine)
|
||||
modify_snapshot_stack(machine) do |stack|
|
||||
name = stack.pop
|
||||
|
||||
# Restore the snapshot and tell the provider to delete it as well.
|
||||
machine.action(
|
||||
:snapshot_restore,
|
||||
snapshot_name: name,
|
||||
snapshot_delete: true)
|
||||
# By reverse sorting, we should be able to find the first
|
||||
# pushed snapshot.
|
||||
name = nil
|
||||
snapshots = machine.provider.capability(:snapshot_list)
|
||||
snapshots.sort.reverse.each do |snapshot|
|
||||
if snapshot =~ /^push_\d+_\d+$/
|
||||
name = snapshot
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def modify_snapshot_stack(machine)
|
||||
# Get the stack
|
||||
snapshot_stack = []
|
||||
snapshot_file = machine.data_dir.join("snapshot_stack")
|
||||
snapshot_stack = JSON.parse(snapshot_file.read) if snapshot_file.file?
|
||||
|
||||
# Yield it so it can be modified
|
||||
yield snapshot_stack
|
||||
|
||||
# Write it out
|
||||
snapshot_file.open("w+") do |f|
|
||||
f.write(JSON.dump(snapshot_stack))
|
||||
# If no snapshot was found, we never pushed
|
||||
if !name
|
||||
machine.ui.info(I18n.t("vagrant.commands.snapshot.no_push_snapshot"))
|
||||
return
|
||||
end
|
||||
|
||||
# Restore the snapshot and tell the provider to delete it as well.
|
||||
machine.action(
|
||||
:snapshot_restore,
|
||||
snapshot_name: name,
|
||||
snapshot_delete: true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1501,13 +1501,17 @@ en:
|
|||
Post install message from the '%{name}' plugin:
|
||||
|
||||
%{message}
|
||||
snapshot: |-
|
||||
snapshot:
|
||||
not_supported: |-
|
||||
This provider doesn't support snapshots.
|
||||
|
||||
This may be intentional or this may be a bug. If this provider
|
||||
should support snapshots, then please report this as a bug to the
|
||||
maintainer of the provider.
|
||||
no_push_snapshot: |-
|
||||
No pushed snapshot found!
|
||||
|
||||
Use `vagrant snapshot push` to push a snapshot to restore to.
|
||||
status:
|
||||
aborted: |-
|
||||
The VM is in an aborted state. This means that it was abruptly
|
||||
|
|
Loading…
Reference in New Issue