summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-08-06 08:52:18 +0000
committerGerrit Code Review <review@openstack.org>2013-08-06 08:52:18 +0000
commit10279ba973f52a26d4137fe294ea88bc38ac4a05 (patch)
treee9318ec8c7c3af20d317d98675a98fed054f8b8d /openstack
parent82fa17f89501fe8b2dfd246ce5a8054f1c74c336 (diff)
parent187227ffe5a2ea1f3b9f6c43081971d5b0009a25 (diff)
downloadoslo-10279ba973f52a26d4137fe294ea88bc38ac4a05.tar.gz
oslo-10279ba973f52a26d4137fe294ea88bc38ac4a05.tar.xz
oslo-10279ba973f52a26d4137fe294ea88bc38ac4a05.zip
Merge "Add missing exceptions for per user quota"
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/quota.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/openstack/common/quota.py b/openstack/common/quota.py
index e4b67de..43f8b01 100644
--- a/openstack/common/quota.py
+++ b/openstack/common/quota.py
@@ -52,63 +52,60 @@ CONF.register_opts(common_quota_opts)
class QuotaException(Exception):
- """Base exception for quota."""
+ """Base exception for quota.
- message = _("Quota exception occurred.")
+ To correctly use this class, inherit from it and define
+ a 'msg_fmt' property. That msg_fmt will get printf'd
+ with the keyword arguments provided to the constructor.
+
+ """
+ msg_fmt = _("Quota exception occurred.")
code = 500
headers = {}
safe = False
def __init__(self, message=None, **kwargs):
- self.kwargs = kwargs
-
- if 'code' not in self.kwargs:
- try:
- self.kwargs['code'] = self.code
- except AttributeError:
- pass
-
+ self.kwargs = {'code': self.code}
+ self.kwargs.update(kwargs)
if not message:
try:
- message = self.message % kwargs
-
+ message = self.msg_fmt % self.kwargs
except Exception:
# kwargs doesn't match a variable in the message
# log the issue and the kwargs
LOG.exception(_('Exception in string format operation'))
for name, value in kwargs.iteritems():
LOG.error("%s: %s" % (name, value))
- else:
- # at least get the core message out if something happened
- message = self.message
-
+ # at least get the core message out if something happened
+ message = self.msg_fmt
super(QuotaException, self).__init__(message)
def format_message(self):
- if self.__class__.__name__.endswith('_Remote'):
- return self.args[0]
- else:
- return unicode(self)
+ return unicode(self)
class QuotaError(QuotaException):
- message = _("Quota exceeded") + ": code=%(code)s"
+ msg_fmt = _("Quota exceeded") + ": code=%(code)s"
code = 413
headers = {'Retry-After': 0}
safe = True
class InvalidQuotaValue(QuotaException):
- message = _("Change would make usage less than 0 for the following "
+ msg_fmt = _("Change would make usage less than 0 for the following "
"resources: %(unders)s")
class OverQuota(QuotaException):
- message = _("Quota exceeded for resources: %(overs)s")
+ msg_fmt = _("Quota exceeded for resources: %(overs)s")
+
+
+class QuotaExists(QuotaException):
+ message = _("Quota exists")
class QuotaResourceUnknown(QuotaException):
- message = _("Unknown quota resources %(unknown)s.")
+ msg_fmt = _("Unknown quota resources %(unknown)s.")
class QuotaNotFound(QuotaException):
@@ -117,24 +114,29 @@ class QuotaNotFound(QuotaException):
class QuotaUsageNotFound(QuotaNotFound):
- message = _("Quota usage for project %(project_id)s could not be found.")
+ msg_fmt = _("Quota usage for project %(project_id)s could not be found.")
class ProjectQuotaNotFound(QuotaNotFound):
- message = _("Quota for project %(project_id)s could not be found.")
+ msg_fmt = _("Quota for project %(project_id)s could not be found.")
+
+
+class ProjectUserQuotaNotFound(QuotaNotFound):
+ msg_fmt = _("Quota for user %(user_id)s in project %(project_id)s "
+ "could not be found.")
class QuotaClassNotFound(QuotaNotFound):
- message = _("Quota class %(class_name)s could not be found.")
+ msg_fmt = _("Quota class %(class_name)s could not be found.")
class ReservationNotFound(QuotaNotFound):
- message = _("Quota reservation %(uuid)s could not be found.")
+ msg_fmt = _("Quota reservation %(uuid)s could not be found.")
class InvalidReservationExpiration(QuotaException):
code = 400
- message = _("Invalid reservation expiration %(expire)s.")
+ msg_fmt = _("Invalid reservation expiration %(expire)s.")
class DbQuotaDriver(object):