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.
|
# Save the snapshot. This will raise an exception if it fails.
|
||||||
machine.action(:snapshot_save, snapshot_name: snapshot_name)
|
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
|
end
|
||||||
|
|
||||||
def pop(machine)
|
def pop(machine)
|
||||||
modify_snapshot_stack(machine) do |stack|
|
# By reverse sorting, we should be able to find the first
|
||||||
name = stack.pop
|
# pushed snapshot.
|
||||||
|
name = nil
|
||||||
# Restore the snapshot and tell the provider to delete it as well.
|
snapshots = machine.provider.capability(:snapshot_list)
|
||||||
machine.action(
|
snapshots.sort.reverse.each do |snapshot|
|
||||||
:snapshot_restore,
|
if snapshot =~ /^push_\d+_\d+$/
|
||||||
snapshot_name: name,
|
name = snapshot
|
||||||
snapshot_delete: true)
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
# If no snapshot was found, we never pushed
|
||||||
|
if !name
|
||||||
def modify_snapshot_stack(machine)
|
machine.ui.info(I18n.t("vagrant.commands.snapshot.no_push_snapshot"))
|
||||||
# Get the stack
|
return
|
||||||
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))
|
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1501,13 +1501,17 @@ en:
|
||||||
Post install message from the '%{name}' plugin:
|
Post install message from the '%{name}' plugin:
|
||||||
|
|
||||||
%{message}
|
%{message}
|
||||||
snapshot: |-
|
snapshot:
|
||||||
not_supported: |-
|
not_supported: |-
|
||||||
This provider doesn't support snapshots.
|
This provider doesn't support snapshots.
|
||||||
|
|
||||||
This may be intentional or this may be a bug. If this provider
|
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
|
should support snapshots, then please report this as a bug to the
|
||||||
maintainer of the provider.
|
maintainer of the provider.
|
||||||
|
no_push_snapshot: |-
|
||||||
|
No pushed snapshot found!
|
||||||
|
|
||||||
|
Use `vagrant snapshot push` to push a snapshot to restore to.
|
||||||
status:
|
status:
|
||||||
aborted: |-
|
aborted: |-
|
||||||
The VM is in an aborted state. This means that it was abruptly
|
The VM is in an aborted state. This means that it was abruptly
|
||||||
|
|
Loading…
Reference in New Issue