Class: One2Influx::Data
- Inherits:
-
Object
- Object
- One2Influx::Data
- Defined in:
- lib/one2influx/data.rb
Overview
Wrapper for function that loads all data from OpenNebula
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Instance Method Summary collapse
-
#initialize ⇒ Data
constructor
Loads all data from ONE according to $CFG and stores it in instance variable @points.
Constructor Details
#initialize ⇒ Data
Loads all data from ONE according to $CFG and stores it in
instance variable @points
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/one2influx/data.rb', line 8 def initialize @points = [] counter = {hosts: 0, vms: 0, dss: 0, clusters: 0} # Connect to ONE @client = OpenNebula::Client.new($CFG.one[:credentials], $CFG.one[:endpoint]) # Load pool of all hosts host_pool = OpenNebula::HostPool.new(@client) rc = host_pool.info raise rc. if OpenNebula.is_error?(rc) # Get data from all hosts in the pool oo_hosts = {} # hash of all instances of OneObject::Host # in form {ID => host} host_pool.each do |one_host| host = ::One2Influx::Host.new(one_host.to_xml, @client) # Get data from all VMs belonging to current host host.vms.each do |vm_id| xml_rep = OpenNebula::VirtualMachine.build_xml(vm_id) one_vm = OpenNebula::VirtualMachine.new(xml_rep, @client) rc = one_vm.info raise rc. if OpenNebula.is_error?(rc) vm = ::One2Influx::VirtualMachine.new(one_vm.to_xml, @client, host) @points += vm.serialize_as_points counter[:vms] += 1 end oo_hosts[host.[:HOST_ID].to_sym] = host @points += host.serialize_as_points counter[:hosts] += 1 end # Load pool of all clusters cluster_pool = OpenNebula::ClusterPool.new(@client) rc = cluster_pool.info raise rc. if OpenNebula.is_error?(rc) # Get data from all clusters in the pool cluster_pool.each do |one_cluster| cluster = ::One2Influx::Cluster.new(one_cluster.to_xml, @client, oo_hosts) @points += cluster.serialize_as_points counter[:clusters] += 1 end # Load pool of all datastores ds_pool = OpenNebula::DatastorePool.new(@client) rc = ds_pool.info raise rc. if OpenNebula.is_error?(rc) # Get hash of all hosts for every datastore if these tags are required # It has form {DS_ID_1: [HOST_ID_1, HOST_ID_2, ...], ...} ds_has_hosts = {} if $CFG.storage[:ds][:tags].has_key? :HOSTS_IDS oo_hosts.each do |id, host| host.datastores.each do |ds| ds_has_hosts[ds] ||= [] ds_has_hosts[ds] << host.[:HOST_ID] end end end # Get data from all datastores in the pool ds_pool.each do |one_ds| ds = ::One2Influx::Datastore.new(one_ds.to_xml, @client) hosts = ds_has_hosts[ds.[:DS_ID]] hosts ||= [] # This doesn't do anything if tag HOSTS_IDS is not enabled ds.add_hosts_ids(hosts) @points += ds.serialize_as_points counter[:dss] += 1 end $LOG.info "Fetched data for #{counter[:vms]} VMs, #{counter[:hosts]} hosts" + ", #{counter[:dss]} datastores and #{counter[:clusters]} " + 'clusters.' end |
Instance Attribute Details
#points ⇒ Object (readonly)
Returns the value of attribute points.
4 5 6 |
# File 'lib/one2influx/data.rb', line 4 def points @points end |