Class: OpenNebula::Cluster

Inherits:
PoolElement show all
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

#name

Class Method Summary collapse

Instance Method Summary collapse

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

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)


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

Parameters:

  • ds_id (Integer)

    Datastore ID

Returns:



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

Parameters:

  • hid (Integer)

    Host ID

Returns:



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

Parameters:

  • vnet_id (Integer)

    VNet ID

Returns:



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

Parameters:

  • id (Integer|Array)

    datastore ID

Returns:

  • (Boolean)

    true if found



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

Parameters:

  • id (Integer|Array)

    host ID

Returns:

  • (Boolean)

    true if found



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

Parameters:

  • id (Integer|Arrray)

    vnet ID

Returns:

  • (Boolean)

    true if found



259
260
261
# File 'lib/opennebula/cluster.rb', line 259

def contains_vnet?(id)
    contains_resource?('VNETS/ID', id)
end

#datastore_idsArray<Integer>

Returns an array with the numeric datastore ids

Returns:

  • (Array<Integer>)


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

Parameters:

  • ds_id (Integer)

    Datastore ID

Returns:



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

#deleteObject

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

Parameters:

  • hid (Integer)

    Host ID

Returns:



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

Parameters:

  • vnet_id (Integer)

    VNet ID

Returns:



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_idsArray<Integer>

Returns an array with the numeric host ids

Returns:

  • (Array<Integer>)


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

#optimizenil, OpenNebula::Error

Create optimization plan for the Cluster

Returns:



194
195
196
# File 'lib/opennebula/cluster.rb', line 194

def optimize()
    return call(CLUSTER_METHODS[:optimize], @pe_id)
end

#plan_actionsArray<PlanAction>

Returns an array plan actions

Returns:

  • (Array<PlanAction>)


285
286
287
# File 'lib/opennebula/cluster.rb', line 285

def plan_actions
    [self.to_hash['CLUSTER']['PLAN']['ACTION']].flatten
end

#plan_deletenil, OpenNebula::Error

Delete optimization plan for the Cluster

Returns:



210
211
212
# File 'lib/opennebula/cluster.rb', line 210

def plan_delete()
    return call(CLUSTER_METHODS[:plandelete], @pe_id)
end

#plan_executenil, OpenNebula::Error

Start applying the optimization plan for the Cluster

Returns:



202
203
204
# File 'lib/opennebula/cluster.rb', line 202

def plan_execute()
    return call(CLUSTER_METHODS[:planexecute], @pe_id)
end

#plan_stateInteger

Returns state of optimization plan

Returns:

  • (Integer)

    -1 if no 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

Parameters:

  • name (String)

    New name for the Cluster.

Returns:



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

Parameters:

  • new_template (String)

    New template contents

  • append (true, false) (defaults to: false)

    True to append new attributes instead of replace the whole template

Returns:



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_idsArray<Integer>

Returns an array with the numeric vnet ids

Returns:

  • (Array<Integer>)


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