Support provisioning flags on snapshot rollback
This commit is contained in:
parent
7ba398ead8
commit
eff2b2d7b4
|
@ -1,6 +1,10 @@
|
||||||
require 'json'
|
require 'json'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
|
require 'vagrant'
|
||||||
|
|
||||||
|
require Vagrant.source_root.join("plugins/commands/up/start_mixins")
|
||||||
|
|
||||||
require_relative "push_shared"
|
require_relative "push_shared"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
@ -8,16 +12,19 @@ module VagrantPlugins
|
||||||
module Command
|
module Command
|
||||||
class Pop < Vagrant.plugin("2", :command)
|
class Pop < Vagrant.plugin("2", :command)
|
||||||
include PushShared
|
include PushShared
|
||||||
|
include VagrantPlugins::CommandUp::StartMixins
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
options = {}
|
options = {}
|
||||||
|
options[:snapshot_delete] = true
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: vagrant snapshot pop [options] [vm-name]"
|
o.banner = "Usage: vagrant snapshot pop [options] [vm-name]"
|
||||||
o.separator ""
|
o.separator ""
|
||||||
|
build_start_options(o, options)
|
||||||
o.separator "Restore state that was pushed with `vagrant snapshot push`."
|
o.separator "Restore state that was pushed with `vagrant snapshot push`."
|
||||||
|
|
||||||
o.on("--no-delete", "Don't delete the snapshot after the restore") do
|
o.on("--no-delete", "Don't delete the snapshot after the restore") do
|
||||||
options[:no_delete] = true
|
options[:snapshot_delete] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,6 +32,9 @@ module VagrantPlugins
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
|
# Validate the provisioners
|
||||||
|
validate_provisioner_flags!(options, argv)
|
||||||
|
|
||||||
return shared_exec(argv, method(:pop), options)
|
return shared_exec(argv, method(:pop), options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,16 +45,9 @@ module VagrantPlugins
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
snapshot_delete = true
|
|
||||||
if opts.key?(:no_delete)
|
|
||||||
snapshot_delete = false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Restore the snapshot and tell the provider to delete it, if required
|
# Restore the snapshot and tell the provider to delete it, if required
|
||||||
machine.action(
|
opts[:snapshot_name] = name
|
||||||
:snapshot_restore,
|
machine.action(:snapshot_restore, opts)
|
||||||
snapshot_name: name,
|
|
||||||
snapshot_delete: snapshot_delete)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,23 @@
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
|
||||||
|
require 'vagrant'
|
||||||
|
|
||||||
|
require Vagrant.source_root.join("plugins/commands/up/start_mixins")
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module CommandSnapshot
|
module CommandSnapshot
|
||||||
module Command
|
module Command
|
||||||
class Restore < Vagrant.plugin("2", :command)
|
class Restore < Vagrant.plugin("2", :command)
|
||||||
|
|
||||||
|
include VagrantPlugins::CommandUp::StartMixins
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
options = {}
|
options = {}
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: vagrant snapshot restore [options] [vm-name] <name>"
|
o.banner = "Usage: vagrant snapshot restore [options] [vm-name] <name>"
|
||||||
o.separator ""
|
o.separator ""
|
||||||
|
build_start_options(o, options)
|
||||||
o.separator "Restore a snapshot taken previously with snapshot save."
|
o.separator "Restore a snapshot taken previously with snapshot save."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,9 +29,14 @@ module VagrantPlugins
|
||||||
help: opts.help.chomp
|
help: opts.help.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Validate the provisioners
|
||||||
|
validate_provisioner_flags!(options, argv)
|
||||||
|
|
||||||
name = argv.pop
|
name = argv.pop
|
||||||
|
options[:snapshot_name] = name
|
||||||
|
|
||||||
with_target_vms(argv) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
vm.action(:snapshot_restore, snapshot_name: name)
|
vm.action(:snapshot_restore, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
|
|
Loading…
Reference in New Issue