class Cloudkeeper::One::Opennebula::Handler

Constants

API_POLLING_WAIT

Attributes

client[R]
pool[RW]

Public Class Methods

new() click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 11
def initialize
  @client = OpenNebula::Client.new Cloudkeeper::One::Settings[:'opennebula-secret'],
                                   Cloudkeeper::One::Settings[:'opennebula-endpoint']
end

Public Instance Methods

exist?(id) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 32
def exist?(id)
  find_by_id id
end
find_all(xpaths = {}) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 20
def find_all(xpaths = {})
  find(:find_all, xpaths)
end
find_by_id(id) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 28
def find_by_id(id)
  find_one('ID' => id.to_s)
end
find_by_name(name) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 24
def find_by_name(name)
  find_one('NAME' => name)
end
find_one(xpaths = {}) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 16
def find_one(xpaths = {})
  find(:find, xpaths)
end

Private Instance Methods

evaluate_xpaths(element, xpaths) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 44
def evaluate_xpaths(element, xpaths)
  xpaths.inject(true) do |red, elem|
    red && (elem.last.is_a?(Array) ? elem.last.include?(element[elem.first]) : element[elem.first] == elem.last)
  end
end
find(method, xpaths = {}) click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 38
def find(method, xpaths = {})
  reload!

  pool.send(method) { |element| evaluate_xpaths(element, xpaths) }
end
reload!() click to toggle source
# File lib/cloudkeeper/one/opennebula/handler.rb, line 50
def reload!
  raise Cloudkeeper::One::Errors::Opennebula::MissingPoolError, 'Handler is missing an OpenNebula pool' unless pool

  method = pool.respond_to?('info_mine!') ? 'info_mine!' : 'info!'
  handle_opennebula_error { pool.send(method.to_sym) }
end