Class: OpenNebula::Zone
- Inherits:
-
PoolElement
- Object
- XMLElement
- PoolElement
- OpenNebula::Zone
- Defined in:
- lib/opennebula/zone.rb
Constant Summary collapse
- ZONE_METHODS =
Constants and Class Methods
{ :info => "zone.info", :allocate => "zone.allocate", :update => "zone.update", :rename => "zone.rename", :delete => "zone.delete", :addserver => "zone.addserver", :delserver => "zone.delserver", :resetserver => "zone.resetserver", :enable => "zone.enable" }
- ZONE_STATES =
%w{ENABLED DISABLED}
- SHORT_ZONE_STATES =
{ "ENABLED" => "on", "DISABLED" => "off" }
Instance Attribute Summary
Attributes inherited from PoolElement
Class Method Summary collapse
-
.build_xml(pe_id = nil) ⇒ Object
Creates a Zone description with just its identifier this method should be used to create plain Zone objects.
Instance Method Summary collapse
-
#add_servers(servers) ⇒ nil, OpenNebula::Error
Adds servers to this Zone.
-
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Zone in OpenNebula.
-
#delete ⇒ nil, OpenNebula::Error
Deletes the Zone.
-
#delete_servers(server_id) ⇒ nil, OpenNebula::Error
Delete servers from this Zone.
-
#disable ⇒ nil, OpenNebula::Error
Disable zone, only readonly commands can be executed in disabled state.
-
#enable ⇒ nil, OpenNebula::Error
Enable zone.
-
#info ⇒ nil, OpenNebula::Error
(also: #info!)
Retrieves the information of the given Zone.
-
#info_extended ⇒ nil, OpenNebula::Error
(also: #info_extended!)
Retrieves the information extended of the given Zone.
-
#initialize(xml, client) ⇒ Zone
constructor
Class constructor.
-
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Zone.
-
#reset_server(server_id) ⇒ nil, OpenNebula::Error
Reset index for a follower.
-
#state ⇒ Object
Returns the state of the Zone (numeric value).
-
#state_str ⇒ Object
Returns the state of the Zone (string value).
-
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents.
Methods inherited from PoolElement
#id, new_with_id, #replace, #to_str
Methods inherited from XMLElement
#[], #attr, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #retrieve_xmlelements, #set_content, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml, #xml_nil?
Constructor Details
#initialize(xml, client) ⇒ Zone
Class constructor
63 64 65 |
# File 'lib/opennebula/zone.rb', line 63 def initialize(xml, client) super(xml,client) end |
Class Method Details
.build_xml(pe_id = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/opennebula/zone.rb', line 52 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 |
Instance Method Details
#add_servers(servers) ⇒ nil, OpenNebula::Error
Adds servers to this Zone
166 167 168 |
# File 'lib/opennebula/zone.rb', line 166 def add_servers(servers) return call(ZONE_METHODS[:addserver], @pe_id, servers) end |
#allocate(description) ⇒ nil, OpenNebula::Error
Allocates a new Zone in OpenNebula
126 127 128 |
# File 'lib/opennebula/zone.rb', line 126 def allocate(description) super(ZONE_METHODS[:allocate], description) end |
#delete ⇒ nil, OpenNebula::Error
Deletes the Zone
145 146 147 |
# File 'lib/opennebula/zone.rb', line 145 def delete() super(ZONE_METHODS[:delete]) end |
#delete_servers(server_id) ⇒ nil, OpenNebula::Error
Delete servers from this Zone
176 177 178 |
# File 'lib/opennebula/zone.rb', line 176 def delete_servers(server_id) return call(ZONE_METHODS[:delserver], @pe_id, server_id) end |
#disable ⇒ nil, OpenNebula::Error
Disable zone, only readonly commands can be executed in disabled state
203 204 205 |
# File 'lib/opennebula/zone.rb', line 203 def disable() return call(ZONE_METHODS[:enable], @pe_id, false) end |
#enable ⇒ nil, OpenNebula::Error
Enable zone
194 195 196 |
# File 'lib/opennebula/zone.rb', line 194 def enable() return call(ZONE_METHODS[:enable], @pe_id, true) end |
#info ⇒ nil, OpenNebula::Error Also known as: info!
Retrieves the information of the given Zone.
74 75 76 |
# File 'lib/opennebula/zone.rb', line 74 def info() super(ZONE_METHODS[:info], 'ZONE') end |
#info_extended ⇒ nil, OpenNebula::Error Also known as: info_extended!
Retrieves the information extended of the given Zone.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/opennebula/zone.rb', line 81 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 |
#rename(name) ⇒ nil, OpenNebula::Error
Renames this Zone
155 156 157 |
# File 'lib/opennebula/zone.rb', line 155 def rename(name) return call(ZONE_METHODS[:rename], @pe_id, name) end |
#reset_server(server_id) ⇒ nil, OpenNebula::Error
Reset index for a follower
186 187 188 |
# File 'lib/opennebula/zone.rb', line 186 def reset_server(server_id) return call(ZONE_METHODS[:resetserver], @pe_id, server_id) end |
#state ⇒ Object
Returns the state of the Zone (numeric value)
212 213 214 |
# File 'lib/opennebula/zone.rb', line 212 def state self['STATE'].to_i end |
#state_str ⇒ Object
Returns the state of the Zone (string value)
217 218 219 |
# File 'lib/opennebula/zone.rb', line 217 def state_str ZONE_STATES[state] end |
#update(new_template = nil, append = false) ⇒ nil, OpenNebula::Error
Replaces the template contents
138 139 140 |
# File 'lib/opennebula/zone.rb', line 138 def update(new_template=nil, append=false) super(ZONE_METHODS[:update], new_template, append ? 1 : 0) end |