vagrant suspend works with new machine abstraction
This commit is contained in:
parent
aad022a626
commit
83b908f3d8
@ -4,10 +4,8 @@ module VagrantPlugins
|
|||||||
module CommandSuspend
|
module CommandSuspend
|
||||||
class Command < Vagrant.plugin("1", :command)
|
class Command < Vagrant.plugin("1", :command)
|
||||||
def execute
|
def execute
|
||||||
options = {}
|
opts = OptionParser.new do |o|
|
||||||
|
o.banner = "Usage: vagrant suspend [vm-name]"
|
||||||
opts = OptionParser.new do |opts|
|
|
||||||
opts.banner = "Usage: vagrant suspend [vm-name]"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
@ -16,18 +14,12 @@ module VagrantPlugins
|
|||||||
|
|
||||||
@logger.debug("'suspend' each target VM...")
|
@logger.debug("'suspend' each target VM...")
|
||||||
with_target_vms(argv) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
vm.action(:suspend)
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Success, exit status 0
|
# Success, exit status 0
|
||||||
0
|
0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,6 +13,7 @@ module VagrantPlugins
|
|||||||
autoload :Halt, File.expand_path("../action/halt", __FILE__)
|
autoload :Halt, File.expand_path("../action/halt", __FILE__)
|
||||||
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
|
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
|
||||||
autoload :MessageWillNotDestroy, File.expand_path("../action/message_will_not_destroy", __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
|
# Include the built-in modules so that we can use them as top-level
|
||||||
# things.
|
# things.
|
||||||
@ -79,6 +80,22 @@ module VagrantPlugins
|
|||||||
b.use SSHRun
|
b.use SSHRun
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
module Vagrant
|
module VagrantPlugins
|
||||||
module Action
|
module ProviderVirtualBox
|
||||||
module VM
|
module Action
|
||||||
class Suspend
|
class Suspend
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
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[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending")
|
||||||
env[:vm].driver.suspend
|
env[:machine].provider.driver.suspend
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
Loading…
x
Reference in New Issue
Block a user