Merge pull request #9 from pronix/master

pause <-> resume
This commit is contained in:
pradels 2013-03-31 09:52:34 -07:00
commit 1069816a75
7 changed files with 54 additions and 5 deletions

View File

@ -13,6 +13,12 @@ module VagrantPlugins
b.use ConnectLibvirt b.use ConnectLibvirt
b.use Call, IsCreated do |env, b2| b.use Call, IsCreated do |env, b2|
if env[:result] if env[:result]
b2.use Call, ReadState do |env2,b3|
if env2[:machine_state_id] == 'paused'
b3.use StartDomain
return true
end
end
b2.use MessageAlreadyCreated b2.use MessageAlreadyCreated
next next
end end
@ -70,7 +76,18 @@ module VagrantPlugins
end end
end end
# suspend
# save vm to file
def self.action_suspend
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectLibvirt
b.use Suspend
end
end
action_root = Pathname.new(File.expand_path("../action", __FILE__)) action_root = Pathname.new(File.expand_path("../action", __FILE__))
autoload :Suspend, action_root.join("suspend")
autoload :ConnectLibvirt, action_root.join("connect_libvirt") autoload :ConnectLibvirt, action_root.join("connect_libvirt")
autoload :IsCreated, action_root.join("is_created") autoload :IsCreated, action_root.join("is_created")
autoload :MessageAlreadyCreated, action_root.join("message_already_created") autoload :MessageAlreadyCreated, action_root.join("message_already_created")

View File

@ -13,7 +13,6 @@ module VagrantPlugins
def call(env) def call(env)
env[:machine_state_id] = read_state(env[:libvirt_compute], env[:machine]) env[:machine_state_id] = read_state(env[:libvirt_compute], env[:machine])
@app.call(env) @app.call(env)
end end

View File

@ -16,7 +16,11 @@ module VagrantPlugins
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s) domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
raise Errors::NoDomainError if domain == nil raise Errors::NoDomainError if domain == nil
domain.start if domain.state.to_s == 'paused'
domain.resume
else
domain.start
end
@app.call(env) @app.call(env)
end end

View File

@ -0,0 +1,25 @@
require 'log4r'
module VagrantPlugins
module Libvirt
module Action
class Suspend
def initialize(app, env)
@logger = Log4r::Logger.new("vagrant_libvirt::action::create_domain")
@app = app
end
# make pause
def call(env)
vmid = env[:machine].id.to_s.chomp
domain = env[:libvirt_compute].servers.get(vmid)
domain.suspend
@logger.info("Machine #{vmid} is suspended ")
@app.call(env)
end
end
end
end
end

View File

@ -91,6 +91,10 @@ en:
Error while attaching new device to domain. %{error_message} Error while attaching new device to domain. %{error_message}
states: states:
short_paused: |-
pause
short_shutoff: |-
shutoff
short_not_created: |- short_not_created: |-
not created not created
long_not_created: |- long_not_created: |-