Adds per-user-quotas support for more detailed quotas management

Implements blueprint per-user-quotas.

Based on the original quotas structure.

NOTE:
quota_instances, quota_cores, quota_ram, quota_volumes,
quota_gigabytes, quota_key_pairs and quota_security_groups
are supported per user.

Allow 'projectadmin' role to access the user quota setting
methods.

Add commands 'nova-manage quota project/user' for quotas
management.

Change-Id: I07a39499432571fedd819c53ae414240cefc3354
This commit is contained in:
Kylin CG
2012-06-04 22:21:41 +08:00
parent c1c3955830
commit 7ee7ec7b20
2 changed files with 53 additions and 1 deletions

View File

@@ -224,6 +224,10 @@ def _db_error(caught_exception):
class ProjectCommands(object):
"""Class for managing projects."""
@args('--project', dest="project_id", metavar='<Project name>',
help='Project name')
@args('--key', dest="key", metavar='<key>', help='Key')
@args('--value', dest="value", metavar='<value>', help='Value')
def quota(self, project_id, key=None, value=None):
"""Set or display quotas for project"""
ctxt = context.get_admin_context()
@@ -256,6 +260,52 @@ class ProjectCommands(object):
AccountCommands = ProjectCommands
class QuotaCommands(object):
"""Class for managing quotas."""
@args('--project', dest="project_id", metavar='<Project name>',
help='Project name')
@args('--key', dest="key", metavar='<key>', help='Key')
@args('--value', dest="value", metavar='<value>', help='Value')
def project(self, project_id, key=None, value=None):
"""Set or display quotas for project"""
ctxt = context.get_admin_context()
if key:
if value.lower() == 'unlimited':
value = None
try:
db.quota_update(ctxt, project_id, key, value)
except exception.ProjectQuotaNotFound:
db.quota_create(ctxt, project_id, key, value)
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'])
@args('--user', dest="user_id", metavar='<User name>',
help='User name')
@args('--project', dest="project_id", metavar='<Project name>',
help='Project name')
@args('--key', dest="key", metavar='<key>', help='Key')
@args('--value', dest="value", metavar='<value>', help='Value')
def user(self, user_id, project_id, key=None, value=None):
"""Set or display quotas for user"""
ctxt = context.get_admin_context()
if key:
if value.lower() == 'unlimited':
value = None
try:
db.quota_update_for_user(ctxt, user_id, project_id, key, value)
except exception.UserQuotaNotFound:
db.quota_create_for_user(ctxt, user_id, project_id, key, value)
user_quota = QUOTAS.get_user_quotas(ctxt, user_id, project_id)
for key, value in user_quota.iteritems():
if value['limit'] < 0 or value['limit'] is None:
value['limit'] = 'unlimited'
print '%s: %s' % (key, value['limit'])
class FixedIpCommands(object):
"""Class for managing fixed ip."""
@@ -1319,6 +1369,7 @@ CATEGORIES = [
('logs', GetLogCommands),
('network', NetworkCommands),
('project', ProjectCommands),
('quota', QuotaCommands),
('service', ServiceCommands),
('shell', ShellCommands),
('sm', StorageManagerCommands),

View File

@@ -105,7 +105,8 @@
"compute_extension:networks": [],
"compute_extension:networks:view": [],
"compute_extension:quotas:show": [],
"compute_extension:quotas:update": [],
"compute_extension:quotas:update_for_project": [],
"compute_extension:quotas:update_for_user": [],
"compute_extension:quota_classes": [],
"compute_extension:rescue": [],
"compute_extension:security_groups": [],