mirror of
https://github.com/vagrant-libvirt/vagrant-libvirt.git
synced 2025-02-25 18:55:27 -06:00
pause <-> resume
This commit is contained in:
parent
f5559d7761
commit
0a66fd2cff
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -13,7 +13,6 @@ module VagrantPlugins
|
||||
|
||||
def call(env)
|
||||
env[:machine_state_id] = read_state(env[:libvirt_compute], env[:machine])
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
25
lib/vagrant-libvirt/action/suspend.rb
Normal file
25
lib/vagrant-libvirt/action/suspend.rb
Normal 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
|
@ -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: |-
|
||||
|
Loading…
Reference in New Issue
Block a user