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 20, 2018
1 parent 00758f4 commit dc5b5d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
20 changes: 15 additions & 5 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,27 @@ def tenant_identity

def self.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
return if data.empty?
data = data.sort_by { |e| [e[0], e[1], e[2], e[3]] }
data = data.map { |row| row.map { |col| col.to_s == "0" ? nil : col } }
data.unshift %w(region zone ems clusters hosts vms storages)
# remove 0's (except for the region)
data = data.map { |row| row.each_with_index.map { |col, i| i.positive? && col.to_s == "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.dup.each do |col_header|
col = data.first.index(col_header)
if data[1..-1].none? { |row| row[col] }
data.each { |row| row.delete_at(col) }
end
end
data
end

private
Expand Down
14 changes: 12 additions & 2 deletions spec/models/ext_management_system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,18 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first)

result = ExtManagementSystem.inventory_status
expect(result.size).to eq(2)
expect(result[0]).to eq(%w(region zone ems clusters hosts vms storages))
expect(result[1][3..-1]).to eq([0, 1, 2, 0])
expect(result[0]).to eq(%w(region zone kind ems hosts vms))
expect(result[1][4..-1]).to eq([1, 2])
end

it "works with container providers" do
ems = FactoryGirl.create(:ems_container)
FactoryGirl.create(:container, :ems_id => ems.id)
FactoryGirl.create(:container, :ems_id => ems.id)
result = ExtManagementSystem.inventory_status
expect(result.size).to eq(2)
expect(result[0]).to eq(%w(region zone kind ems containers))
expect(result[1][4..-1]).to eq([2])
end
end
end

0 comments on commit dc5b5d2

Please sign in to comment.