Class: OpenNebula::Host
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Host
- Defined in:
- lib/opennebula/host.rb
Constant Summary collapse
- HOST_METHODS =
{ :info => "host.info", :allocate => "host.allocate", :delete => "host.delete", :enable => "host.enable", :update => "host.update", :monitoring => "host.monitoring", :rename => "host.rename" }
- HOST_STATES =
%w{INIT MONITORING_MONITORED MONITORED ERROR DISABLED MONITORING_ERROR MONITORING_INIT MONITORING_DISABLED}
- SHORT_HOST_STATES =
{ "INIT" => "init", "MONITORING_MONITORED" => "update", "MONITORED" => "on", "ERROR" => "err", "DISABLED" => "off", "MONITORING_ERROR" => "retry", "MONITORING_INIT" => "init", "MONITORING_DISABLED" => "off" }
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Host description with just its identifier this method should be used to create plain Host objects.
Instance Method Summary collapse
-
#allocate(hostname, im, vmm, vnm, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new Host in OpenNebula.
-
#delete ⇒ Object
Deletes the Host.
-
#disable ⇒ Object
Disables the Host.
-
#enable ⇒ Object
Enables the Host.
- #flush ⇒ Object
-
#import_wild(name) ⇒ nil, OpenNebula::Error
Imports a wild VM from the host and puts it in running state.
-
#importable_wilds ⇒ Object
Get importable wild VMs in the host.
-
#info ⇒ Object
(also: #info!)
Retrieves the information of the given Host.
-
#initialize(xml, client) ⇒ Host
constructor
Class constructor.
-
#monitoring(xpath_expressions) ⇒ Hash<String, Array<Array<int>>>, OpenNebula::Error
Retrieves this Host’s monitoring data from OpenNebula.
-
#monitoring_xml ⇒ String
Retrieves this Host’s monitoring data from OpenNebula, in XML.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Host.
-
#short_state_str ⇒ Object
Returns the state of the Host (string value).
-
#state ⇒ Object
Returns the state of the Host (numeric value).
-
#state_str ⇒ Object
Returns the state of the Host (string value).
-
#template_str(indent = true) ⇒ Object
- Returns the <TEMPLATE> element in text form indent
-
Boolean indents the resulting string, default true.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
-
#wilds ⇒ Object
Get wild VMs in the host.
Methods inherited from PoolElement
#id, #name, new_with_id, #to_str
Methods inherited from XMLElement
#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_xml, #text, #to_hash, #to_xml
Constructor Details
#initialize(xml, client) ⇒ Host
Class constructor
69 70 71 72 73 74 |
# File 'lib/opennebula/host.rb', line 69 def initialize(xml, client) super(xml,client) @client = client @pe_id = self['ID'].to_i if self['ID'] end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/opennebula/host.rb', line 58 def Host.build_xml(pe_id=nil) if pe_id host_xml = "<HOST><ID>#{pe_id}</ID></HOST>" else host_xml = "<HOST></HOST>" end XMLElement.build_xml(host_xml, 'HOST') end |
Instance Method Details
#allocate(hostname, im, vmm, vnm, cluster_id = ClusterPool::NONE_CLUSTER_ID) ⇒ Integer, OpenNebula::Error
Allocates a new Host in OpenNebula
97 98 99 |
# File 'lib/opennebula/host.rb', line 97 def allocate(hostname,im,vmm,vnm,cluster_id=ClusterPool::NONE_CLUSTER_ID) super(HOST_METHODS[:allocate],hostname,im,vmm,vnm,cluster_id) end |
#delete ⇒ Object
Deletes the Host
102 103 104 |
# File 'lib/opennebula/host.rb', line 102 def delete() super(HOST_METHODS[:delete]) end |
#disable ⇒ Object
Disables the Host
112 113 114 |
# File 'lib/opennebula/host.rb', line 112 def disable() set_enabled(false) end |
#enable ⇒ Object
Enables the Host
107 108 109 |
# File 'lib/opennebula/host.rb', line 107 def enable() set_enabled(true) end |
#flush ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/opennebula/host.rb', line 116 def flush() self.disable vm_pool = OpenNebula::VirtualMachinePool.new(@client, VirtualMachinePool::INFO_ALL_VM) rc = vm_pool.info if OpenNebula.is_error?(rc) puts rc. exit -1 end vm_pool.each do |vm| hid = vm['HISTORY_RECORDS/HISTORY[last()]/HID'] if hid == self['ID'] vm.resched end end end |
#import_wild(name) ⇒ nil, OpenNebula::Error
Imports a wild VM from the host and puts it in running state
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/opennebula/host.rb', line 197 def import_wild(name) vms = importable_wilds.select {|vm| vm['VM_NAME'] == name } if vms.length == 0 return OpenNebula::Error.new("No importable wilds with name " << "'#{name}' found.") elsif vms.length > 1 return OpenNebula::Error.new("More than one importable wild " << "with name '#{name}' found.") end wild = vms.first template = Base64.decode64(wild['IMPORT_TEMPLATE']) xml = OpenNebula::VirtualMachine.build_xml vm = OpenNebula::VirtualMachine.new(xml, @client) rc = vm.allocate(template) return rc if OpenNebula.is_error?(rc) vm.deploy(id, false) end |
#importable_wilds ⇒ Object
Get importable wild VMs in the host
253 254 255 |
# File 'lib/opennebula/host.rb', line 253 def importable_wilds wilds.select {|w| Hash === w && w['IMPORT_TEMPLATE'] } end |
#info ⇒ Object Also known as: info!
Retrieves the information of the given Host.
81 82 83 |
# File 'lib/opennebula/host.rb', line 81 def info() super(HOST_METHODS[:info], 'HOST') end |
#monitoring(xpath_expressions) ⇒ Hash<String, Array<Array<int>>>, OpenNebula::Error
Retrieves this Host’s monitoring data from OpenNebula
167 168 169 170 |
# File 'lib/opennebula/host.rb', line 167 def monitoring(xpath_expressions) return super(HOST_METHODS[:monitoring], 'HOST', 'LAST_MON_TIME', xpath_expressions) end |
#monitoring_xml ⇒ String
Retrieves this Host’s monitoring data from OpenNebula, in XML
175 176 177 178 179 |
# File 'lib/opennebula/host.rb', line 175 def monitoring_xml() return Error.new('ID not defined') if !@pe_id return @client.call(HOST_METHODS[:monitoring], @pe_id) end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Host
187 188 189 |
# File 'lib/opennebula/host.rb', line 187 def rename(name) return call(HOST_METHODS[:rename], @pe_id, name) end |
#short_state_str ⇒ Object
Returns the state of the Host (string value)
237 238 239 |
# File 'lib/opennebula/host.rb', line 237 def short_state_str SHORT_HOST_STATES[state_str] end |
#state ⇒ Object
Returns the state of the Host (numeric value)
227 228 229 |
# File 'lib/opennebula/host.rb', line 227 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the Host (string value)
232 233 234 |
# File 'lib/opennebula/host.rb', line 232 def state_str HOST_STATES[state] end |
#template_str(indent = true) ⇒ Object
Returns the <TEMPLATE> element in text form
- indent
-
Boolean indents the resulting string, default true
243 244 245 |
# File 'lib/opennebula/host.rb', line 243 def template_str(indent=true) template_like_str('TEMPLATE', indent) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
144 145 146 |
# File 'lib/opennebula/host.rb', line 144 def update(new_template, append=false) super(HOST_METHODS[:update], new_template, append ? 1 : 0) end |
#wilds ⇒ Object
Get wild VMs in the host
248 249 250 |
# File 'lib/opennebula/host.rb', line 248 def wilds [self.to_hash['HOST']['TEMPLATE']['VM']].flatten.compact end |