From 3bec2b7f0bf7fb9ea5f6db03f1f0f4fa81b6bbd7 Mon Sep 17 00:00:00 2001 From: Nichita Herciu <nherciu@cloudbasesolutions.com> Date: Fri, 9 Nov 2018 08:13:00 +0200 Subject: [PATCH] Added "Resource flavor" column. This is a new column in the costs page that indicates the flavor name or volume type of a given resource. --- admin-costs-plugin/garr_costs/content/costs/tables.py | 7 ++++--- admin-costs-plugin/garr_costs/content/costs/views.py | 5 ++++- costs-plugin/garr_costs/content/costs/tables.py | 3 ++- costs-plugin/garr_costs/content/costs/views.py | 5 ++++- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/admin-costs-plugin/garr_costs/content/costs/tables.py b/admin-costs-plugin/garr_costs/content/costs/tables.py index 4276233..c182e4c 100644 --- a/admin-costs-plugin/garr_costs/content/costs/tables.py +++ b/admin-costs-plugin/garr_costs/content/costs/tables.py @@ -22,14 +22,15 @@ def get_link(resource): return urlresolvers.reverse(link, args=(resource['id'],)) -class CostsTable(tables.DataTable): +class CostsTable(tables.DataTable): resource = tables.WrappingColumn('name', verbose_name=_('Resource Name'), link=get_link) id = tables.WrappingColumn('id', verbose_name=_('ID'), attrs={'data-type': 'uuid'}, hidden=True) resource_type = tables.WrappingColumn('resource_type', verbose_name=_('Resource Type')) - + + flavor = tables.Column('flavor', verbose_name=_("Resource flavor")) value = tables.Column('value', verbose_name=_('Usage')) unit = tables.Column('unit', verbose_name=_("Unit")) price = tables.Column('price', verbose_name=_("Price")) @@ -37,7 +38,7 @@ class CostsTable(tables.DataTable): def get_object_id(self, resource): return resource['id'] - + class Meta(object): name = 'costs_table' verbose_name = _("Costs") diff --git a/admin-costs-plugin/garr_costs/content/costs/views.py b/admin-costs-plugin/garr_costs/content/costs/views.py index 9a3fc12..abf670b 100644 --- a/admin-costs-plugin/garr_costs/content/costs/views.py +++ b/admin-costs-plugin/garr_costs/content/costs/views.py @@ -125,8 +125,10 @@ class IndexView(tables.DataTableView): try: if resource['type'] == 'instance': cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end) + resource_flavor = resource['flavor_name'] elif resource['type'] == 'volume': cost, usage, unit = get_volume_usage(self.request, resource, price, resource_usage_start, resource_usage_end, client) + resource_flavor = api.cinder.volume_type_get(self.request, resource['volume_type']).name else: continue except Exception as ex: @@ -144,7 +146,8 @@ class IndexView(tables.DataTableView): 'id': resource['id'], 'price': '{}/{}'.format(price, cost_unit), 'resource_type': resource['type'], - 'cost': cost + 'cost': cost, + 'flavor': resource_flavor }) return sorted(result, key=lambda resource: resource['name']) diff --git a/costs-plugin/garr_costs/content/costs/tables.py b/costs-plugin/garr_costs/content/costs/tables.py index aa3ec0e..7bc775e 100644 --- a/costs-plugin/garr_costs/content/costs/tables.py +++ b/costs-plugin/garr_costs/content/costs/tables.py @@ -36,6 +36,7 @@ class CostsTable(tables.DataTable): hidden=True) resource_type = tables.WrappingColumn('resource_type', verbose_name=_('Resource Type')) + flavor = tables.Column('flavor', verbose_name=_("Resource flavor")) value = tables.Column('value', verbose_name=_('Usage')) unit = tables.Column('unit', verbose_name=_("Unit")) price = tables.Column('price', verbose_name=_("Price")) @@ -48,4 +49,4 @@ class CostsTable(tables.DataTable): name = 'costs_table' verbose_name = _("Costs") table_actions = () - multi_select = False \ No newline at end of file + multi_select = False diff --git a/costs-plugin/garr_costs/content/costs/views.py b/costs-plugin/garr_costs/content/costs/views.py index 9a3fc12..abf670b 100644 --- a/costs-plugin/garr_costs/content/costs/views.py +++ b/costs-plugin/garr_costs/content/costs/views.py @@ -125,8 +125,10 @@ class IndexView(tables.DataTableView): try: if resource['type'] == 'instance': cost, usage, unit = get_instance_usage(resource, price, resource_usage_start, resource_usage_end) + resource_flavor = resource['flavor_name'] elif resource['type'] == 'volume': cost, usage, unit = get_volume_usage(self.request, resource, price, resource_usage_start, resource_usage_end, client) + resource_flavor = api.cinder.volume_type_get(self.request, resource['volume_type']).name else: continue except Exception as ex: @@ -144,7 +146,8 @@ class IndexView(tables.DataTableView): 'id': resource['id'], 'price': '{}/{}'.format(price, cost_unit), 'resource_type': resource['type'], - 'cost': cost + 'cost': cost, + 'flavor': resource_flavor }) return sorted(result, key=lambda resource: resource['name']) -- GitLab