class OpenNebula::Cluster

Constants

CLUSTER_METHODS

Constants and Class Methods

PLAN_STATE

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

Class constructor

Calls superclass method
# File lib/opennebula/cluster.rb, line 63
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 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) 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 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) 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 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) 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 81
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 240
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 221
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 259
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 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) 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 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() click to toggle source

Deletes the Cluster

Calls superclass method
# File lib/opennebula/cluster.rb, line 86
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 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) 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 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() click to toggle source

Returns an array with the numeric host ids @return [Array<Integer>]

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

Retrieves the information of the given Cluster.

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

Create optimization plan for the Cluster

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

otherwise
# File lib/opennebula/cluster.rb, line 194
def optimize()
    return call(CLUSTER_METHODS[:optimize], @pe_id)
end
plan_actions() click to toggle source

Returns an array plan actions @return [Array<PlanAction>]

# File lib/opennebula/cluster.rb, line 285
def plan_actions
    [self.to_hash['CLUSTER']['PLAN']['ACTION']].flatten
end
plan_delete() click to toggle source

Delete optimization plan for the Cluster

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

otherwise
# File lib/opennebula/cluster.rb, line 210
def plan_delete()
    return call(CLUSTER_METHODS[:plandelete], @pe_id)
end
plan_execute() click to toggle source

Start applying the optimization plan for the Cluster

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

otherwise
# File lib/opennebula/cluster.rb, line 202
def plan_execute()
    return call(CLUSTER_METHODS[:planexecute], @pe_id)
end
plan_state() click to toggle source

Returns state of optimization plan @return [Integer] -1 if no plan

# File lib/opennebula/cluster.rb, line 277
def plan_state
    state = self['PLAN/STATE'] || -1

    state.to_i
end
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 186
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 176
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 265
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 291
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