Commit 5cbda43d authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

quotaholder: Improve data of NoCapacityError

Replace `available' by two fields: `limit' and `usage'.
parent e9eb7991
......@@ -417,7 +417,8 @@ commission_failure_response = {
"resource": "cyclades.ram",
"quantity": 520000000},
"name": "NoCapacityError",
"available": 420000000}}}
"limit": 600000000,
"usage": 180000000}}}
pending_commissions = [100, 200]
......
......@@ -222,7 +222,8 @@ Status Description
"quantity": 1
},
"name": "NoCapacityError",
"available": 0
"limit": 2,
"usage": 2
}
}
}
......
......@@ -91,7 +91,8 @@ class Import(Operation):
provision = cls.provision(holding, quantity, importing=True)
raise NoCapacityError(m,
provision=provision,
available=limit-imported_max)
limit=limit,
usage=imported_max)
holding.imported_max = new_imported_max
holding.save()
......
......@@ -51,31 +51,28 @@ class InvalidDataError(QuotaholderError):
class CommissionException(QuotaholderError):
data = {}
def add_data(self, kwargs, key):
value = kwargs.pop(key, None)
if value is not None:
self.data[key] = value
def __init__(self, *args, **kwargs):
self.data['name'] = self.__class__.__name__
provision = kwargs.pop('provision', None)
if provision is not None:
self.data['provision'] = provision
self.add_data(kwargs, 'provision')
QuotaholderError.__init__(self, *args, **kwargs)
class NoCapacityError(CommissionException):
def __init__(self, *args, **kwargs):
available = kwargs.pop('available', None)
if available is not None:
self.data['available'] = available
self.add_data(kwargs, 'usage')
self.add_data(kwargs, 'limit')
CommissionException.__init__(self, *args, **kwargs)
class NoQuantityError(CommissionException):
def __init__(self, *args, **kwargs):
available = kwargs.pop('available', None)
if available is not None:
self.data['available'] = available
self.add_data(kwargs, 'available')
CommissionException.__init__(self, *args, **kwargs)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment