class OpenNebula::Cluster
Constants
- CLUSTER_METHODS
Constants and Class Methods
Public Class Methods
Creates a Cluster description with just its
identifier this method should be used to create plain Cluster objects. id
the id of the host
Example:
cluster = Cluster.new(Cluster.build_xml(3),rpc_client)
# File lib/opennebula/cluster.rb, line 47 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
Class constructor
# File lib/opennebula/cluster.rb, line 58 def initialize(xml, client) super(xml,client) end
Public Instance Methods
Adds a Datastore to this Cluster @param ds_id [Integer] Datastore ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 115 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
Adds a Host to this Cluster @param hid [Integer] Host ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 89 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
Adds a VNet to this Cluster @param vnet_id [Integer] VNet ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 141 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
Allocates a new Cluster in OpenNebula
clustername
A string containing the name of the Cluster.
# File lib/opennebula/cluster.rb, line 76 def allocate(clustername) super(CLUSTER_METHODS[:allocate], clustername) end
Returns whether or not the datastore with 'id' is part of this cluster @param id [Integer|Array] datastore ID @return [Boolean] true if found
# File lib/opennebula/cluster.rb, line 211 def contains_datastore?(id) contains_resource?('DATASTORES/ID', id) end
Returns whether or not the host with 'id' is part of this cluster @param id [Integer|Array] host ID @return [Boolean] true if found
# File lib/opennebula/cluster.rb, line 192 def contains_host?(id) contains_resource?('HOSTS/ID', id) end
Returns whether or not the vnet with 'id' is part of this cluster @param id [Integer|Arrray] vnet ID @return [Boolean] true if found
# File lib/opennebula/cluster.rb, line 230 def contains_vnet?(id) contains_resource?('VNETS/ID', id) end
Returns an array with the numeric datastore ids @return [Array<Integer>]
# File lib/opennebula/cluster.rb, line 217 def datastore_ids array = Array.new self.each("DATASTORES/ID") do |id| array << id.text.to_i end return array end
Deletes a Datastore from this Cluster @param ds_id [Integer] Datastore ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 128 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
Deletes the Cluster
# File lib/opennebula/cluster.rb, line 81 def delete() super(CLUSTER_METHODS[:delete]) end
Deletes a Host from this Cluster @param hid [Integer] Host ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 102 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
Deletes a VNet from this Cluster @param vnet_id [Integer] VNet ID @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 154 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
Returns an array with the numeric host ids @return [Array<Integer>]
# File lib/opennebula/cluster.rb, line 198 def host_ids array = Array.new self.each("HOSTS/ID") do |id| array << id.text.to_i end return array end
Retrieves the information of the given Cluster.
# File lib/opennebula/cluster.rb, line 67 def info() super(CLUSTER_METHODS[:info], 'CLUSTER') end
Replaces the template contents
@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of
replace the whole template
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
# File lib/opennebula/cluster.rb, line 171 def update(new_template, append=false) super(CLUSTER_METHODS[:update], new_template, append ? 1 : 0) end
Returns an array with the numeric vnet ids @return [Array<Integer>]
# File lib/opennebula/cluster.rb, line 236 def vnet_ids array = Array.new self.each("VNETS/ID") do |id| array << id.text.to_i end return array end
Private Instance Methods
# File lib/opennebula/cluster.rb, line 248 def contains_resource?(xpath, id) id_array = retrieve_elements(xpath) return false if id_array.nil? id = [id] if id.class != Array id.each { |i| return false if !id_array.include?(i.to_s) } return true end