Skip to content

Commit

Permalink
evm:inventory - add containers.
Browse files Browse the repository at this point in the history
also don't display the column if it is empty (or all 0)
  • Loading branch information
kbrock committed Feb 9, 2018
1 parent b602aed commit 6b2066c
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,28 @@ def tenant_identity

def self.output_inventory_status
data = includes(:zone)
.select(:id, :zone_id, :name, :total_hosts, :total_vms, :total_clusters)
.select(:id, :parent_ems_id, :zone_id, :type, :name, :total_hosts, :total_vms, :total_clusters)
.map do |ems|
[
ems.region_id, ems.zone.name, ems.name,
ems.total_clusters, ems.total_hosts, ems.total_vms, ems.total_storages
ems.region_id, ems.zone.name, ems.class.short_token, ems.name,
ems.total_clusters, ems.total_hosts, ems.total_vms, ems.total_storages,
ems.try(:containers).try(:count)
]
end
data = data.sort_by { |e| [e[1], e[2], e[3]] }
data = data.map { |row| row.map { |col| col.to_s == "0" ? nil : col } }
header = %w(region zone ems clusters hosts vms storages)
puts data.unshift(header).tableize unless data.empty?
unless data.empty?
data = data.sort_by { |e| [e[0], e[1], e[2], e[3]] }
# remove 0's (except for the region)
data = data.map { |row| row.each_with_index.map { |col, i| i > 0 && col == 0 ? nil : col } }
data.unshift(%w(region zone kind ems clusters hosts vms storages containers))
# remove columns where all values (except for the header) are blank
data.first.each do |col_header|
col = data[0].index(col_header)
if data[1..-1].map { |row| row[col] }.none?
data.each { |row| row.delete_at(col) }
end
end
puts data.tableize
end
end

private
Expand Down

0 comments on commit 6b2066c

Please sign in to comment.