pause <-> resume

This commit is contained in:
dima 2013-03-30 13:42:59 +01:00
parent f5559d7761
commit 0a66fd2cff
7 changed files with 54 additions and 5 deletions

View File

@ -13,6 +13,12 @@ module VagrantPlugins
b.use ConnectLibvirt
b.use Call, IsCreated do |env, b2|
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
next
end
@ -70,7 +76,18 @@ module VagrantPlugins
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__))
autoload :Suspend, action_root.join("suspend")
autoload :ConnectLibvirt, action_root.join("connect_libvirt")
autoload :IsCreated, action_root.join("is_created")
autoload :MessageAlreadyCreated, action_root.join("message_already_created")

View File

@ -12,7 +12,7 @@ module VagrantPlugins
def call(env)
# Destroy the server and remove the tracking ID
# Destroy the server and remove the tracking ID
env[:ui].info(I18n.t("vagrant_libvirt.destroy_domain"))
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)

View File

@ -12,7 +12,7 @@ module VagrantPlugins
def call(env)
# Verify box metadata for mandatory values.
#
#
# Virtual size has to be set for allocating space in storage pool.
box_virtual_size = env[:machine].box.metadata['virtual_size']
if box_virtual_size == nil
@ -103,7 +103,7 @@ module VagrantPlugins
sent = stream.send buff
progress += sent
yield progress
end
end
end
rescue => e
raise Errors::ImageUploadError,

View File

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

View File

@ -16,7 +16,11 @@ module VagrantPlugins
domain = env[:libvirt_compute].servers.get(env[:machine].id.to_s)
raise Errors::NoDomainError if domain == nil
domain.start
if domain.state.to_s == 'paused'
domain.resume
else
domain.start
end
@app.call(env)
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}
states:
short_paused: |-
pause
short_shutoff: |-
shutoff
short_not_created: |-
not created
long_not_created: |-