Class: OpenNebula::Cluster

Inherits:
PoolElement show all
Defined in:
OpenNebula/Cluster.rb

Constant Summary

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",
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from PoolElement

#id, #name, new_with_id, #to_str

Methods inherited from XMLElement

#[], #add_element, #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml

Constructor Details

- (Cluster) initialize(xml, client)

Class constructor



57
58
59
# File 'OpenNebula/Cluster.rb', line 57

def initialize(xml, client)
    super(xml,client)
end

Class Method Details

+ (Object) build_xml(pe_id = nil)

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)


46
47
48
49
50
51
52
53
54
# File 'OpenNebula/Cluster.rb', line 46

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

- (nil, OpenNebula::Error) adddatastore(ds_id)

Adds a Datastore to this Cluster

Parameters:

  • ds_id (Integer)

    Datastore ID

Returns:



112
113
114
115
116
117
118
119
# File 'OpenNebula/Cluster.rb', line 112

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

- (nil, OpenNebula::Error) addhost(hid)

Adds a Host to this Cluster

Parameters:

  • hid (Integer)

    Host ID

Returns:



86
87
88
89
90
91
92
93
# File 'OpenNebula/Cluster.rb', line 86

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

- (nil, OpenNebula::Error) addvnet(vnet_id)

Adds a VNet to this Cluster

Parameters:

  • vnet_id (Integer)

    VNet ID

Returns:



138
139
140
141
142
143
144
145
# File 'OpenNebula/Cluster.rb', line 138

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

- (Object) allocate(clustername)

Allocates a new Cluster in OpenNebula

clustername A string containing the name of the Cluster.



73
74
75
# File 'OpenNebula/Cluster.rb', line 73

def allocate(clustername)
    super(CLUSTER_METHODS[:allocate], clustername)
end

- (Boolean) contains_datastore?(id)

Returns whether or not the datastore with 'id' is part of this cluster

Parameters:

  • id (Integer|Array)

    datastore ID

Returns:

  • (Boolean)

    true if found



196
197
198
# File 'OpenNebula/Cluster.rb', line 196

def contains_datastore?(id)
    contains_resource?('DATASTORES/ID', id)
end

- (Boolean) contains_host?(id)

Returns whether or not the host with 'id' is part of this cluster

Parameters:

  • id (Integer|Array)

    host ID

Returns:

  • (Boolean)

    true if found



177
178
179
# File 'OpenNebula/Cluster.rb', line 177

def contains_host?(id)
    contains_resource?('HOSTS/ID', id)
end

- (Boolean) contains_vnet?(id)

Returns whether or not the vnet with 'id' is part of this cluster

Parameters:

  • id (Integer|Arrray)

    vnet ID

Returns:

  • (Boolean)

    true if found



215
216
217
# File 'OpenNebula/Cluster.rb', line 215

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

- (Array<Integer>) datastore_ids

Returns an array with the numeric datastore ids

Returns:

  • (Array<Integer>)


202
203
204
205
206
207
208
209
210
# File 'OpenNebula/Cluster.rb', line 202

def datastore_ids
    array = Array.new

    self.each("DATASTORES/ID") do |id|
        array << id.text.to_i
    end

    return array
end

- (nil, OpenNebula::Error) deldatastore(ds_id)

Deletes a Datastore from this Cluster

Parameters:

  • ds_id (Integer)

    Datastore ID

Returns:



125
126
127
128
129
130
131
132
# File 'OpenNebula/Cluster.rb', line 125

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

- (Object) delete

Deletes the Cluster



78
79
80
# File 'OpenNebula/Cluster.rb', line 78

def delete()
    super(CLUSTER_METHODS[:delete])
end

- (nil, OpenNebula::Error) delhost(hid)

Deletes a Host from this Cluster

Parameters:

  • hid (Integer)

    Host ID

Returns:



99
100
101
102
103
104
105
106
# File 'OpenNebula/Cluster.rb', line 99

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

- (nil, OpenNebula::Error) delvnet(vnet_id)

Deletes a VNet from this Cluster

Parameters:

  • vnet_id (Integer)

    VNet ID

Returns:



151
152
153
154
155
156
157
158
# File 'OpenNebula/Cluster.rb', line 151

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

- (Array<Integer>) host_ids

Returns an array with the numeric host ids

Returns:

  • (Array<Integer>)


183
184
185
186
187
188
189
190
191
# File 'OpenNebula/Cluster.rb', line 183

def host_ids
    array = Array.new

    self.each("HOSTS/ID") do |id|
        array << id.text.to_i
    end

    return array
end

- (Object) info

Retrieves the information of the given Cluster.



66
67
68
# File 'OpenNebula/Cluster.rb', line 66

def info()
    super(CLUSTER_METHODS[:info], 'CLUSTER')
end

- (nil, OpenNebula::Error) update(new_template)

Replaces the template contents

Parameters:

  • new_template (String)

    New template contents

Returns:



166
167
168
# File 'OpenNebula/Cluster.rb', line 166

def update(new_template)
    super(CLUSTER_METHODS[:update], new_template)
end

- (Array<Integer>) vnet_ids

Returns an array with the numeric vnet ids

Returns:

  • (Array<Integer>)


221
222
223
224
225
226
227
228
229
# File 'OpenNebula/Cluster.rb', line 221

def vnet_ids
    array = Array.new

    self.each("VNETS/ID") do |id|
        array << id.text.to_i
    end

    return array
end