Commit e87b125c authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

quotaholder: Rename counters to usage_min, usage_max

parent 615de8f9
......@@ -39,16 +39,16 @@ from django.db.models import Q
def from_holding(holding):
limit, imported_min, imported_max = holding
limit, usage_min, usage_max = holding
body = {'limit': limit,
'usage': imported_max,
'pending': imported_max-imported_min,
'usage': usage_max,
'pending': usage_max-usage_min,
}
return body
def limits_only(holding):
limit, imported_min, imported_max = holding
limit, usage_min, usage_max = holding
return limit
......
......@@ -62,7 +62,7 @@ def get_quota(holders=None, sources=None, resources=None):
quotas = {}
for holding in holdings:
key = (holding.holder, holding.source, holding.resource)
value = (holding.limit, holding.imported_min, holding.imported_max)
value = (holding.limit, holding.usage_min, holding.usage_max)
quotas[key] = value
return quotas
......@@ -186,8 +186,8 @@ def _log_provision(commission, provision, holding, log_time, reason):
'source': holding.source,
'resource': holding.resource,
'limit': holding.limit,
'imported_min': holding.imported_min,
'imported_max': holding.imported_max,
'usage_min': holding.usage_min,
'usage_max': holding.usage_max,
'delta_quantity': provision.quantity,
'issue_time': commission.issue_time,
'log_time': log_time,
......
......@@ -38,7 +38,7 @@ class Operation(object):
@staticmethod
def assertions(holding):
assert(holding.imported_min <= holding.imported_max)
assert(holding.usage_min <= holding.usage_max)
@classmethod
def _prepare(cls, holding, quantity, check=True):
......@@ -80,11 +80,11 @@ class Import(Operation):
@classmethod
def _prepare(cls, holding, quantity, check=True):
imported_max = holding.imported_max
new_imported_max = imported_max + quantity
usage_max = holding.usage_max
new_usage_max = usage_max + quantity
limit = holding.limit
if check and new_imported_max > limit:
if check and new_usage_max > limit:
holder = holding.holder
resource = holding.resource
m = ("%s has not enough capacity of %s." % (holder, resource))
......@@ -92,14 +92,14 @@ class Import(Operation):
raise NoCapacityError(m,
provision=provision,
limit=limit,
usage=imported_max)
usage=usage_max)
holding.imported_max = new_imported_max
holding.usage_max = new_usage_max
holding.save()
@classmethod
def _finalize(cls, holding, quantity):
holding.imported_min += quantity
holding.usage_min += quantity
holding.save()
......@@ -107,10 +107,10 @@ class Release(Operation):
@classmethod
def _prepare(cls, holding, quantity, check=True):
imported_min = holding.imported_min
new_imported_min = imported_min - quantity
usage_min = holding.usage_min
new_usage_min = usage_min - quantity
if check and new_imported_min < 0:
if check and new_usage_min < 0:
holder = holding.holder
resource = holding.resource
m = ("%s attempts to release more %s than it contains." %
......@@ -118,14 +118,14 @@ class Release(Operation):
provision = cls.provision(holding, quantity, importing=False)
raise NoQuantityError(m,
provision=provision,
available=imported_min)
available=usage_min)
holding.imported_min = new_imported_min
holding.usage_min = new_usage_min
holding.save()
@classmethod
def _finalize(cls, holding, quantity):
holding.imported_max -= quantity
holding.usage_max -= quantity
holding.save()
......
......@@ -47,8 +47,8 @@ class Holding(Model):
resource = CharField(max_length=4096, null=False)
limit = intDecimalField()
imported_min = intDecimalField(default=0)
imported_max = intDecimalField(default=0)
usage_min = intDecimalField(default=0)
usage_max = intDecimalField(default=0)
objects = ForUpdateManager()
......@@ -104,8 +104,8 @@ class ProvisionLog(Model):
source = CharField(max_length=4096, null=True)
resource = CharField(max_length=4096)
limit = intDecimalField()
imported_min = intDecimalField()
imported_max = intDecimalField()
usage_min = intDecimalField()
usage_max = intDecimalField()
delta_quantity = intDecimalField()
reason = CharField(max_length=4096)
......
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