class OpenNebula::Zone

Constants

ZONE_METHODS

Constants and Class Methods

Public Class Methods

build_xml(pe_id=nil) click to toggle source

Creates a Zone description with just its identifier this method should be used to create plain Zone objects. @param id [Integer] the id of the Zone

Example:

zone = Zone.new(Zone.build_xml(3),rpc_client)
# File lib/opennebula/zone.rb, line 44
def Zone.build_xml(pe_id=nil)
    if pe_id
        zone_xml = "<ZONE><ID>#{pe_id}</ID></ZONE>"
    else
        zone_xml = "<ZONE></ZONE>"
    end

    XMLElement.build_xml(zone_xml,'ZONE')
end
new(xml, client) click to toggle source

Class constructor

Calls superclass method OpenNebula::PoolElement::new
# File lib/opennebula/zone.rb, line 55
def initialize(xml, client)
    super(xml,client)
end

Public Instance Methods

add_servers(servers) click to toggle source

Adds servers to this Zone

@param name [String] Template with zone servers

SERVER = [ NAME = "<server_name>", ENDPOINT = "<rpc_ep>" ]

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

otherwise
# File lib/opennebula/zone.rb, line 158
def add_servers(servers)
    return call(ZONE_METHODS[:addserver], @pe_id, servers)
end
allocate(description) click to toggle source

Allocates a new Zone in OpenNebula

@param description [String] The template of the Zone. @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#allocate
# File lib/opennebula/zone.rb, line 118
def allocate(description)
    super(ZONE_METHODS[:allocate], description)
end
delete() click to toggle source

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

otherwise
Calls superclass method OpenNebula::PoolElement#delete
# File lib/opennebula/zone.rb, line 137
def delete()
    super(ZONE_METHODS[:delete])
end
delete_servers(server_id) click to toggle source

Delete servers from this Zone

@param id [Int] Server ID

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

otherwise
# File lib/opennebula/zone.rb, line 168
def delete_servers(server_id)
    return call(ZONE_METHODS[:delserver], @pe_id, server_id)
end
info() click to toggle source

Retrieves the information of the given Zone. @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
Calls superclass method OpenNebula::PoolElement#info
# File lib/opennebula/zone.rb, line 66
def info()
    super(ZONE_METHODS[:info], 'ZONE')
end
Also aliased as: info!
info!()
Alias for: info
info_extended() click to toggle source

Retrieves the information extended of the given Zone. @return [nil, OpenNebula::Error] nil in case of success, Error

otherwise
# File lib/opennebula/zone.rb, line 73
def info_extended()
    rc = info()

    return rc if OpenNebula.is_error?(rc)

    @xml.xpath("SERVER_POOL/SERVER").each do |server|
        endpoint = server.xpath("ENDPOINT")
        endpoint = endpoint.text if endpoint

        next if endpoint.nil?

        client = OpenNebula::Client.new(nil, endpoint, {:timeout => 5})

        xml = client.call("zone.raftstatus")

        if OpenNebula.is_error?(xml)
            add_element(server, "STATE", "-")
            add_element(server, "TERM", "-")
            add_element(server, "VOTEDFOR", "-")
            add_element(server, "COMMIT", "-")
            add_element(server, "LOG_INDEX", "-")
            add_element(server, "FEDLOG_INDEX", "-")

            next
        end

        xml = Nokogiri::XML(xml)

        add_element_xml(server, xml, "STATE", "RAFT/STATE")
        add_element_xml(server, xml, "TERM", "RAFT/TERM")
        add_element_xml(server, xml, "VOTEDFOR", "RAFT/VOTEDFOR")
        add_element_xml(server, xml, "COMMIT", "RAFT/COMMIT")
        add_element_xml(server, xml, "LOG_INDEX", "RAFT/LOG_INDEX")
        add_element_xml(server, xml, "FEDLOG_INDEX","RAFT/FEDLOG_INDEX")
    end
end
Also aliased as: info_extended!
info_extended!()
Alias for: info_extended
rename(name) click to toggle source

Renames this Zone

@param name [String] New name for the Zone.

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

otherwise
# File lib/opennebula/zone.rb, line 147
def rename(name)
    return call(ZONE_METHODS[:rename], @pe_id, name)
end
reset_server(server_id) click to toggle source

Reset index for a follower

@param id [Int] Server ID

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

otherwise
# File lib/opennebula/zone.rb, line 178
def reset_server(server_id)
    return call(ZONE_METHODS[:resetserver], @pe_id, server_id)
end
update(new_template=nil, append=false) click to toggle source

Replaces the template contents

@param new_template [String] New template contents @param append [true, false] True to append new attributes instead of

replace the whole template

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

otherwise
Calls superclass method OpenNebula::PoolElement#update
# File lib/opennebula/zone.rb, line 130
def update(new_template=nil, append=false)
    super(ZONE_METHODS[:update], new_template, append ? 1 : 0)
end

Private Instance Methods

add_element(parent, key, value) click to toggle source

These methods adds elements to the given node of the zone

# File lib/opennebula/zone.rb, line 185
def add_element(parent, key, value)
    elem = Nokogiri::XML::Node.new(key, @xml.document)
    elem.content = value

    parent.add_child(elem)
end
add_element_xml(parent, doc, key, xpath) click to toggle source
# File lib/opennebula/zone.rb, line 192
def add_element_xml(parent, doc, key, xpath)
    value = doc.at_xpath(xpath)

    if value
        value = value.text
    else
        value = "-"
    end

    elem = Nokogiri::XML::Node.new(key, @xml.document)
    elem.content = value

    parent.add_child(elem)
end