Class OpenNebula::PoolElement

  1. OpenNebula/Pool.rb
Parent: Object

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

Methods

public class

  1. new
  2. new_with_id

public instance

  1. id
  2. name
  3. to_str

protected instance

  1. allocate
  2. delete
  3. info

Included modules

  1. XMLUtilsElement

Public class methods

new (node, client)
node:_XML_is a XML element that represents the Pool element
client:Client represents a XML-RPC connection
[show source]
# File OpenNebula/Pool.rb, line 77
        def initialize(node, client)
            @xml    = node
            @client = client

            if self['ID']
                @pe_id = self['ID'].to_i
            else
                @pe_id = nil
            end
            @name = self['NAME'] if self['NAME']
        end
new_with_id (id, client=nil)

Creates new element specifying its id

id:identifyier of the element
client:initialized OpenNebula::Client object
[show source]
# File OpenNebula/Pool.rb, line 149
        def self.new_with_id(id, client=nil)
            self.new(self.build_xml(id), client)
        end

Public instance methods

id ()

Returns element identifier

return
Integer the PoolElement ID
[show source]
# File OpenNebula/Pool.rb, line 155
        def id
            @pe_id
        end
name ()

Gets element name

return
String the PoolElement name
[show source]
# File OpenNebula/Pool.rb, line 161
        def name
            @name
        end
to_str ()

DO NOT USE - ONLY REXML BACKEND

[show source]
# File OpenNebula/Pool.rb, line 166
        def to_str
            str = ""
            REXML::Formatters::Pretty.new(1).write(@xml,str)
            
            return str 
        end

Protected instance methods

allocate (xml_method, *args)

Calls to the corresponding allocate method to create a new element in the OpenNebula core

xml_method:String the name of the XML-RPC method
args:Array additional arguments including the template for the
new element
return
nil in case of success or an Error object
[show source]
# File OpenNebula/Pool.rb, line 120
        def allocate(xml_method, *args)
            rc = @client.call(xml_method, *args)

            if !OpenNebula.is_error?(rc)
                @pe_id = rc
                rc     = nil
            end

            return rc
        end
delete (xml_method)

Calls to the corresponding delete method to remove this element from the OpenNebula core

xml_method:String the name of the XML-RPC method
return
nil in case of success or an Error object
[show source]
# File OpenNebula/Pool.rb, line 135
        def delete(xml_method)
            return Error.new('ID not defined') if !@pe_id

            rc = @client.call(xml_method,@pe_id)
            rc = nil if !OpenNebula.is_error?(rc)

            return rc
        end
info (xml_method, root_element)

Calls to the corresponding info method to retreive the element detailed information in XML format

xml_method:String the name of the XML-RPC method
root_element:String Base XML element
return
nil in case of success or an Error object
[show source]
# File OpenNebula/Pool.rb, line 98
        def info(xml_method, root_element)
            return Error.new('ID not defined') if !@pe_id

            rc = @client.call(xml_method,@pe_id)

            if !OpenNebula.is_error?(rc)
                @xml = XMLUtilsElement::initialize_xml(rc, root_element)
                rc   = nil
                
                @pe_id = self['ID'].to_i if self['ID']
                @name  = self['NAME'] if self['NAME']
            end

            return rc
        end