1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

B #5143: use monitoring information in flow rules (#349)

(cherry picked from commit 708ed64bf1c6d366514f4416f1b94c8bb6f3aea3)
This commit is contained in:
Alejandro Huertas Herrero 2020-10-22 13:12:18 +02:00 committed by Ruben S. Montero
parent 4c0a5c3ef3
commit 0a0a24aa80
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
2 changed files with 24 additions and 5 deletions

View File

@ -36,7 +36,15 @@ class ServiceAutoScaler
def start
loop do
@srv_pool.info
vm_pool = VirtualMachinePool.new(client)
# -2 to get all resources, 0 just to get last record
monitoring = vm_pool.monitoring_xml(-2, 0)
monitoring = XMLElement.new(XMLElement.build_xml(monitoring,
'MONITORING_DATA'))
monitoring = monitoring.to_hash['MONITORING_DATA']['MONITORING']
vm_pool.info_all_extended
@srv_pool.each do |service|
@ -49,7 +57,7 @@ class ServiceAutoScaler
'Checking policies for ' \
"service: #{service.id}"
apply_scaling_policies(service, vm_pool)
apply_scaling_policies(service, vm_pool, monitoring)
end
sleep(@interval)
@ -67,10 +75,13 @@ class ServiceAutoScaler
# If a role needs to scale, its cardinality is updated, and its state is set
# to SCALING. Only one role is set to scale.
#
# @param [OpenNebula::Service] service
def apply_scaling_policies(service, vm_pool)
# @param service [OpenNebula::Service]
# @param vm_pool [OpenNebula::VirtualMachinePool] VM pool
# @param monitoring [Hash] Monitoring data
def apply_scaling_policies(service, vm_pool, monitoring)
service.roles.each do |name, role|
diff, cooldown_duration = role.scale?(vm_pool)
diff, cooldown_duration = role.scale?({ :vm_pool => vm_pool,
:monitoring => monitoring })
policies = {}
policies['elasticity_policies'] = role.elasticity_policies

View File

@ -244,6 +244,9 @@ module OpenNebula
def info_nodes(vm_pool)
ret = []
monitoring = vm_pool[:monitoring]
vm_pool = vm_pool[:vm_pool]
@body['nodes'].each do |node|
id = node['deploy_id']
vm = vm_pool.retrieve_xmlelements("/VM_POOL/VM[ID=#{id}]")[0]
@ -255,7 +258,12 @@ module OpenNebula
else
obj = {}
obj['deploy_id'] = node['deploy_id']
obj['vm_info'] = vm.to_hash
hash = vm.to_hash
vm_monit = monitoring.select {|v| v['ID'].to_i == id }[0]
hash['VM']['MONITORING'] = vm_monit if vm_monit
obj['vm_info'] = hash
ret << obj
end