`vagrant suspend` works with new machine abstraction
This commit is contained in:
parent
aad022a626
commit
83b908f3d8
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue