providers/virtualbox: use caps for snapshot list
This commit is contained in:
parent
94b6755813
commit
7480b65e9d
|
@ -5,8 +5,6 @@ module VagrantPlugins
|
||||||
module Command
|
module Command
|
||||||
class List < Vagrant.plugin("2", :command)
|
class List < Vagrant.plugin("2", :command)
|
||||||
def execute
|
def execute
|
||||||
options = {}
|
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: vagrant snapshot list [options] [vm-name]"
|
o.banner = "Usage: vagrant snapshot list [options] [vm-name]"
|
||||||
o.separator ""
|
o.separator ""
|
||||||
|
@ -18,7 +16,26 @@ module VagrantPlugins
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
with_target_vms(argv) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
vm.action(:snapshot_list)
|
if !vm.id
|
||||||
|
vm.ui.info(I18n.t("vagrant.commands.common.vm_not_created"))
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
if !vm.provider.capability?(:snapshot_list)
|
||||||
|
vm.ui.info(I18n.t("vagrant.commands.snapshot.not_supported"))
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
snapshots = vm.provider.capability(:snapshot_list)
|
||||||
|
if snapshots.empty?
|
||||||
|
vm.ui.output(I18n.t("vagrant.actions.vm.snapshot.list_none"))
|
||||||
|
vm.ui.detail(I18n.t("vagrant.actions.vm.snapshot.list_none_detail"))
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
snapshots.each do |snapshot|
|
||||||
|
vm.ui.output(snapshot, prefix: false)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
|
|
|
@ -43,7 +43,6 @@ module VagrantPlugins
|
||||||
autoload :SetName, File.expand_path("../action/set_name", __FILE__)
|
autoload :SetName, File.expand_path("../action/set_name", __FILE__)
|
||||||
autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
|
autoload :SetupPackageFiles, File.expand_path("../action/setup_package_files", __FILE__)
|
||||||
autoload :SnapshotDelete, File.expand_path("../action/snapshot_delete", __FILE__)
|
autoload :SnapshotDelete, File.expand_path("../action/snapshot_delete", __FILE__)
|
||||||
autoload :SnapshotList, File.expand_path("../action/snapshot_list", __FILE__)
|
|
||||||
autoload :SnapshotRestore, File.expand_path("../action/snapshot_restore", __FILE__)
|
autoload :SnapshotRestore, File.expand_path("../action/snapshot_restore", __FILE__)
|
||||||
autoload :SnapshotSave, File.expand_path("../action/snapshot_save", __FILE__)
|
autoload :SnapshotSave, File.expand_path("../action/snapshot_save", __FILE__)
|
||||||
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
|
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
|
||||||
|
@ -239,19 +238,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.action_snapshot_list
|
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
|
||||||
b.use CheckVirtualbox
|
|
||||||
b.use Call, Created do |env, b2|
|
|
||||||
if env[:result]
|
|
||||||
b2.use SnapshotList
|
|
||||||
else
|
|
||||||
b2.use MessageNotCreated
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# This is the action that is primarily responsible for saving a snapshot
|
# This is the action that is primarily responsible for saving a snapshot
|
||||||
def self.action_snapshot_restore
|
def self.action_snapshot_restore
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
module VagrantPlugins
|
|
||||||
module ProviderVirtualBox
|
|
||||||
module Action
|
|
||||||
class SnapshotList
|
|
||||||
def initialize(app, env)
|
|
||||||
@app = app
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
snapshots = env[:machine].provider.driver.list_snapshots(
|
|
||||||
env[:machine].id)
|
|
||||||
|
|
||||||
snapshots.each do |snapshot|
|
|
||||||
env[:machine].ui.output(snapshot, prefix: false)
|
|
||||||
end
|
|
||||||
|
|
||||||
if snapshots.empty?
|
|
||||||
env[:machine].ui.output(I18n.t("vagrant.actions.vm.snapshot.list_none"))
|
|
||||||
env[:machine].ui.detail(I18n.t("vagrant.actions.vm.snapshot.list_none_detail"))
|
|
||||||
end
|
|
||||||
|
|
||||||
@app.call(env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -22,6 +22,13 @@ module VagrantPlugins
|
||||||
def self.nic_mac_addresses(machine)
|
def self.nic_mac_addresses(machine)
|
||||||
machine.provider.driver.read_mac_addresses
|
machine.provider.driver.read_mac_addresses
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a list of the snapshots that are taken on this machine.
|
||||||
|
#
|
||||||
|
# @return [Array<String>] Snapshot Name
|
||||||
|
def self.snapshot_list(machine)
|
||||||
|
machine.provider.driver.list_snapshots(machine.id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,11 @@ module VagrantPlugins
|
||||||
require_relative "cap"
|
require_relative "cap"
|
||||||
Cap
|
Cap
|
||||||
end
|
end
|
||||||
|
|
||||||
|
provider_capability(:virtualbox, :snapshot_list) do
|
||||||
|
require_relative "cap"
|
||||||
|
Cap
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
autoload :Action, File.expand_path("../action", __FILE__)
|
autoload :Action, File.expand_path("../action", __FILE__)
|
||||||
|
|
|
@ -1501,6 +1501,13 @@ en:
|
||||||
Post install message from the '%{name}' plugin:
|
Post install message from the '%{name}' plugin:
|
||||||
|
|
||||||
%{message}
|
%{message}
|
||||||
|
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.
|
||||||
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