From 5ed14372c91d651739e30e069142fc0170c14a4a Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Aug 2018 14:49:20 -0300 Subject: [PATCH] Adding summary for number of resources and health states to Provider --- .../providers/physical_infra_manager.rb | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/app/models/manageiq/providers/physical_infra_manager.rb b/app/models/manageiq/providers/physical_infra_manager.rb index 4ffceadf8f9..726ee2daccb 100644 --- a/app/models/manageiq/providers/physical_infra_manager.rb +++ b/app/models/manageiq/providers/physical_infra_manager.rb @@ -17,6 +17,15 @@ class PhysicalInfraManager < BaseManager virtual_column :total_hosts, :type => :integer virtual_column :total_vms, :type => :integer + virtual_column :total_valid, :type => :integer + virtual_column :total_warning, :type => :integer + virtual_column :total_critical, :type => :integer + virtual_column :health_state_info, :type => :json + + virtual_column :total_racks, :type => :integer + virtual_column :total_resources, :type => :integer + virtual_column :resources_info, :type => :json + class << model_name define_method(:route_key) { "ems_physical_infras" } define_method(:singular_route_key) { "ems_physical_infra" } @@ -34,6 +43,47 @@ def validate_authentication_status {:available => true, :message => nil} end + def count_health_state(state) + count = 0 + count += physical_chassis.where(:health_state => state).count + count += physical_servers.where(:health_state => state).count + count += physical_switches.where(:health_state => state).count + count += physical_storages.where(:health_state => state).count + end + + def assign_health_states + { + :total_valid => count_health_state("Valid"), + :total_warning => count_health_state("Warning"), + :total_critical => count_health_state("Critical"), + } + end + + alias health_state_info assign_health_states + + def count_resources(component = nil) + count = 0 + + if component + count = component.count + else + count += physical_racks.count + count += physical_chassis.count + count += physical_servers.count + count += physical_switches.count + count += physical_storages.count + end + end + + def assign_resources_info + { + :total_racks => count_resources(physical_racks), + :total_resources => count_resources, + } + end + + alias resources_info assign_resources_info + def count_physical_servers_with_host physical_servers.inject(0) { |t, physical_server| physical_server.host.nil? ? t : t + 1 } end