Class: OpenNebula::PoolElement

Inherits:
XMLElement show all
Defined in:
lib/opennebula/pool_element.rb

Overview

The PoolElement Class represents a generic element of a Pool in XML format

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from XMLElement

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

Instance Attribute Details

#nameObject (readonly)

Gets element name

return

String the PoolElement name



224
225
226
# File 'lib/opennebula/pool_element.rb', line 224

def name
  @name
end

Class Method Details

.new_with_id(id, client = nil) ⇒ Object

Creates new element specifying its id

id

identifyier of the element

client

initialized OpenNebula::Client object



212
213
214
# File 'lib/opennebula/pool_element.rb', line 212

def self.new_with_id(id, client = nil)
    new(build_xml(id), client)
end

Instance Method Details

#idObject

Returns element identifier

return

Integer the PoolElement ID



218
219
220
# File 'lib/opennebula/pool_element.rb', line 218

def id
    @pe_id
end

#replace(opts, xpath = 'TEMPLATE') ⇒ Object

Replace the xml pointed by xpath using a Hash object one object will be modified taking hash object pairs

Parameters:

  • xpath (String) (defaults to: 'TEMPLATE')
  • options (Hash)

    object containing pair key-value



241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/opennebula/pool_element.rb', line 241

def replace(opts, xpath = 'TEMPLATE')
    return unless self[xpath]

    opts.each do |att, value|
        xpath_u = xpath+"/#{att}"
        docs = retrieve_xmlelements(xpath_u)
        if docs.size == 1
            docs[0].set_content(value)
        end
    end
    update(template_like_str(xpath))
end

#to_strObject

DO NOT USE - ONLY REXML BACKEND



227
228
229
230
231
232
# File 'lib/opennebula/pool_element.rb', line 227

def to_str
    str = ''
    REXML::Formatters::Pretty.new(1).write(@xml, str)

    str
end