help='number of seconds between subsequent usage refreshes'),
cfg.StrOpt('quota_driver',
default='cinder.quota.DbQuotaDriver',
- help='default driver to use for quota checks'), ]
+ help='default driver to use for quota checks'),
+ cfg.BoolOpt('use_default_quota_class',
+ default='True',
+ help='whether to use default quota class for default quota'), ]
CONF = cfg.CONF
CONF.register_opts(quota_opts)
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 = {}
+ if CONF.use_default_quota_class:
+ default_quotas = db.quota_class_get_default(context)
for resource in resources.values():
- quotas[resource.name] = resource.default
+ if resource.name not in default_quotas:
+ LOG.deprecated(_("Default quota for resource: %(res)s is set "
+ "by the default quota flag: quota_%(res)s, "
+ "it is now deprecated. Please use the "
+ "the default quota class for default "
+ "quota.") % {'res': resource.name})
+ quotas[resource.name] = default_quotas.get(resource.name,
+ resource.default)
return quotas
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:
continue
quotas[resource.name] = dict(
- limit=project_quotas.get(resource.name,
- class_quotas.get(resource.name,
- resource.default)), )
+ limit=project_quotas.get(
+ resource.name,
+ class_quotas.get(resource.name,
+ default_quotas[resource.name])),
+ )
# Include usages if desired. This is optional because one
# internal consumer of this interface wants to access the
def test_get_defaults(self):
# Use our pre-defined resources
+ self._stub_quota_class_get_default()
result = self.driver.get_defaults(None, quota.QUOTAS._resources)
self.assertEqual(
snapshots=10,
gigabytes=1000, ))
+ def _stub_quota_class_get_default(self):
+ # Stub out quota_class_get_default
+ def fake_qcgd(context):
+ self.calls.append('quota_class_get_default')
+ return dict(volumes=10,
+ snapshots=10,
+ gigabytes=1000,)
+ self.stubs.Set(db, 'quota_class_get_default', fake_qcgd)
+
def _stub_quota_class_get_all_by_name(self):
# Stub out quota_class_get_all_by_name
def fake_qcgabn(context, quota_class):
self.stubs.Set(db, 'quota_usage_get_all_by_project', fake_qugabp)
self._stub_quota_class_get_all_by_name()
+ self._stub_quota_class_get_default()
def test_get_project_quotas(self):
self._stub_get_by_project()
self.assertEqual(self.calls, ['quota_get_all_by_project',
'quota_usage_get_all_by_project',
- 'quota_class_get_all_by_name', ])
+ 'quota_class_get_all_by_name',
+ 'quota_class_get_default', ])
self.assertEqual(result, dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
quota.QUOTAS._resources, 'test_project')
self.assertEqual(self.calls, ['quota_get_all_by_project',
- 'quota_usage_get_all_by_project', ])
+ 'quota_usage_get_all_by_project',
+ 'quota_class_get_default', ])
self.assertEqual(result, dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
self.assertEqual(self.calls, ['quota_get_all_by_project',
'quota_usage_get_all_by_project',
- 'quota_class_get_all_by_name', ])
+ 'quota_class_get_all_by_name',
+ 'quota_class_get_default', ])
self.assertEqual(result, dict(volumes=dict(limit=10,
in_use=2,
reserved=0, ),
self.assertEqual(self.calls, ['quota_get_all_by_project',
'quota_usage_get_all_by_project',
- 'quota_class_get_all_by_name', ])
+ 'quota_class_get_all_by_name',
+ 'quota_class_get_default', ])
self.assertEqual(result,
dict(gigabytes=dict(limit=50,
in_use=10,
quota.QUOTAS._resources, 'test_project', usages=False)
self.assertEqual(self.calls, ['quota_get_all_by_project',
- 'quota_class_get_all_by_name', ])
+ 'quota_class_get_all_by_name',
+ 'quota_class_get_default', ])
self.assertEqual(result, dict(volumes=dict(limit=10, ),
snapshots=dict(limit=10, ),
gigabytes=dict(limit=50, ), ))