Class: Berta::Service
- Inherits:
-
Object
- Object
- Berta::Service
- Defined in:
- lib/berta/service.rb
Overview
Berta service for communication with OpenNebula
Constant Summary collapse
- RESOURCE_STATES =
VM states that take resources
%w(SUSPENDED POWEROFF CLONING).freeze
- ACTIVE_STATE =
Active state has some lcm states that should not expire
'ACTIVE'.freeze
- NON_RESOURCE_ACTIVE_LCM_STATES =
LCM states in which active state shouldn't expire
%w(EPILOG SHUTDOWN STOP UNDEPLOY FAILURE).freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#clusters ⇒ OpenNebula::ClusterPool
Fetch clusters from OpenNebula.
-
#initialize(secret, endpoint) ⇒ Service
constructor
Initializes service object and connects to opennebula backend.
-
#running_vms ⇒ Berta::VirtualMachineHandler
Fetch running vms from OpenNebula and filter out vms that take no resources.
-
#users ⇒ OpenNebula::UserPool
Fetch users from OpenNebula.
Constructor Details
#initialize(secret, endpoint) ⇒ Service
Initializes service object and connects to opennebula backend. If both arguments are nil default ONE_AUTH will be used.
22 23 24 25 |
# File 'lib/berta/service.rb', line 22 def initialize(secret, endpoint) @endpoint = endpoint @client = OpenNebula::Client.new(secret, endpoint) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'lib/berta/service.rb', line 14 def client @client end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
13 14 15 |
# File 'lib/berta/service.rb', line 13 def endpoint @endpoint end |
Instance Method Details
#clusters ⇒ OpenNebula::ClusterPool
Fetch clusters from OpenNebula
68 69 70 71 72 73 74 75 |
# File 'lib/berta/service.rb', line 68 def clusters return @cached_clusters if @cached_clusters logger.debug 'Fetching clusters' cluster_pool = OpenNebula::ClusterPool.new(client) Berta::Utils::OpenNebula::Helper.handle_error { cluster_pool.info } @cached_clusters = cluster_pool cluster_pool end |
#running_vms ⇒ Berta::VirtualMachineHandler
Fetch running vms from OpenNebula and filter out vms that take no resources.
37 38 39 40 41 42 43 |
# File 'lib/berta/service.rb', line 37 def running_vms logger.debug 'Fetching vms' vm_pool = OpenNebula::VirtualMachinePool.new(client) Berta::Utils::OpenNebula::Helper.handle_error { vm_pool.info_all } vm_pool.map { |vm| Berta::VirtualMachineHandler.new(vm) } .delete_if { |vmh| excluded?(vmh) || !takes_resources?(vmh) } end |
#users ⇒ OpenNebula::UserPool
Fetch users from OpenNebula
53 54 55 56 57 58 |
# File 'lib/berta/service.rb', line 53 def users logger.debug 'Fetching users' user_pool = OpenNebula::UserPool.new(client) Berta::Utils::OpenNebula::Helper.handle_error { user_pool.info } user_pool end |