Commit 75c55487 authored by Simon Leinen's avatar Simon Leinen

List all undead ressources by default

Factor out insignificant_usage()

Make ram_cut a class parameter.

Default ram_cut to zero in the main program.

Only call tenant_report() with the (new) default parameters in the
main program.
parent b1bfefa0
......@@ -51,7 +51,8 @@ class UsageAnalyzer:
username= os.environ['OS_USERNAME'],
password= os.environ['OS_PASSWORD'],
tenant_name= os.environ['OS_TENANT_NAME'],
auth_url= os.environ['OS_AUTH_URL']):
auth_url= os.environ['OS_AUTH_URL'],
ram_cut = 12 * 1024):
self.fine_grained = fine_grained
......@@ -60,6 +61,11 @@ class UsageAnalyzer:
self.tenant_name = tenant_name
self.auth_url = auth_url
## All cost centers that total less than this
## are considered "small" and thrown into one bin.
##
self.ram_cut = ram_cut
auth = v2.Password(auth_url=self.auth_url,
username=self.username,
password=self.password,
......@@ -249,14 +255,14 @@ class UsageAnalyzer:
for flavor in flavors:
self.retrieve_flavor(r, flavor.id)
def tenant_report(self, per_region=True, active_only=True, undead_only=True):
def tenant_report(self, per_region=True, active_only=False, undead_only=True):
def status_set(active_only, undead_only):
if active_only:
return ['ACTIVE', 'in-use']
if undead_only:
return ['ACTIVE', 'in-use', 'available', 'SUSPENDED', 'ERROR']
return ['ACTIVE', 'in-use', 'available', 'SUSPENDED', 'ERROR', 'SHUTOFF']
return ['ACTIVE', 'in-use', 'available', 'error', 'PAUSED', 'SUSPENDED', 'ERROR']
return ['ACTIVE', 'in-use', 'available', 'error', 'PAUSED', 'SUSPENDED', 'ERROR', 'SHUTOFF']
def title():
return "Status " + ", ".join(status_set(active_only, undead_only))
......@@ -264,10 +270,8 @@ class UsageAnalyzer:
def out_title():
print(title() + "\n")
## All cost centers that total less than this
## are considered "small" and thrown into one bin.
##
ram_cut = 12 * 1024
def insignificant_usage(usage):
return usage['total'].ram < self.ram_cut
small_usage = dict()
small_usage['per_region'] = dict()
......@@ -326,14 +330,14 @@ class UsageAnalyzer:
key=lambda cc_name: usage_per_cc[cc_name]['total'].ram):
if not usage_per_cc[cc_name]['total'].nonzero():
continue
if usage_per_cc[cc_name]['total'].ram < ram_cut:
if insignificant_usage(usage_per_cc[cc_name]):
small_usage['total'].add(usage_per_cc[cc_name]['total'])
for region in self.get_regions():
small_usage['per_region'][region].add(usage_per_cc[cc_name]['per_region'][region])
continue
out_cc(cc_name, usage_per_cc[cc_name])
if small_usage['total'].nonzero():
out_cc('smaller CCs', small_usage)
out_cc('SMALL_CCs', small_usage)
if total_usage['total'].nonzero():
out_cc('TOTAL', total_usage)
......@@ -402,13 +406,9 @@ class CostCenter:
self.name = name
self.tenants = tenants[:]
ua = UsageAnalyzer()
ua = UsageAnalyzer(ram_cut = 0)
ua.collect_flavors()
ua.collect_servers()
ua.collect_volumes()
ua.tenant_report(active_only=True)
print("")
ua.tenant_report(active_only=False)
print("")
ua.tenant_report(active_only=False, undead_only=False)
ua.tenant_report()
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