Class: OpenNebula::Hook
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Hook
- Defined in:
- lib/opennebula/hook.rb
Overview
Class for representing a Hook object.
Constant Summary collapse
- HOOK_METHODS =
Constants and Class Methods
{ :allocate => 'hook.allocate', :delete => 'hook.delete', :update => 'hook.update', :rename => 'hook.rename', :info => 'hook.info', :lock => 'hook.lock', :unlock => 'hook.unlock', :retry => 'hook.retry' }
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Hook description with just its identifier this method should be used to create plain Hook objects.
Instance Method Summary collapse
-
#allocate(template) ⇒ nil, OpenNebula::Error
Allocates a new Hook in OpenNebula.
-
#delete ⇒ nil, OpenNebula::Error
Deletes the Hook.
-
#gid ⇒ Object
Returns the group identifier [return] Integer the element’s group ID.
-
#info ⇒ Object
(also: #info!)
Retrieves the information of the given Hook.
-
#initialize(xml, client) ⇒ Hook
constructor
Class constructor.
-
#lock(level) ⇒ Object
Lock a Hook.
- #owner_id ⇒ Object
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Hook.
-
#retry(exec_id) ⇒ nil, OpenNebula::Error
Retry a previous execution of the hook.
-
#unlock ⇒ Object
Unlock a Hook.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the Hook contents.
Methods inherited from PoolElement
#id, #name, new_with_id, #replace, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
#initialize(xml, client) ⇒ Hook
Class constructor
56 57 58 59 60 |
# File 'lib/opennebula/hook.rb', line 56 def initialize(xml, client) super(xml, client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/opennebula/hook.rb', line 45 def self.build_xml(pe_id = nil) if pe_id obj_xml = "<HOOK><ID>#{pe_id}</ID></HOOK>" else obj_xml = '<HOOK></HOOK>' end XMLElement.build_xml(obj_xml, 'HOOK') end |
Instance Method Details
#allocate(template) ⇒ nil, OpenNebula::Error
Allocates a new Hook in OpenNebula
91 92 93 |
# File 'lib/opennebula/hook.rb', line 91 def allocate(template) super(HOOK_METHODS[:allocate], template) end |
#delete ⇒ nil, OpenNebula::Error
Deletes the Hook
99 100 101 |
# File 'lib/opennebula/hook.rb', line 99 def delete call(HOOK_METHODS[:delete], @pe_id) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
141 142 143 |
# File 'lib/opennebula/hook.rb', line 141 def gid self['GID'].to_i end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Hook.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/opennebula/hook.rb', line 67 def info return Error.new('ID not defined') unless @pe_id rc = @client.call(HOOK_METHODS[:info], @pe_id, false) if !OpenNebula.is_error?(rc) initialize_xml(rc, 'HOOK') rc = nil @pe_id = self['ID'].to_i if self['ID'] @name = self['NAME'] if self['NAME'] end rc end |
#lock(level) ⇒ Object
Lock a Hook
150 151 152 |
# File 'lib/opennebula/hook.rb', line 150 def lock(level) call(HOOK_METHODS[:lock], @pe_id, level) end |
#owner_id ⇒ Object
145 146 147 |
# File 'lib/opennebula/hook.rb', line 145 def owner_id self['UID'].to_i end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Hook
121 122 123 |
# File 'lib/opennebula/hook.rb', line 121 def rename(name) call(HOOK_METHODS[:rename], @pe_id, name) end |
#retry(exec_id) ⇒ nil, OpenNebula::Error
Retry a previous execution of the hook.
131 132 133 |
# File 'lib/opennebula/hook.rb', line 131 def retry(exec_id) call(HOOK_METHODS[:retry], @pe_id, exec_id) end |
#unlock ⇒ Object
Unlock a Hook
155 156 157 |
# File 'lib/opennebula/hook.rb', line 155 def unlock call(HOOK_METHODS[:unlock], @pe_id) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the Hook contents
111 112 113 |
# File 'lib/opennebula/hook.rb', line 111 def update(new_template, append = false) super(HOOK_METHODS[:update], new_template, append ? 1 : 0) end |