Class: OpenNebula::Cluster
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Cluster
- Defined in:
- lib/opennebula/cluster.rb
Constant Summary collapse
- CLUSTER_METHODS =
Constants and Class Methods
{ :info => "cluster.info", :allocate => "cluster.allocate", :delete => "cluster.delete", :addhost => "cluster.addhost", :delhost => "cluster.delhost", :adddatastore => "cluster.adddatastore", :deldatastore => "cluster.deldatastore", :addvnet => "cluster.addvnet", :delvnet => "cluster.delvnet", :update => "cluster.update", :rename => "cluster.rename", :optimize => "cluster.optimize", :planexecute => "cluster.planexecute", :plandelete => "cluster.plandelete" }
- PLAN_STATE =
['READY', 'APPLYING', 'DONE', 'ERROR', 'TIMEOUT']
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Cluster description with just its identifier this method should be used to create plain Cluster objects.
Instance Method Summary collapse
-
#adddatastore(ds_id) ⇒ nil, OpenNebula::Error
Adds a Datastore to this Cluster.
-
#addhost(hid) ⇒ nil, OpenNebula::Error
Adds a Host to this Cluster.
-
#addvnet(vnet_id) ⇒ nil, OpenNebula::Error
Adds a VNet to this Cluster.
-
#allocate(clustername) ⇒ Object
Allocates a new Cluster in OpenNebula.
-
#contains_datastore?(id) ⇒ Boolean
Returns whether or not the datastore with ‘id’ is part of this cluster.
-
#contains_host?(id) ⇒ Boolean
Returns whether or not the host with ‘id’ is part of this cluster.
-
#contains_vnet?(id) ⇒ Boolean
Returns whether or not the vnet with ‘id’ is part of this cluster.
-
#datastore_ids ⇒ Array<Integer>
Returns an array with the numeric datastore ids.
-
#deldatastore(ds_id) ⇒ nil, OpenNebula::Error
Deletes a Datastore from this Cluster.
-
#delete ⇒ Object
Deletes the Cluster.
-
#delhost(hid) ⇒ nil, OpenNebula::Error
Deletes a Host from this Cluster.
-
#delvnet(vnet_id) ⇒ nil, OpenNebula::Error
Deletes a VNet from this Cluster.
-
#host_ids ⇒ Array<Integer>
Returns an array with the numeric host ids.
-
#info(decrypt = false) ⇒ Object
(also: #info!)
Retrieves the information of the given Cluster.
-
#initialize(xml, client) ⇒ Cluster
constructor
Class constructor.
-
#optimize ⇒ nil, OpenNebula::Error
Create optimization plan for the Cluster.
-
#plan_actions ⇒ Array<PlanAction>
Returns an array plan actions.
-
#plan_delete ⇒ nil, OpenNebula::Error
Delete optimization plan for the Cluster.
-
#plan_execute ⇒ nil, OpenNebula::Error
Start applying the optimization plan for the Cluster.
-
#plan_state ⇒ Integer
Returns state of optimization plan.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Cluster.
-
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
-
#vnet_ids ⇒ Array<Integer>
Returns an array with the numeric vnet ids.
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) ⇒ Cluster
Class constructor
63 64 65 |
# File 'lib/opennebula/cluster.rb', line 63 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/opennebula/cluster.rb', line 52 def Cluster.build_xml(pe_id=nil) if pe_id cluster_xml = "<CLUSTER><ID>#{pe_id}</ID></CLUSTER>" else cluster_xml = "<CLUSTER></CLUSTER>" end XMLElement.build_xml(cluster_xml,'CLUSTER') end |
Instance Method Details
#adddatastore(ds_id) ⇒ nil, OpenNebula::Error
Adds a Datastore to this Cluster
120 121 122 123 124 125 126 127 |
# File 'lib/opennebula/cluster.rb', line 120 def adddatastore(ds_id) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:adddatastore], @pe_id, ds_id) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#addhost(hid) ⇒ nil, OpenNebula::Error
Adds a Host to this Cluster
94 95 96 97 98 99 100 101 |
# File 'lib/opennebula/cluster.rb', line 94 def addhost(hid) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:addhost], @pe_id, hid) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#addvnet(vnet_id) ⇒ nil, OpenNebula::Error
Adds a VNet to this Cluster
146 147 148 149 150 151 152 153 |
# File 'lib/opennebula/cluster.rb', line 146 def addvnet(vnet_id) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:addvnet], @pe_id, vnet_id) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#allocate(clustername) ⇒ Object
Allocates a new Cluster in OpenNebula
clustername A string containing the name of the Cluster.
81 82 83 |
# File 'lib/opennebula/cluster.rb', line 81 def allocate(clustername) super(CLUSTER_METHODS[:allocate], clustername) end |
#contains_datastore?(id) ⇒ Boolean
Returns whether or not the datastore with ‘id’ is part of this cluster
240 241 242 |
# File 'lib/opennebula/cluster.rb', line 240 def contains_datastore?(id) contains_resource?('DATASTORES/ID', id) end |
#contains_host?(id) ⇒ Boolean
Returns whether or not the host with ‘id’ is part of this cluster
221 222 223 |
# File 'lib/opennebula/cluster.rb', line 221 def contains_host?(id) contains_resource?('HOSTS/ID', id) end |
#contains_vnet?(id) ⇒ Boolean
Returns whether or not the vnet with ‘id’ is part of this cluster
259 260 261 |
# File 'lib/opennebula/cluster.rb', line 259 def contains_vnet?(id) contains_resource?('VNETS/ID', id) end |
#datastore_ids ⇒ Array<Integer>
Returns an array with the numeric datastore ids
246 247 248 249 250 251 252 253 254 |
# File 'lib/opennebula/cluster.rb', line 246 def datastore_ids array = Array.new self.each("DATASTORES/ID") do |id| array << id.text.to_i end return array end |
#deldatastore(ds_id) ⇒ nil, OpenNebula::Error
Deletes a Datastore from this Cluster
133 134 135 136 137 138 139 140 |
# File 'lib/opennebula/cluster.rb', line 133 def deldatastore(ds_id) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:deldatastore], @pe_id, ds_id) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#delete ⇒ Object
Deletes the Cluster
86 87 88 |
# File 'lib/opennebula/cluster.rb', line 86 def delete() super(CLUSTER_METHODS[:delete]) end |
#delhost(hid) ⇒ nil, OpenNebula::Error
Deletes a Host from this Cluster
107 108 109 110 111 112 113 114 |
# File 'lib/opennebula/cluster.rb', line 107 def delhost(hid) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:delhost], @pe_id, hid) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#delvnet(vnet_id) ⇒ nil, OpenNebula::Error
Deletes a VNet from this Cluster
159 160 161 162 163 164 165 166 |
# File 'lib/opennebula/cluster.rb', line 159 def delvnet(vnet_id) return Error.new('ID not defined') if !@pe_id rc = @client.call(CLUSTER_METHODS[:delvnet], @pe_id, vnet_id) rc = nil if !OpenNebula.is_error?(rc) return rc end |
#host_ids ⇒ Array<Integer>
Returns an array with the numeric host ids
227 228 229 230 231 232 233 234 235 |
# File 'lib/opennebula/cluster.rb', line 227 def host_ids array = Array.new self.each("HOSTS/ID") do |id| array << id.text.to_i end return array end |
#info(decrypt = false) ⇒ Object Also known as: info!
Retrieves the information of the given Cluster.
72 73 74 |
# File 'lib/opennebula/cluster.rb', line 72 def info(decrypt = false) super(CLUSTER_METHODS[:info], 'CLUSTER', decrypt) end |
#optimize ⇒ nil, OpenNebula::Error
Create optimization plan for the Cluster
194 195 196 |
# File 'lib/opennebula/cluster.rb', line 194 def optimize() return call(CLUSTER_METHODS[:optimize], @pe_id) end |
#plan_actions ⇒ Array<PlanAction>
Returns an array plan actions
285 286 287 |
# File 'lib/opennebula/cluster.rb', line 285 def plan_actions [self.to_hash['CLUSTER']['PLAN']['ACTION']].flatten end |
#plan_delete ⇒ nil, OpenNebula::Error
Delete optimization plan for the Cluster
210 211 212 |
# File 'lib/opennebula/cluster.rb', line 210 def plan_delete() return call(CLUSTER_METHODS[:plandelete], @pe_id) end |
#plan_execute ⇒ nil, OpenNebula::Error
Start applying the optimization plan for the Cluster
202 203 204 |
# File 'lib/opennebula/cluster.rb', line 202 def plan_execute() return call(CLUSTER_METHODS[:planexecute], @pe_id) end |
#plan_state ⇒ Integer
Returns state of optimization plan
277 278 279 280 281 |
# File 'lib/opennebula/cluster.rb', line 277 def plan_state state = self['PLAN/STATE'] || -1 state.to_i end |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Cluster
186 187 188 |
# File 'lib/opennebula/cluster.rb', line 186 def rename(name) return call(CLUSTER_METHODS[:rename], @pe_id, name) end |
#update(new_template, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
176 177 178 |
# File 'lib/opennebula/cluster.rb', line 176 def update(new_template, append=false) super(CLUSTER_METHODS[:update], new_template, append ? 1 : 0) end |
#vnet_ids ⇒ Array<Integer>
Returns an array with the numeric vnet ids
265 266 267 268 269 270 271 272 273 |
# File 'lib/opennebula/cluster.rb', line 265 def vnet_ids array = Array.new self.each("VNETS/ID") do |id| array << id.text.to_i end return array end |