From 0314de8336a56040c973542d335607a2dbb17939 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Tue, 24 Jan 2012 10:45:23 -0800 Subject: [PATCH] Remove another quota-related openstackx dep * Another fix for bug 919420 Change-Id: Iea5d254804251e099813a90ef972bb2e2d4d8a55 --- horizon/horizon/api/nova.py | 23 ++++++++++++++++--- .../dashboards/syspanel/quotas/views.py | 7 +++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/horizon/horizon/api/nova.py b/horizon/horizon/api/nova.py index 139d43135aa..1fe91baaa82 100644 --- a/horizon/horizon/api/nova.py +++ b/horizon/horizon/api/nova.py @@ -77,7 +77,7 @@ class VNCConsole(APIDictWrapper): class Quota(object): - """ Basic wrapper for individual limits in a quota. """ + """ Basic wrapper for individual limits in a quota.""" def __init__(self, name, limit): self.name = name self.limit = limit @@ -86,6 +86,19 @@ def __repr__(self): return "" % (self.name, self.limit) +class QuotaSet(object): + """ Basic wrapper for quota sets.""" + def __init__(self, apiresource): + self.items = [] + for k in apiresource._info.keys(): + if k in ['id']: + continue + v = int(apiresource._info[k]) + q = Quota(k, v) + self.items.append(q) + setattr(self, k, v) + + class Server(APIResourceWrapper): """Simple wrapper around openstackx.extras.server.Server @@ -327,14 +340,18 @@ def server_remove_floating_ip(request, server, address): return novaclient(request).servers.remove_floating_ip(server, fip) -def tenant_quota_get(request, tenant): - return novaclient(request).quotas.get(tenant) +def tenant_quota_get(request, tenant_id): + return QuotaSet(novaclient(request).quotas.get(tenant_id)) def tenant_quota_update(request, tenant_id, **kwargs): novaclient(request).quotas.update(tenant_id, **kwargs) +def tenant_quota_defaults(request, tenant_id): + return QuotaSet(novaclient(request).quotas.defaults(tenant_id)) + + @check_openstackx def usage_get(request, tenant_id, start, end): return Usage(extras_api(request).usage.get(tenant_id, start, end)) diff --git a/horizon/horizon/dashboards/syspanel/quotas/views.py b/horizon/horizon/dashboards/syspanel/quotas/views.py index 23125150970..b7fd0afcaab 100644 --- a/horizon/horizon/dashboards/syspanel/quotas/views.py +++ b/horizon/horizon/dashboards/syspanel/quotas/views.py @@ -37,10 +37,9 @@ class IndexView(tables.DataTableView): def get_data(self): try: - quotas = api.admin_api(self.request).quota_sets.get(True)._info - quotas['ram'] = int(quotas['ram']) - quotas.pop('id') - data = [api.nova.Quota(key, val) for key, val in quotas.items()] + quota_set = api.tenant_quota_defaults(self.request, + self.request.user.tenant_id) + data = quota_set.items except Exception, e: data = [] LOG.exception('Exception while getting quota info')