providers/virtualbox: snapshot save/delete
This commit is contained in:
parent
a99ebcb3ce
commit
d0e8ecfc73
|
@ -42,6 +42,8 @@ module VagrantPlugins
|
|||
autoload :SaneDefaults, File.expand_path("../action/sane_defaults", __FILE__)
|
||||
autoload :SetName, File.expand_path("../action/set_name", __FILE__)
|
||||
autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
|
||||
autoload :SnapshotDelete, File.expand_path("../action/snapshot_delete", __FILE__)
|
||||
autoload :SnapshotSave, File.expand_path("../action/snapshot_save", __FILE__)
|
||||
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
|
||||
|
||||
# Include the built-in modules so that we can use them as top-level
|
||||
|
@ -222,6 +224,33 @@ module VagrantPlugins
|
|||
end
|
||||
end
|
||||
|
||||
def self.action_snapshot_delete
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use CheckVirtualbox
|
||||
b.use Call, Created do |env, b2|
|
||||
if env[:result]
|
||||
b2.use SnapshotDelete
|
||||
else
|
||||
b2.use MessageNotCreated
|
||||
end
|
||||
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|
|
||||
b.use CheckVirtualbox
|
||||
b.use Call, Created do |env, b2|
|
||||
if env[:result]
|
||||
b2.use SnapshotSave
|
||||
else
|
||||
b2.use MessageNotCreated
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This is the action that will exec into an SSH shell.
|
||||
def self.action_ssh
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class SnapshotDelete
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env[:ui].info(I18n.t(
|
||||
"vagrant.actions.vm.snapshot.deleting",
|
||||
name: env[:snapshot_name]))
|
||||
env[:machine].provider.driver.delete_snapshot(
|
||||
env[:machine].id, env[:snapshot_name])
|
||||
|
||||
env[:ui].success(I18n.t(
|
||||
"vagrant.actions.vm.snapshot.deleted",
|
||||
name: env[:snapshot_name]))
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
module Action
|
||||
class SnapshotSave
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
env[:ui].info(I18n.t(
|
||||
"vagrant.actions.vm.snapshot.saving",
|
||||
name: env[:snapshot_name]))
|
||||
env[:machine].provider.driver.create_snapshot(
|
||||
env[:machine].id, env[:snapshot_name])
|
||||
|
||||
env[:ui].success(I18n.t(
|
||||
"vagrant.actions.vm.snapshot.saved",
|
||||
name: env[:snapshot_name]))
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -89,6 +89,7 @@ module VagrantPlugins
|
|||
:create_host_only_network,
|
||||
:create_snapshot,
|
||||
:delete,
|
||||
:delete_snapshot,
|
||||
:delete_unused_host_only_networks,
|
||||
:discard_saved_state,
|
||||
:enable_adapters,
|
||||
|
@ -113,6 +114,7 @@ module VagrantPlugins
|
|||
:read_vms,
|
||||
:reconfig_host_only,
|
||||
:remove_dhcp_server,
|
||||
:restore_snapshot,
|
||||
:resume,
|
||||
:set_mac_address,
|
||||
:set_name,
|
||||
|
|
|
@ -86,6 +86,14 @@ module VagrantPlugins
|
|||
execute("snapshot", machine_id, "take", snapshot_name)
|
||||
end
|
||||
|
||||
def delete_snapshot(machine_id, snapshot_name)
|
||||
execute("snapshot", machine_id, "delete", snapshot_name)
|
||||
end
|
||||
|
||||
def restore_snapshot(machine_id, snapshot_name)
|
||||
execute("snapshot", machine_id, "restore", snapshot_name)
|
||||
end
|
||||
|
||||
def delete
|
||||
execute("unregistervm", @uuid, "--delete")
|
||||
end
|
||||
|
|
|
@ -1765,6 +1765,17 @@ en:
|
|||
set_name:
|
||||
setting_name: |-
|
||||
Setting the name of the VM: %{name}
|
||||
snapshot:
|
||||
deleting: |-
|
||||
Deleting the snapshot '%{name}'...
|
||||
deleted: |-
|
||||
Snapshot deleted!
|
||||
saving: |-
|
||||
Snapshotting the machine as '%{name}'...
|
||||
saved: |-
|
||||
Snapshot saved! You can restore the snapshot at any time by
|
||||
using `vagrant snapshot restore`. You can delete it using
|
||||
`vagrant snapshot delete`.
|
||||
suspend:
|
||||
suspending: Saving VM state and suspending execution...
|
||||
|
||||
|
|
Loading…
Reference in New Issue