class OpenNebula::PoolElement

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

Attributes

name[R]

Gets element name

return

String the PoolElement name

Public Class Methods

new(node, client) click to toggle source
node

_XML_is a XML element that represents the Pool element

client

Client represents a XML-RPC connection

# File lib/opennebula/pool_element.rb, line 29
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) click to toggle source

Creates new element specifying its id

id

identifyier of the element

client

initialized OpenNebula::Client object

# File lib/opennebula/pool_element.rb, line 212
def self.new_with_id(id, client = nil)
    new(build_xml(id), client)
end

Public Instance Methods

id() click to toggle source

Returns element identifier

return

Integer the PoolElement ID

# File lib/opennebula/pool_element.rb, line 218
def id
    @pe_id
end
replace(opts, xpath = 'TEMPLATE') click to toggle source

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

@param [String] xpath @param [Hash] options object containing pair key-value

@returns the new xml representation

# 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_str() click to toggle source

DO NOT USE - ONLY REXML BACKEND

# File lib/opennebula/pool_element.rb, line 227
def to_str
    str = ''
    REXML::Formatters::Pretty.new(1).write(@xml, str)

    str
end

Protected Instance Methods

allocate(xml_method, *args) click to toggle source

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

@param [String] xml_method the name of the XML-RPC method @param [Array] args any extra arguments for the xml-rpc method

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 94
def allocate(xml_method, *args)
    rc = @client.call(xml_method, *args)

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

    rc
end
call(xml_method, *args) click to toggle source

Common client call wrapper. Checks that @pe_id is defined, and returns nil instead of the response if it is successful

@param [String] xml_method xml-rpc method @param [Array] args any arguments for the xml-rpc method

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 53
def call(xml_method, *args)
    return Error.new('ID not defined') unless @pe_id

    rc = @client.call(xml_method, *args)
    rc = nil unless OpenNebula.is_error?(rc)

    rc
end
chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u, other_m, other_a) click to toggle source

Calls to the corresponding chmod method to modify the object’s permission bits Each [Integer] parameter must be 1 to allow, 0 deny, -1 do not change

@param xml_method [String] the name of the XML-RPC method

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 177
def chmod(xml_method, owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
          other_m, other_a)
    call(xml_method, @pe_id, owner_u, owner_m,
         owner_a, group_u, group_m, group_a, other_u,
         other_m, other_a)
end
chmod_octet(_xml_method, octet) click to toggle source

Calls to the corresponding chmod method to modify the object’s permission bits

@param xml_method [String] the name of the XML-RPC method @param octet [String] Permissions octed , e.g. 640

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 154
def chmod_octet(_xml_method, octet)
    owner_u = octet[0..0].to_i & 4 != 0 ? 1 : 0
    owner_m = octet[0..0].to_i & 2 != 0 ? 1 : 0
    owner_a = octet[0..0].to_i & 1 != 0 ? 1 : 0
    group_u = octet[1..1].to_i & 4 != 0 ? 1 : 0
    group_m = octet[1..1].to_i & 2 != 0 ? 1 : 0
    group_a = octet[1..1].to_i & 1 != 0 ? 1 : 0
    other_u = octet[2..2].to_i & 4 != 0 ? 1 : 0
    other_m = octet[2..2].to_i & 2 != 0 ? 1 : 0
    other_a = octet[2..2].to_i & 1 != 0 ? 1 : 0

    chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
          other_m, other_a)
end
chown(xml_method, uid, gid) click to toggle source

Calls to the corresponding chown method to modify the object’s owner and group

@param [String] xml_method the name of the XML-RPC method @param [Integer] uid the new owner id. Set to -1 to leave the current one @param [Integer] gid the new goup id. Set to -1 to leave the current one

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 142
def chown(xml_method, uid, gid)
    call(xml_method, @pe_id, uid, gid)
end
delete(xml_method) click to toggle source

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

@param [String] xml_method the name of the XML-RPC method

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 129
def delete(xml_method)
    call(xml_method, @pe_id)
end
info(xml_method, root_element, decrypt = false) click to toggle source

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

@param [String] xml_method the name of the XML-RPC method @param [String] root_element Base XML element name

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 70
def info(xml_method, root_element, decrypt = false)
    return Error.new('ID not defined') unless @pe_id

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

    if !OpenNebula.is_error?(rc)
        initialize_xml(rc, root_element)
        rc = nil

        @pe_id = self['ID'].to_i if self['ID']
        @name  = self['NAME'] if self['NAME']
    end

    rc
end
monitoring(xml_method, xpaths) click to toggle source

Retrieves this Element’s monitoring data from OpenNebula

@param [String] xml_method the name of the XML-RPC method @param xpaths [Array<String>] Xpath expressions for the elements to retrieve.

@return [Hash<String, Array<Array<int>>, OpenNebula::Error] Hash with

the requested xpath expressions, and an Array of [timestamp, value].
# File lib/opennebula/pool_element.rb, line 192
def monitoring(xml_method, xpaths)
    return Error.new('ID not defined') unless @pe_id

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

    if OpenNebula.is_error?(rc)
        return rc
    end

    xmldoc = XMLElement.new
    xmldoc.initialize_xml(rc, 'MONITORING_DATA')

    OpenNebula.process_monitoring(xmldoc, @pe_id, xpaths)
end
update(xml_method, new_template, *args) click to toggle source

Calls to the corresponding update method to modify the object’s template

@param [String] xml_method the name of the XML-RPC method @param [String] new_template the new template contents @param [Array] args any extra arguments for the xml-rpc method

@return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/pool_element.rb, line 114
def update(xml_method, new_template, *args)
    if new_template.nil?
        return Error.new('Wrong argument', Error::EXML_RPC_CALL)
    end

    call(xml_method, @pe_id, new_template, *args)
end