summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-04-01 18:08:27 +0000
committerGerrit Code Review <review@openstack.org>2013-04-01 18:08:27 +0000
commit987977814dff8acb7a13d0f2d27dc20faef88395 (patch)
tree4b25107b3316e7df846ae06a607582c2b7552b58
parent95179a0a6d19c75f98db3319477f6a68d9989155 (diff)
parent1fefa254616df68fb13913c9a9272405d82b0efb (diff)
Merge "Show quota 'in_use' and 'reserved' info"
-rwxr-xr-xbin/nova-manage46
-rw-r--r--nova/tests/test_nova_manage.py3
2 files changed, 34 insertions, 15 deletions
diff --git a/bin/nova-manage b/bin/nova-manage
index f80660010..3bcccfcce 100755
--- a/bin/nova-manage
+++ b/bin/nova-manage
@@ -227,26 +227,44 @@ class ProjectCommands(object):
@args('--key', metavar='<key>', help='Key')
@args('--value', metavar='<value>', help='Value')
def quota(self, project_id, key=None, value=None):
- """Set or display quotas for project."""
+ """
+ Create, update or display quotas for project
+
+ If no quota key is provided, the quota will be displayed.
+ If a valid quota key is provided and it does not exist,
+ it will be created. Otherwise, it will be updated.
+ """
+
ctxt = context.get_admin_context()
project_quota = QUOTAS.get_project_quotas(ctxt, project_id)
- if key and key in project_quota:
- if value.lower() == 'unlimited':
- value = -1
- try:
- db.quota_update(ctxt, project_id, key, value)
- except exception.ProjectQuotaNotFound:
- db.quota_create(ctxt, project_id, key, value)
- else:
- print _('%(key)s is not a valid quota key. Valid options are: '
- '%(options)s.') % {'key': key,
- 'options': ', '.join(project_quota)}
- sys.exit(2)
+ # if key is None, that means we need to show the quotas instead
+ # of updating them
+ if key:
+ if key in project_quota:
+ if value.lower() == 'unlimited':
+ value = -1
+ try:
+ db.quota_update(ctxt, project_id, key, value)
+ except exception.ProjectQuotaNotFound:
+ db.quota_create(ctxt, project_id, key, value)
+ else:
+ print _('%(key)s is not a valid quota key. Valid options are: '
+ '%(options)s.') % {'key': key,
+ 'options': ', '.join(project_quota)}
+ sys.exit(2)
+ print_format = "%-36s %-10s %-10s %-10s"
+ print print_format % (
+ _('Quota'),
+ _('Limit'),
+ _('In Use'),
+ _('Reserved'))
+ # Retrieve the quota after update
project_quota = QUOTAS.get_project_quotas(ctxt, project_id)
for key, value in project_quota.iteritems():
if value['limit'] < 0 or value['limit'] is None:
value['limit'] = 'unlimited'
- print '%s: %s' % (key, value['limit'])
+ print print_format % (key, value['limit'], value['in_use'],
+ value['reserved'])
@args('--project', dest='project_id', metavar='<Project name>',
help='Project name')
diff --git a/nova/tests/test_nova_manage.py b/nova/tests/test_nova_manage.py
index 49f9f3256..727746b18 100644
--- a/nova/tests/test_nova_manage.py
+++ b/nova/tests/test_nova_manage.py
@@ -366,7 +366,8 @@ class ProjectCommandsTestCase(test.TestCase):
sys.stdout = sys.__stdout__
result = output.getvalue()
- self.assertEquals(('instances: unlimited' in result), True)
+ print_format = "%-36s %-10s" % ('instances', 'unlimited')
+ self.assertEquals((print_format in result), True)
def test_quota_update_invalid_key(self):
self.assertRaises(SystemExit,