diff --git a/plugins/commands/snapshot/command/pop.rb b/plugins/commands/snapshot/command/pop.rb index 2c3499f43..a10d57227 100644 --- a/plugins/commands/snapshot/command/pop.rb +++ b/plugins/commands/snapshot/command/pop.rb @@ -10,17 +10,22 @@ module VagrantPlugins include PushShared def execute + options = {} opts = OptionParser.new do |o| o.banner = "Usage: vagrant snapshot pop [options] [vm-name]" o.separator "" o.separator "Restore state that was pushed with `vagrant snapshot push`." + + o.on("--no-delete", "Don't delete the snapshot after the restore") do + options[:no_delete] = true + end end # Parse the options argv = parse_options(opts) return if !argv - return shared_exec(argv, method(:pop)) + return shared_exec(argv, method(:pop), options) end end end diff --git a/plugins/commands/snapshot/command/push_shared.rb b/plugins/commands/snapshot/command/push_shared.rb index a82779ee5..2942b6f23 100644 --- a/plugins/commands/snapshot/command/push_shared.rb +++ b/plugins/commands/snapshot/command/push_shared.rb @@ -4,7 +4,7 @@ module VagrantPlugins module CommandSnapshot module Command module PushShared - def shared_exec(argv, m) + def shared_exec(argv, m, opts={}) with_target_vms(argv) do |vm| if !vm.id vm.ui.info("Not created. Cannot push snapshot state.") @@ -12,7 +12,7 @@ module VagrantPlugins end vm.env.lock("machine-snapshot-stack") do - m.call(vm) + m.call(vm,opts) end end @@ -20,14 +20,14 @@ module VagrantPlugins 0 end - def push(machine) + def push(machine,opts={}) snapshot_name = "push_#{Time.now.to_i}_#{rand(10000)}" # Save the snapshot. This will raise an exception if it fails. machine.action(:snapshot_save, snapshot_name: snapshot_name) end - def pop(machine) + def pop(machine,opts={}) # By reverse sorting, we should be able to find the first # pushed snapshot. name = nil @@ -45,11 +45,16 @@ module VagrantPlugins return end - # Restore the snapshot and tell the provider to delete it as well. + snapshot_delete = true + if opts.key?(:no_delete) + snapshot_delete = false + end + + # Restore the snapshot and tell the provider to delete it, if required machine.action( :snapshot_restore, snapshot_name: name, - snapshot_delete: true) + snapshot_delete: snapshot_delete) end end end