class OpenNebula::Cluster

Constants

CLUSTER_METHODS

Constants and Class Methods

Public Class Methods

build_xml(pe_id=nil) click to toggle source

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
new(xml, client) click to toggle source

Class constructor

Calls superclass method
# File lib/opennebula/cluster.rb, line 58
def initialize(xml, client)
    super(xml,client)
end

Public Instance Methods

adddatastore(ds_id) click to toggle source

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
addhost(hid) click to toggle source

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
addvnet(vnet_id) click to toggle source

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
allocate(clustername) click to toggle source

Allocates a new Cluster in OpenNebula

clustername A string containing the name of the Cluster.

Calls superclass method
# File lib/opennebula/cluster.rb, line 76
def allocate(clustername)
    super(CLUSTER_METHODS[:allocate], clustername)
end
contains_datastore?(id) click to toggle source

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
contains_host?(id) click to toggle source

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
contains_vnet?(id) click to toggle source

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
datastore_ids() click to toggle source

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
deldatastore(ds_id) click to toggle source

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
delete() click to toggle source

Deletes the Cluster

Calls superclass method
# File lib/opennebula/cluster.rb, line 81
def delete()
    super(CLUSTER_METHODS[:delete])
end
delhost(hid) click to toggle source

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
delvnet(vnet_id) click to toggle source

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
host_ids() click to toggle source

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
info() click to toggle source

Retrieves the information of the given Cluster.

Calls superclass method
# File lib/opennebula/cluster.rb, line 67
def info()
    super(CLUSTER_METHODS[:info], 'CLUSTER')
end
Also aliased as: info!
info!()
Alias for: info
rename(name) click to toggle source

Renames this Cluster

@param name [String] New name for the Cluster.

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/cluster.rb, line 181
def rename(name)
    return call(CLUSTER_METHODS[:rename], @pe_id, name)
end
update(new_template, append=false) click to toggle source

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
Calls superclass method
# File lib/opennebula/cluster.rb, line 171
def update(new_template, append=false)
    super(CLUSTER_METHODS[:update], new_template, append ? 1 : 0)
end
vnet_ids() click to toggle source

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

contains_resource?(xpath, id) click to toggle source
# 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