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

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?

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)
    self.new(self.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

#nameObject

Gets element name

return

String the PoolElement name



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

def name
    @name
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



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

def replace(opts, xpath = "TEMPLATE")
    if 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
end

#to_strObject

DO NOT USE - ONLY REXML BACKEND



229
230
231
232
233
234
# File 'lib/opennebula/pool_element.rb', line 229

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

    return str
end