Module: OpenNebula::WaitExt
- Defined in:
- lib/opennebula/wait_ext.rb
Overview
Module to decorate Wait classes with the following methods:
- Wait
rubocop:disable Style/ClassAndModuleChildren
Constant Summary collapse
- WAIT =
Wait classes and the name published in ZMQ/STATE
{ OpenNebula::Host => { :event => lambda {|o, s1, _s2| "EVENT STATE HOST/#{s1}//#{o['ID']}" }, :in_state => lambda {|o, s1, _s2| obj_s = Integer(o['STATE']) inx_s = OpenNebula::Host::HOST_STATES.index(s1) obj_s == inx_s }, :in_state_e => lambda {|s1, _s2, content| xml = Nokogiri::XML(Base64.decode64(content)) obj_s = Integer(xml.xpath('//HOST/STATE').text) inx_s = OpenNebula::Host::HOST_STATES.index(s1) obj_s == inx_s } }, OpenNebula::Image => { :event => lambda {|o, s1, _s2| "EVENT STATE IMAGE/#{s1}//#{o['ID']}" }, :in_state => lambda {|o, s1, _s2| obj_s = Integer(o['STATE']) inx_s = OpenNebula::Image::IMAGE_STATES.index(s1) obj_s == inx_s }, :in_state_e => lambda {|s1, _s2, content| xml = Nokogiri::XML(Base64.decode64(content)) obj_s = Integer(xml.xpath('//IMAGE/STATE').text) inx_s = OpenNebula::Image::IMAGE_STATES.index(s1) obj_s == inx_s } }, OpenNebula::VirtualMachine => { :event => lambda {|o, s1, s2| "EVENT STATE VM/#{s1}/#{s2}/#{o['ID']}" }, :in_state => lambda {|o, s1, s2| obj_s1 = Integer(o['STATE']) inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1) obj_s2 = Integer(o['LCM_STATE']) inx_s2 = OpenNebula::VirtualMachine::LCM_STATE.index(s2) obj_s1 == inx_s1 && obj_s2 == inx_s2 }, :in_state_e => lambda {|s1, s2, content| xml = Nokogiri::XML(Base64.decode64(content)) obj_s1 = Integer(xml.xpath('//VM/STATE').text) inx_s1 = OpenNebula::VirtualMachine::VM_STATE.index(s1) obj_s2 = Integer(xml.xpath('//VM/LCM_STATE').text) inx_s2 = OpenNebula::VirtualMachine::LCM_STATE.index(s2) obj_s1 == inx_s1 && obj_s2 == inx_s2 } } }
Class Method Summary collapse
- .extend_object(obj) ⇒ Object
-
.wait?(obj) ⇒ Boolean
Check if object has the method wait or not.
Instance Method Summary collapse
-
#wait(state_str, timeout = 60, cycles = -1)) ⇒ Object
Wait until the element reaches some specific state It waits until the state can be found in ZMQ event message.
Class Method Details
.extend_object(obj) ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/opennebula/wait_ext.rb', line 214 def self.extend_object(obj) wait?(obj) class << obj begin require 'ffi-rzmq' include OpenNebula::WaitExtEvent rescue LoadError include OpenNebula::WaitExtPolling end end super end |
.wait?(obj) ⇒ Boolean
Check if object has the method wait or not
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/opennebula/wait_ext.rb', line 247 def self.wait?(obj) # Get obj class to find parents in wait class # rubocop:disable Style/TernaryParentheses (obj.is_a? Class) ? o_class = obj : o_class = obj.class # rubocop:enable Style/TernaryParentheses found = false i_class = o_class while i_class if WAIT.keys.include?(i_class) found = true break end i_class = i_class.superclass end return if found raise StandardError, "Cannot extend #{o_class} with WaitExt" end |
Instance Method Details
#wait(state_str, timeout = 60, cycles = -1)) ⇒ Object
Wait until the element reaches some specific state It waits until the state can be found in ZMQ event message
240 241 242 |
# File 'lib/opennebula/wait_ext.rb', line 240 def wait(state_str, timeout = 60, cycles = -1) wait2(state_str, '', timeout, cycles) end |