Skip to content

Commit

Permalink
Adding summary for number of resources and health states to Provider
Browse files Browse the repository at this point in the history
  • Loading branch information
EsdrasVP committed Aug 16, 2018
1 parent bae58fc commit 5ed1437
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions app/models/manageiq/providers/physical_infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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
Expand Down

0 comments on commit 5ed1437

Please sign in to comment.