Class: OpenNebula::VirtualMachinePool

Inherits:
Pool show all
Defined in:
lib/opennebula/virtual_machine_pool.rb

Constant Summary collapse

VM_POOL_METHODS =
{
    :info       => "vmpool.info",
    :monitoring => "vmpool.monitoring",
    :accounting => "vmpool.accounting"
}
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

Methods inherited from Pool

#each, #each_with_xpath, #get_hash, #info_paginated, #to_str

Methods inherited from XMLPool

#each_element

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



44
45
46
47
48
# File 'lib/opennebula/virtual_machine_pool.rb', line 44

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

Examples:

{"HISTORY_RECORDS"=>
    {"HISTORY"=> [
      {"OID"=>"0",
       "SEQ"=>"0",
       "HOSTNAME"=>"dummy",
       ...
      },
      {"OID"=>"0",
       "SEQ"=>"0",
       "HOSTNAME"=>"dummy",

:order_by_1 => VM/UID

{"0"=>
    {"HISTORY_RECORDS"=>
       {"HISTORY"=> [
         {"OID"=>"0",
          "SEQ"=>"0",
          "HOSTNAME"=>"dummy",
          ...
         },
         {"OID"=>"0",
          "SEQ"=>"0",
          "HOSTNAME"=>"dummy",

:order_by_1 => VM/UID, :order_by_2 => VM/ID

{"0"=>
    {"0"=>
        {"HISTORY_RECORDS"=>
            {"HISTORY"=> [
              {"OID"=>"0",
               "SEQ"=>"0",
               "HOSTNAME"=>"dummy",
               ...
              },
              {"OID"=>"0",
               "SEQ"=>"0",
               "HOSTNAME"=>"dummy",

Parameters:

  • filter_flag (Integer) (defaults to: INFO_ALL)

    Optional filter flag to retrieve all or part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE or user_id

  • options (Hash) (defaults to: {})
  • params (Hash)

    a customizable set of options

Returns:

  • (Hash, OpenNebula::Error)

    The first level hash uses the :order_by_1 values as keys, and as value a Hash with the :order_by_2 values and the HISTORY_RECORDS



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/opennebula/virtual_machine_pool.rb', line 226

def accounting(filter_flag=INFO_ALL, options={})
    acct_hash = Hash.new

    rc = build_accounting(filter_flag, options) do |history|
        hash = acct_hash

        if options[:order_by_1]
            id_1 = history[options[:order_by_1]]
            acct_hash[id_1] ||= Hash.new

            if options[:order_by_2]
                id_2 = history[options[: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

Parameters:

  • filter_flag (Integer) (defaults to: INFO_ALL)

    Optional filter flag to retrieve all or part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE or user_id

  • options (Hash) (defaults to: {})
  • params (Hash)

    a customizable set of options

Returns:

  • (String)

    the xml representing the accounting data



272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/opennebula/virtual_machine_pool.rb', line 272

def accounting_xml(filter_flag=INFO_ALL, options={})
    acct_hash = Hash.new
    xml_str = "<HISTORY_RECORDS>\n"

    rc = build_accounting(filter_flag, options) do |history|
        xml_str << history.to_xml
    end

    return rc if OpenNebula.is_error?(rc)

    xml_str << "\n</HISTORY_RECORDS>"
    xml_str
end

#factory(element_xml) ⇒ Object

Default Factory Method for the Pools



51
52
53
# File 'lib/opennebula/virtual_machine_pool.rb', line 51

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


63
64
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
# File 'lib/opennebula/virtual_machine_pool.rb', line 63

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_allObject Also known as: info_all!



92
93
94
95
96
97
98
# File 'lib/opennebula/virtual_machine_pool.rb', line 92

def info_all()
    return info_filter(VM_POOL_METHODS[:info],
                       INFO_ALL,
                       -1,
                       -1,
                       INFO_NOT_DONE)
end

#info_groupObject Also known as: info_group!



108
109
110
111
112
113
114
# File 'lib/opennebula/virtual_machine_pool.rb', line 108

def info_group()
    return info_filter(VM_POOL_METHODS[:info],
                       INFO_GROUP,
                       -1,
                       -1,
                       INFO_NOT_DONE)
end

#info_mineObject Also known as: info_mine!



100
101
102
103
104
105
106
# File 'lib/opennebula/virtual_machine_pool.rb', line 100

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

Examples:

vm_pool.monitoring( ['CPU', 'NET_TX', 'TEMPLATE/CUSTOM_PROBE'] )

{"1"=>
 {"CPU"=>
   [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
  "NET_TX"=>
   [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
  "TEMPLATE/CUSTOM_PROBE"=>
   []},

"0"=>
 {"CPU"=>
   [["1337608271", "0"], ["1337608301", "0"], ["1337608331", "0"]],
  "NET_TX"=>
   [["1337608271", "510"], ["1337608301", "510"], ["1337608331", "520"]],
  "TEMPLATE/CUSTOM_PROBE"=>
   []}}

Parameters:

  • xpath_expressions (Array<String>)

    Elements to retrieve.

  • filter_flag (Integer) (defaults to: INFO_ALL)

    Optional filter flag to retrieve all or part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE.

Returns:

  • (Hash<String, <Hash<String, Array<Array<int>>>>>, OpenNebula::Error)

    The first level hash uses the VM ID as keys, and as value a Hash with the requested xpath expressions, and an Array of ‘timestamp, value’.



150
151
152
153
# File 'lib/opennebula/virtual_machine_pool.rb', line 150

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

Parameters:

  • filter_flag (Integer) (defaults to: INFO_ALL)

    Optional filter flag to retrieve all or part of the Pool. Possible values: INFO_ALL, INFO_GROUP, INFO_MINE.

Returns:

  • (String)

    VM monitoring data, in XML



161
162
163
# File 'lib/opennebula/virtual_machine_pool.rb', line 161

def monitoring_xml(filter_flag=INFO_ALL)
    return @client.call(VM_POOL_METHODS[:monitoring], filter_flag)
end