Editable default quota support
Implement blueprint edit-default-quota DocImpact Using the class quotas named `default` as the default editable quotas. We can use the following novaclient command to update default quota: nova quota-class-update default <key> <value> Change-Id: I5a5001fadcbd61d550ebd5bdc33613b0ffdf29b2
This commit is contained in:
parent
68678bc3dd
commit
371a3524a3
@ -105,14 +105,18 @@ class DbQuotaDriver(object):
|
||||
|
||||
def get_defaults(self, context, resources):
|
||||
"""Given a list of resources, retrieve the default quotas.
|
||||
Use the class quotas named `_DEFAULT_QUOTA_NAME` as default quotas,
|
||||
if it exists.
|
||||
|
||||
:param context: The request context, for access checks.
|
||||
:param resources: A dictionary of the registered resources.
|
||||
"""
|
||||
|
||||
quotas = {}
|
||||
default_quotas = db.quota_class_get_default(context)
|
||||
for resource in resources.values():
|
||||
quotas[resource.name] = resource.default
|
||||
quotas[resource.name] = default_quotas.get(resource.name,
|
||||
resource.default)
|
||||
|
||||
return quotas
|
||||
|
||||
@ -180,6 +184,8 @@ class DbQuotaDriver(object):
|
||||
else:
|
||||
class_quotas = {}
|
||||
|
||||
default_quotas = self.get_defaults(context, resources)
|
||||
|
||||
for resource in resources.values():
|
||||
# Omit default/quota class values
|
||||
if not defaults and resource.name not in project_quotas:
|
||||
@ -187,7 +193,7 @@ class DbQuotaDriver(object):
|
||||
|
||||
quotas[resource.name] = dict(
|
||||
limit=project_quotas.get(resource.name, class_quotas.get(
|
||||
resource.name, resource.default)),
|
||||
resource.name, default_quotas[resource.name])),
|
||||
)
|
||||
|
||||
# Include usages if desired. This is optional because one
|
||||
|
@ -3930,6 +3930,28 @@ class KeyPairTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
param['user_id'], param['name'])
|
||||
|
||||
|
||||
class QuotaClassTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotaClassTestCase, self).setUp()
|
||||
self.ctxt = context.get_admin_context()
|
||||
|
||||
def test_quota_class_get_default(self):
|
||||
params = {
|
||||
'test_resource1': '10',
|
||||
'test_resource2': '20',
|
||||
'test_resource3': '30',
|
||||
}
|
||||
for res, limit in params.items():
|
||||
db.quota_class_create(self.ctxt, 'default', res, limit)
|
||||
|
||||
defaults = db.quota_class_get_default(self.ctxt)
|
||||
self.assertEqual(defaults, dict(class_name='default',
|
||||
test_resource1=10,
|
||||
test_resource2=20,
|
||||
test_resource3=30))
|
||||
|
||||
|
||||
class ArchiveTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user