Class: OpenNebula::Pool

Inherits:
XMLPool show all
Includes:
Enumerable
Defined in:
lib/opennebula/pool.rb

Overview

The Pool class represents a generic OpenNebula Pool in XML format and provides the basic functionality to handle the Pool elements

Constant Summary collapse

PAGINATED_POOLS =
%w{VM_POOL IMAGE_POOL TEMPLATE_POOL VN_POOL
DOCUMENT_POOL}
INFO_GROUP =

Constants for info queries (include/RequestManagerPoolInfoFilter.h)

-1
INFO_ALL =
-2
INFO_MINE =
-3

Instance Method Summary collapse

Methods inherited from XMLPool

#each_element

Methods inherited from XMLElement

#[], #add_element, #attr, build_xml, #delete_element, #each_xpath, #element_xml, #has_elements?, #initialize_xml, #name, #retrieve_elements, #template_like_str, #template_str, #template_xml, #text, #to_hash, #to_xml

Instance Method Details

#each(&block) ⇒ Object

Iterates over every PoolElement in the Pool and calls the block with a a PoolElement obtained calling the factory method

block

Block



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

def each(&block)
    each_element(block) if @xml
end

#each_with_xpathObject



25
# File 'lib/opennebula/pool.rb', line 25

alias_method :each_with_xpath, :each

#get_hash(size = nil) ⇒ Object

Gets a hash from a pool

size

nil => default page size < 2 => not paginated >=2 => page size

The default page size can be changed with the environment variable ONE_POOL_PAGE_SIZE. Any value > 2 will set a page size, a non numeric value disables pagination.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/opennebula/pool.rb', line 172

def get_hash(size=nil)
    allow_paginated = PAGINATED_POOLS.include?(@pool_name)

    if OpenNebula.pool_page_size && allow_paginated &&
            ( ( size && size >= 2 ) || !size )
        size = OpenNebula.pool_page_size if !size
        hash=info_paginated(size)

        return hash if OpenNebula.is_error?(hash)
        { @pool_name => { @element_name => hash } }
    else
        rc=info
        return rc if OpenNebula.is_error?(rc)
        to_hash
    end
end

#info_paginated(size) ⇒ Object

Gets a pool in hash form using pagination

size

Integer size of each page



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/opennebula/pool.rb', line 192

def info_paginated(size)
    array=Array.new
    current=0

    parser=ParsePoolSax.new(@pool_name, @element_name)

    while true
        a=@client.call("#{@pool_name.delete('_').downcase}.info",
            @user_id, current, -size, -1)
        return a if OpenNebula.is_error?(a)

        a_array=parser.parse(a)

        array += a_array
        current += size
        break if !a || a_array.length<size
    end

    array.compact!
    array=nil if array.length == 0

    array
end

#to_strObject

DO NOT USE - ONLY REXML BACKEND



156
157
158
159
160
161
# File 'lib/opennebula/pool.rb', line 156

def to_str
    str = ""
    REXML::Formatters::Pretty.new(1).write(@xml,str)

    return str
end