lib/vagrant-ovirt3/action.rb in vagrant-ovirt3-1.2.0 vs lib/vagrant-ovirt3/action.rb in vagrant-ovirt3-1.3.0
- old
+ new
@@ -9,31 +9,76 @@
# This action is called to bring the box up from nothing.
def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectOVirt
- b.use Call, IsCreated do |env, b2|
- if env[:result]
- b2.use MessageAlreadyCreated
+ b.use Call, ReadState do |env, b2|
+ if env[:machine_state_id] == :up
+ b2.use SyncFolders
+ b2.use MessageAlreadyUp
next
end
- b2.use SetNameOfDomain
- b2.use CreateVM
- b2.use ResizeDisk
+ if env[:machine_state_id] == :saving_state
+ b2.use MessageSavingState
+ next
+ end
- b2.use Provision
- b2.use CreateNetworkInterfaces
+ if env[:machine_state_id] == :not_created
+ b2.use SetNameOfDomain
+ b2.use CreateVM
+ b2.use ResizeDisk
- b2.use SetHostname
+ b2.use Provision
+ b2.use CreateNetworkInterfaces
+
+ b2.use SetHostname
+ end
+
b2.use StartVM
b2.use WaitTillUp
b2.use SyncFolders
end
end
end
+ def self.action_halt
+ with_ovirt do |env, b|
+ if env[:machine_state_id] != :up
+ b.use MessageNotUp
+ next
+ end
+ b.use HaltVM
+ end
+ end
+
+ def self.action_suspend
+ with_ovirt do |env, b|
+ if env[:machine_state_id] != :up
+ b.use MessageNotUp
+ next
+ end
+ b.use SuspendVM
+ end
+ end
+
+ def self.action_resume
+ with_ovirt do |env, b|
+ if env[:machine_state_id] == :saving_state
+ b.use MessageSavingState
+ next
+ end
+ if env[:machine_state_id] != :suspended
+ b.use MessageNotSuspended
+ next
+ end
+ b.use StartVM
+ b.use WaitTillUp
+ b.use SyncFolders
+ end
+ end
+
# This is the action that is primarily responsible for completely
# freeing the resources of the underlying virtual machine.
def self.action_destroy
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
@@ -71,28 +116,37 @@
end
def self.action_ssh
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
- b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ b.use ConnectOVirt
+ b.use Call, ReadState do |env, b2|
+ if env[:machine_state_id] == :not_created
b2.use MessageNotCreated
next
end
+ if env[:machine_state_id] != :up
+ b2.use MessageNotUp
+ next
+ end
b2.use SSHExec
end
end
end
def self.action_ssh_run
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
- if !env[:result]
+ if env[:machine_state_id] == :not_created
b2.use MessageNotCreated
next
end
+ if env[:machine_state_id] != :up
+ b2.use MessageNotUp
+ next
+ end
b2.use SSHRun
end
end
end
@@ -117,15 +171,36 @@
autoload :CreateVM, action_root.join("create_vm")
autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
autoload :ResizeDisk, action_root.join("resize_disk")
autoload :StartVM, action_root.join("start_vm")
autoload :MessageNotCreated, action_root.join("message_not_created")
+ autoload :HaltVM, action_root.join("halt_vm")
+ autoload :SuspendVM, action_root.join("suspend_vm")
autoload :DestroyVM, action_root.join("destroy_vm")
autoload :ReadState, action_root.join("read_state")
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
autoload :WaitTillUp, action_root.join("wait_till_up")
autoload :SyncFolders, action_root.join("sync_folders")
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
+ autoload :MessageAlreadyUp, action_root.join("message_already_up")
+ autoload :MessageNotUp, action_root.join("message_not_up")
+ autoload :MessageSavingState, action_root.join("message_saving_state")
+ autoload :MessageNotSuspended, action_root.join("message_not_suspended")
+
+ private
+ def self.with_ovirt
+ Vagrant::Action::Builder.new.tap do |b|
+ b.use ConfigValidate
+ b.use ConnectOVirt
+ b.use Call, ReadState do |env, b2|
+ if !env[:machine_state_id] == :not_created
+ b2.use MessageNotCreated
+ next
+ end
+ yield env, b2
+ end
+ end
+ end
end
end
end