Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding summary for number of resources, racks and health states to Provider #17841

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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