From 83b908f3d8f1fe1d46a7b2c087f702291fe726c0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 13 Aug 2012 19:30:41 -0700 Subject: [PATCH] `vagrant suspend` works with new machine abstraction --- plugins/commands/suspend/command.rb | 16 ++++------------ plugins/providers/virtualbox/action.rb | 17 +++++++++++++++++ .../providers/virtualbox/action}/suspend.rb | 10 +++++----- 3 files changed, 26 insertions(+), 17 deletions(-) rename {lib/vagrant/action/vm => plugins/providers/virtualbox/action}/suspend.rb (60%) diff --git a/plugins/commands/suspend/command.rb b/plugins/commands/suspend/command.rb index 539be8ac5..6183b71d3 100644 --- a/plugins/commands/suspend/command.rb +++ b/plugins/commands/suspend/command.rb @@ -4,10 +4,8 @@ module VagrantPlugins module CommandSuspend class Command < Vagrant.plugin("1", :command) def execute - options = {} - - opts = OptionParser.new do |opts| - opts.banner = "Usage: vagrant suspend [vm-name]" + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant suspend [vm-name]" end # Parse the options @@ -16,18 +14,12 @@ module VagrantPlugins @logger.debug("'suspend' each target VM...") with_target_vms(argv) do |vm| - if vm.created? - @logger.info("Suspending: #{vm.name}") - vm.suspend - else - @logger.info("Not created: #{vm.name}. Not suspending.") - vm.ui.info I18n.t("vagrant.commands.common.vm_not_created") - end + vm.action(:suspend) end # Success, exit status 0 0 - end + end end end end diff --git a/plugins/providers/virtualbox/action.rb b/plugins/providers/virtualbox/action.rb index 804be8911..33e6b3f11 100644 --- a/plugins/providers/virtualbox/action.rb +++ b/plugins/providers/virtualbox/action.rb @@ -13,6 +13,7 @@ module VagrantPlugins autoload :Halt, File.expand_path("../action/halt", __FILE__) autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__) autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __FILE__) + autoload :Suspend, File.expand_path("../action/suspend", __FILE__) # Include the built-in modules so that we can use them as top-level # things. @@ -79,6 +80,22 @@ module VagrantPlugins b.use SSHRun end end + + # This is the action that is primarily responsible for suspending + # the virtual machine. + def self.action_suspend + Vagrant::Action::Builder.new.tap do |b| + b.use CheckVirtualbox + b.use Call, Created do |env, b2| + if env[:result] + b2.use CheckAccessible + b2.use Suspend + else + b2.use MessageNotCreated + end + end + end + end end end end diff --git a/lib/vagrant/action/vm/suspend.rb b/plugins/providers/virtualbox/action/suspend.rb similarity index 60% rename from lib/vagrant/action/vm/suspend.rb rename to plugins/providers/virtualbox/action/suspend.rb index 8f39293eb..9a9b7a94b 100644 --- a/lib/vagrant/action/vm/suspend.rb +++ b/plugins/providers/virtualbox/action/suspend.rb @@ -1,15 +1,15 @@ -module Vagrant - module Action - module VM +module VagrantPlugins + module ProviderVirtualBox + module Action class Suspend def initialize(app, env) @app = app end def call(env) - if env[:vm].state == :running + if env[:machine].provider.state == :running env[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending") - env[:vm].driver.suspend + env[:machine].provider.driver.suspend end @app.call(env)