providers/virtualbox: use caps for snapshot list

This commit is contained in:
Mitchell Hashimoto 2015-10-08 08:46:36 -04:00
parent 94b6755813
commit 7480b65e9d
6 changed files with 39 additions and 44 deletions

View File

@ -5,8 +5,6 @@ module VagrantPlugins
module Command
class List < Vagrant.plugin("2", :command)
def execute
options = {}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant snapshot list [options] [vm-name]"
o.separator ""
@ -18,7 +16,26 @@ module VagrantPlugins
return if !argv
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
# Success, exit status 0

View File

@ -43,7 +43,6 @@ module VagrantPlugins
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 :SnapshotList, File.expand_path("../action/snapshot_list", __FILE__)
autoload :SnapshotRestore, File.expand_path("../action/snapshot_restore", __FILE__)
autoload :SnapshotSave, File.expand_path("../action/snapshot_save", __FILE__)
autoload :Suspend, File.expand_path("../action/suspend", __FILE__)
@ -239,19 +238,6 @@ module VagrantPlugins
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
def self.action_snapshot_restore
Vagrant::Action::Builder.new.tap do |b|

View File

@ -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

View File

@ -22,6 +22,13 @@ module VagrantPlugins
def self.nic_mac_addresses(machine)
machine.provider.driver.read_mac_addresses
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

View File

@ -33,6 +33,11 @@ module VagrantPlugins
require_relative "cap"
Cap
end
provider_capability(:virtualbox, :snapshot_list) do
require_relative "cap"
Cap
end
end
autoload :Action, File.expand_path("../action", __FILE__)

View File

@ -1501,6 +1501,13 @@ en:
Post install message from the '%{name}' plugin:
%{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:
aborted: |-
The VM is in an aborted state. This means that it was abruptly