Class: OpenNebula::VirtualMachinePool
- Inherits:
-
Pool
- Object
- XMLElement
- XMLPool
- Pool
- OpenNebula::VirtualMachinePool
- Defined in:
- lib/opennebula/virtual_machine_pool.rb
Constant Summary collapse
- VM_POOL_METHODS =
{ :info => "vmpool.info", :monitoring => "vmpool.monitoring", :accounting => "vmpool.accounting", :showback => "vmpool.showback", :calculate_showback => "vmpool.calculateshowback" }
- INFO_NOT_DONE =
Constants for info queries (include/RequestManagerPoolInfoFilter.h)
-1
- INFO_ALL_VM =
-2
Constants inherited from Pool
Pool::INFO_ALL, Pool::INFO_GROUP, Pool::INFO_MINE, Pool::PAGINATED_POOLS
Instance Method Summary collapse
-
#accounting(filter_flag = INFO_ALL, options = {}) ⇒ Hash, OpenNebula::Error
Retrieves the accounting data for all the VMs in the pool.
-
#accounting_xml(filter_flag = INFO_ALL, options = {}) ⇒ String
Retrieves the accounting data for all the VMs in the pool in xml.
-
#calculate_showback(start_month, start_year, end_month, end_year) ⇒ Object
Processes all the history records, and stores the monthly cost for each VM.
-
#factory(element_xml) ⇒ Object
Default Factory Method for the Pools.
-
#info(*args) ⇒ Object
(also: #info!)
Retrieves all or part of the VirtualMachines in the pool.
- #info_all ⇒ Object (also: #info_all!)
- #info_group ⇒ Object (also: #info_group!)
- #info_mine ⇒ Object (also: #info_mine!)
-
#initialize(client, user_id = 0) ⇒ VirtualMachinePool
constructor
client
a Client object that represents a XML-RPC connectionuser_id
is to refer to a Pool with VirtualMachines from that user. -
#monitoring(xpath_expressions, filter_flag = INFO_ALL) ⇒ Hash<String, <Hash<String, Array<Array<int>>>>>, OpenNebula::Error
Retrieves the monitoring data for all the VMs in the pool.
-
#monitoring_xml(filter_flag = INFO_ALL) ⇒ String
Retrieves the monitoring data for all the VMs in the pool, in XML.
-
#showback(filter_flag = INFO_ALL, options = {}) ⇒ Hash, OpenNebula::Error
Retrieves the showback data for all the VMs in the pool.
-
#showback_xml(filter_flag = INFO_ALL, options = {}) ⇒ String
Retrieves the showback data for all the VMs in the pool, in xml.
Methods inherited from Pool
#each, #each_with_xpath, #get_hash, #info_paginated, #to_str
Methods inherited from XMLPool
Methods inherited from XMLElement
#[], #add_element, #attr, build_xml, #delete_element, #each, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml
Constructor Details
#initialize(client, user_id = 0) ⇒ VirtualMachinePool
client
a Client object that represents a XML-RPC connection user_id
is to refer to a Pool with VirtualMachines from that user
46 47 48 49 50 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 46 def initialize(client, user_id=0) super('VM_POOL','VM',client) @user_id = user_id end |
Instance Method Details
#accounting(filter_flag = INFO_ALL, options = {}) ⇒ Hash, OpenNebula::Error
Retrieves the accounting data for all the VMs in the pool
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 249 def accounting(filter_flag=INFO_ALL, ={}) acct_hash = Hash.new rc = build_accounting(filter_flag, ) do |history| hash = acct_hash if [:order_by_1] id_1 = history[[:order_by_1]] acct_hash[id_1] ||= Hash.new if [:order_by_2] id_2 = history[[:order_by_2]] acct_hash[id_1][id_2] ||= Hash.new hash = acct_hash[id_1][id_2] else hash = acct_hash[id_1] end end hash["HISTORY_RECORDS"] ||= Hash.new hash["HISTORY_RECORDS"]["HISTORY"] ||= Array.new hash["HISTORY_RECORDS"]["HISTORY"] << history.to_hash['HISTORY'] end return rc if OpenNebula.is_error?(rc) acct_hash end |
#accounting_xml(filter_flag = INFO_ALL, options = {}) ⇒ String
Retrieves the accounting data for all the VMs in the pool in xml
295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 295 def accounting_xml(filter_flag=INFO_ALL, ={}) acct_hash = Hash.new xml_str = "<HISTORY_RECORDS>\n" rc = build_accounting(filter_flag, ) do |history| xml_str << history.to_xml end return rc if OpenNebula.is_error?(rc) xml_str << "\n</HISTORY_RECORDS>" xml_str end |
#calculate_showback(start_month, start_year, end_month, end_year) ⇒ Object
Processes all the history records, and stores the monthly cost for each VM
@param [Integer] start_month First month (+year) to process. January is 1.
Use -1 to unset
@param [Integer] start_year First year (+month) to process. e.g. 2014.
Use -1 to unset
@param [Integer] end_month Last month (+year) to process. January is 1.
Use -1 to unset
@param [Integer] end_year Last year (+month) to process. e.g. 2014.
Use -1 to unset
178 179 180 181 182 183 184 185 186 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 178 def calculate_showback(start_month, start_year, end_month, end_year) start_month ||= -1 start_year ||= -1 end_month ||= -1 end_year ||= -1 return @client.call(VM_POOL_METHODS[:calculate_showback], start_month, start_year, end_month, end_year) end |
#factory(element_xml) ⇒ Object
Default Factory Method for the Pools
53 54 55 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 53 def factory(element_xml) OpenNebula::VirtualMachine.new(element_xml,@client) end |
#info(*args) ⇒ Object Also known as: info!
Retrieves all or part of the VirtualMachines in the pool. No arguments, returns the not-in-done VMs for the user
- user_id, start_id, end_id
- user_id, start_id, end_id, state
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 65 def info(*args) case args.size when 0 info_filter(VM_POOL_METHODS[:info], @user_id, -1, -1, INFO_NOT_DONE) when 1 info_filter(VM_POOL_METHODS[:info], args[0], -1, -1, INFO_NOT_DONE) when 3 info_filter(VM_POOL_METHODS[:info], args[0], args[1], args[2], INFO_NOT_DONE) when 4 info_filter(VM_POOL_METHODS[:info], args[0], args[1], args[2], args[3]) end end |
#info_all ⇒ Object Also known as: info_all!
94 95 96 97 98 99 100 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 94 def info_all() return info_filter(VM_POOL_METHODS[:info], INFO_ALL, -1, -1, INFO_NOT_DONE) end |
#info_group ⇒ Object Also known as: info_group!
110 111 112 113 114 115 116 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 110 def info_group() return info_filter(VM_POOL_METHODS[:info], INFO_GROUP, -1, -1, INFO_NOT_DONE) end |
#info_mine ⇒ Object Also known as: info_mine!
102 103 104 105 106 107 108 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 102 def info_mine() return info_filter(VM_POOL_METHODS[:info], INFO_MINE, -1, -1, INFO_NOT_DONE) end |
#monitoring(xpath_expressions, filter_flag = INFO_ALL) ⇒ Hash<String, <Hash<String, Array<Array<int>>>>>, OpenNebula::Error
Retrieves the monitoring data for all the VMs in the pool
152 153 154 155 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 152 def monitoring(xpath_expressions, filter_flag=INFO_ALL) return super(VM_POOL_METHODS[:monitoring], 'VM', 'LAST_POLL', xpath_expressions, filter_flag) end |
#monitoring_xml(filter_flag = INFO_ALL) ⇒ String
Retrieves the monitoring data for all the VMs in the pool, in XML
163 164 165 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 163 def monitoring_xml(filter_flag=INFO_ALL) return @client.call(VM_POOL_METHODS[:monitoring], filter_flag) end |
#showback(filter_flag = INFO_ALL, options = {}) ⇒ Hash, OpenNebula::Error
Retrieves the showback data for all the VMs in the pool
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 333 def showback(filter_flag=INFO_ALL, ={}) data_hash = Hash.new rc = build_showback(filter_flag, ) do |record| hash = data_hash if [:order_by_1] id_1 = record[[:order_by_1]] data_hash[id_1] ||= Hash.new if [:order_by_2] id_2 = record[[:order_by_2]] data_hash[id_1][id_2] ||= Hash.new hash = data_hash[id_1][id_2] else hash = data_hash[id_1] end end hash["SHOWBACK_RECORDS"] ||= Hash.new hash["SHOWBACK_RECORDS"]["SHOWBACK"] ||= Array.new hash["SHOWBACK_RECORDS"]["SHOWBACK"] << record.to_hash['SHOWBACK'] end return rc if OpenNebula.is_error?(rc) data_hash end |
#showback_xml(filter_flag = INFO_ALL, options = {}) ⇒ String
Retrieves the showback data for all the VMs in the pool, in xml
382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/opennebula/virtual_machine_pool.rb', line 382 def showback_xml(filter_flag=INFO_ALL, ={}) xml_str = "<SHOWBACK_RECORDS>\n" rc = build_showback(filter_flag, ) do |showback| xml_str << showback.to_xml end return rc if OpenNebula.is_error?(rc) xml_str << "\n</SHOWBACK_RECORDS>" xml_str end |