class OpenNebula::Zone
Constants
- ZONE_METHODS
Constants and Class Methods
Public Class Methods
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
Class constructor
OpenNebula::PoolElement::new
# File lib/opennebula/zone.rb, line 55 def initialize(xml, client) super(xml,client) end
Public Instance Methods
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
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
OpenNebula::PoolElement#allocate
# File lib/opennebula/zone.rb, line 118 def allocate(description) super(ZONE_METHODS[:allocate], description) end
Deletes the Zone
@return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
OpenNebula::PoolElement#delete
# File lib/opennebula/zone.rb, line 137 def delete() super(ZONE_METHODS[:delete]) end
Retrieves the information of the given Zone
. @return [nil, OpenNebula::Error] nil in case of success, Error
otherwise
OpenNebula::PoolElement#info
# File lib/opennebula/zone.rb, line 66 def info() super(ZONE_METHODS[:info], 'ZONE') end
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
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
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
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
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
# 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