Commit 34052817 authored by Simon Leinen's avatar Simon Leinen

Improved reporting for various status values

New optional tenant_report() parameter 'any_status' ensures that all
status values are looked at.

The table title now includes the sorted set of status values.
parent 908b9ed7
......@@ -255,17 +255,36 @@ class UsageAnalyzer:
for flavor in flavors:
self.retrieve_flavor(r, flavor.id)
def tenant_report(self, per_region=True, active_only=False, undead_only=True):
def status_values(self):
def status_set(active_only, undead_only):
"""
Compute the set of all "status" values for which we have usage records
"""
statuses=set()
for tenant_id, usage in self.usage_per_tenant.iteritems():
t_usage = self.usage_per_tenant.get(tenant_id, None)
if t_usage is None:
continue
for region in self.get_regions():
r_usage = t_usage.per_region.get(region, None)
if r_usage is None:
continue
for status, usage in r_usage.per_status.iteritems():
statuses.add(status)
return statuses
def tenant_report(self, per_region=True, active_only=False, any_status=False):
def status_set(active_only, any_status):
if active_only:
return ['ACTIVE', 'in-use']
if undead_only:
return ['ACTIVE', 'in-use', 'available', 'error', 'PAUSED', 'SUSPENDED', 'ERROR']
return ['ACTIVE', 'in-use', 'available', 'error', 'PAUSED', 'SUSPENDED', 'ERROR', 'SHUTOFF']
if any_status:
return self.status_values()
return ['ACTIVE', 'in-use', 'available', 'error', 'PAUSED', 'SUSPENDED', 'ERROR']
def title():
return "Status " + ", ".join(status_set(active_only, undead_only))
return "Status " + ", ".join(sorted(status_set(active_only, any_status)))
def out_title():
print(title() + "\n")
......@@ -286,6 +305,7 @@ class UsageAnalyzer:
total_usage['per_region'][region] = ResourceUsage()
usage_per_cc = dict()
interesting_statuses = status_set(active_only, any_status)
for cc_name, cc in self.get_cost_centers().iteritems():
usage_per_cc[cc_name] = dict()
usage_per_cc[cc_name]['total'] = ResourceUsage()
......@@ -300,7 +320,6 @@ class UsageAnalyzer:
r_usage = t_usage.per_region.get(region, None)
if r_usage is None:
continue
interesting_statuses = status_set(active_only, undead_only)
for status in interesting_statuses:
usage = r_usage.per_status.get(status, None)
if usage:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment