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' }
Instance Attribute Summary
Attributes inherited from PoolElement
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.
- #owner_id ⇒ Object
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Hook.
-
#retry(exec_id) ⇒ nil, OpenNebula::Error
Retry a previous execution of the hook.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the Hook contents.
Methods inherited from PoolElement
#id, 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
57 58 59 60 61 62 63 |
# File 'lib/opennebula/hook.rb', line 57 def initialize(xml, client) LockableExt.make_lockable(self, HOOK_METHODS) super(xml, client) @client = client end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/opennebula/hook.rb', line 46 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
94 95 96 |
# File 'lib/opennebula/hook.rb', line 94 def allocate(template) super(HOOK_METHODS[:allocate], template) end |
#delete ⇒ nil, OpenNebula::Error
Deletes the Hook
102 103 104 |
# File 'lib/opennebula/hook.rb', line 102 def delete call(HOOK_METHODS[:delete], @pe_id) end |
#gid ⇒ Object
Returns the group identifier
- return
-
Integer the element’s group ID
144 145 146 |
# File 'lib/opennebula/hook.rb', line 144 def gid self['GID'].to_i end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Hook.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/opennebula/hook.rb', line 70 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 |
#owner_id ⇒ Object
148 149 150 |
# File 'lib/opennebula/hook.rb', line 148 def owner_id self['UID'].to_i end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Hook
124 125 126 |
# File 'lib/opennebula/hook.rb', line 124 def rename(name) call(HOOK_METHODS[:rename], @pe_id, name) end |
#retry(exec_id) ⇒ nil, OpenNebula::Error
Retry a previous execution of the hook.
134 135 136 |
# File 'lib/opennebula/hook.rb', line 134 def retry(exec_id) call(HOOK_METHODS[:retry], @pe_id, exec_id) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the Hook contents
114 115 116 |
# File 'lib/opennebula/hook.rb', line 114 def update(new_template, append = false) super(HOOK_METHODS[:update], new_template, append ? 1 : 0) end |