Skip to content

Commit

Permalink
Remove another quota-related openstackx dep
Browse files Browse the repository at this point in the history
 * Another fix for bug 919420

Change-Id: Iea5d254804251e099813a90ef972bb2e2d4d8a55
  • Loading branch information
sleepsonthefloor committed Jan 24, 2012
1 parent 97b53f5 commit 0314de8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 20 additions & 3 deletions horizon/horizon/api/nova.py
Expand Up @@ -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
Expand All @@ -86,6 +86,19 @@ def __repr__(self):
return "<Quota: (%s, %s)>" % (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
Expand Down Expand Up @@ -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))
Expand Down
7 changes: 3 additions & 4 deletions horizon/horizon/dashboards/syspanel/quotas/views.py
Expand Up @@ -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')
Expand Down

0 comments on commit 0314de8

Please sign in to comment.