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:
		| @@ -224,6 +224,10 @@ def _db_error(caught_exception): | |||||||
| class ProjectCommands(object): | class ProjectCommands(object): | ||||||
|     """Class for managing projects.""" |     """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): |     def quota(self, project_id, key=None, value=None): | ||||||
|         """Set or display quotas for project""" |         """Set or display quotas for project""" | ||||||
|         ctxt = context.get_admin_context() |         ctxt = context.get_admin_context() | ||||||
| @@ -256,6 +260,52 @@ class ProjectCommands(object): | |||||||
| AccountCommands = ProjectCommands | 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 FixedIpCommands(object): | ||||||
|     """Class for managing fixed ip.""" |     """Class for managing fixed ip.""" | ||||||
|  |  | ||||||
| @@ -1319,6 +1369,7 @@ CATEGORIES = [ | |||||||
|     ('logs', GetLogCommands), |     ('logs', GetLogCommands), | ||||||
|     ('network', NetworkCommands), |     ('network', NetworkCommands), | ||||||
|     ('project', ProjectCommands), |     ('project', ProjectCommands), | ||||||
|  |     ('quota', QuotaCommands), | ||||||
|     ('service', ServiceCommands), |     ('service', ServiceCommands), | ||||||
|     ('shell', ShellCommands), |     ('shell', ShellCommands), | ||||||
|     ('sm', StorageManagerCommands), |     ('sm', StorageManagerCommands), | ||||||
|   | |||||||
| @@ -105,7 +105,8 @@ | |||||||
|     "compute_extension:networks": [], |     "compute_extension:networks": [], | ||||||
|     "compute_extension:networks:view": [], |     "compute_extension:networks:view": [], | ||||||
|     "compute_extension:quotas:show": [], |     "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:quota_classes": [], | ||||||
|     "compute_extension:rescue": [], |     "compute_extension:rescue": [], | ||||||
|     "compute_extension:security_groups": [], |     "compute_extension:security_groups": [], | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Kylin CG
					Kylin CG