Add quota_destroy_all_by_project
This method will be used in the follow-up patch to add api controller for the quotas. Change-Id: I0562285bfa4bab431ced967be381292ed5962756
This commit is contained in:
parent
1218a3bd77
commit
04e1a2b520
@ -940,6 +940,13 @@ def quota_destroy(context, project_id, resource):
|
||||
resource)
|
||||
|
||||
|
||||
@profiler.trace("db")
|
||||
def quota_destroy_all_by_project(context, project_id, resource):
|
||||
"""Destroy all resource associated with a given project."""
|
||||
return _get_dbdriver_instance().quota_destroy_all_by_project(context,
|
||||
project_id)
|
||||
|
||||
|
||||
@profiler.trace("db")
|
||||
def quota_class_create(context, class_name, resource, limit):
|
||||
"""Create a quota class for the given name and resource"""
|
||||
|
@ -1234,6 +1234,11 @@ class EtcdAPI(object):
|
||||
def quota_destroy(self, context, project_id, resource):
|
||||
self.client.delete('/quotas/{}/{}' . format(project_id, resource))
|
||||
|
||||
@lockutils.synchronized('etcd_quota')
|
||||
def quota_destroy_all_by_project(self, context, project_id):
|
||||
self.client.delete('/quotas/{}' . format(project_id))
|
||||
self.client.delete('/quota_usages/{}' . format(project_id))
|
||||
|
||||
def quota_class_create(self, context, class_name, resource, limit):
|
||||
quota_class_data = {
|
||||
'class_name': class_name,
|
||||
|
@ -1099,6 +1099,24 @@ class Connection(object):
|
||||
filter_by(resource=resource)
|
||||
query.delete()
|
||||
|
||||
def quota_destroy_all_by_project(self, context, project_id):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
quotas = model_query(context, models.Quota, session=session).\
|
||||
filter_by(project_id).\
|
||||
all()
|
||||
|
||||
for quota in quotas:
|
||||
quota.delete(session=session)
|
||||
|
||||
quota_usages = model_query(context, models.QuotaUsage,
|
||||
session=session).\
|
||||
filter_by(project_id=project_id).\
|
||||
all()
|
||||
|
||||
for quota_usage in quota_usages:
|
||||
quota_usage.delete(session=session)
|
||||
|
||||
def quota_class_create(self, context, class_name, resource, limit):
|
||||
quota_class_ref = models.QuotaClass()
|
||||
quota_class_ref.class_name = class_name
|
||||
|
@ -20,7 +20,8 @@ from zun.objects import base
|
||||
class Quota(base.ZunPersistentObject, base.ZunObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Add uuid column
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Add destroy_all_by_project method
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(),
|
||||
@ -82,6 +83,15 @@ class Quota(base.ZunPersistentObject, base.ZunObject):
|
||||
db_quota = dbapi.quota_create(context, project_id, resource, limit)
|
||||
self._from_db_object(self, db_quota)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def destroy_all_by_project(cls, context, project_id):
|
||||
"""Destroy all quotas associated with a project.
|
||||
|
||||
:param context: security context.
|
||||
:param project_id: the id of the project
|
||||
"""
|
||||
dbapi.quota_destroy_all_by_project(context, project_id)
|
||||
|
||||
@base.remotable
|
||||
def destroy(self, context=None):
|
||||
"""Delete the Quota from the DB.
|
||||
|
@ -358,7 +358,7 @@ object_data = {
|
||||
'ComputeNode': '1.11-08be22db017745f4f0bc8f873eca7db0',
|
||||
'PciDevicePool': '1.0-3f5ddc3ff7bfa14da7f6c7e9904cc000',
|
||||
'PciDevicePoolList': '1.0-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'Quota': '1.1-627da82e1289d7a4df8db759e1df132b',
|
||||
'Quota': '1.2-3a7d520d119fe1e886baad968ef7990a',
|
||||
'QuotaClass': '1.1-239ae335b32036b86504684d3fdbeb7f',
|
||||
'ContainerPCIRequest': '1.0-b060f9f9f734bedde79a71a4d3112ee0',
|
||||
'ContainerPCIRequests': '1.0-7b8f7f044661fe4e24e6949c035af2c4',
|
||||
|
Loading…
x
Reference in New Issue
Block a user