Commit 3d720d3f authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Add details to OverLimit exception

* Add details to OverLimit exception, with the values provided by
kamamaki.clients.quotaholder.exception.CommissionValueException.
* Fix DummyQuotaholder exceptions
* Fix DummyQuotaholder checks
parent a35124e3
......@@ -72,15 +72,25 @@ class DummyQuotaholderClient(object):
user_vm_limit = VMS_USER_QUOTA.get(userid, MAX_VMS_PER_USER)
log.debug("Users VMs %s User Limits %s", user_vms,
user_vm_limit)
if user_vms + size >= user_vm_limit:
raise NoQuantityError()
if user_vms + size > user_vm_limit:
raise NoQuantityError(source='cyclades',
target=userid,
resource=resource,
requested=size,
current=user_vms,
limit=user_vm_limit)
if resource == "cyclades.network.private" and size > 0:
user_networks = Network.objects.filter(userid=userid,
deleted=False).count()
user_network_limit =\
NETWORKS_USER_QUOTA.get(userid, MAX_NETWORKS_PER_USER)
if user_networks + size >= user_network_limit:
raise NoQuantityError()
if user_networks + size > user_network_limit:
raise NoQuantityError(source='cyclades',
target=userid,
resource=resource,
requested=size,
current=user_networks,
limit=user_network_limit)
return None
......@@ -187,11 +197,11 @@ def issue_commission(**commission_info):
with get_quota_holder() as qh:
try:
serial = qh.issue_commission(**commission_info)
except (NoCapacityError, NoQuantityError):
raise OverLimit("Limit exceeded for your account")
except (NoCapacityError, NoQuantityError) as e:
msg, details = render_quotaholder_exception(e)
raise OverLimit(msg, details=details)
except CallError as e:
if e.call_error in ["NoCapacityError", "NoQuantityError"]:
raise OverLimit("Limit exceeded for your account")
log.exception("Unexpected error")
raise
if serial:
......@@ -318,3 +328,24 @@ def get_quotaholder_pending():
pending_serials = qh.get_pending_commissions(context={},
clientkey='cyclades')
return pending_serials
def render_quotaholder_exception(e):
resource_name = {"vm": "Virtual Machine",
"cpu": "CPU",
"ram": "RAM",
"network.private": "Private Network"}
res = e.resource.replace("cyclades.", "", 1)
try:
resource = resource_name[res]
except KeyError:
resource = res
requested = e.requested
current = e.current
limit = e.limit
msg = "Resource Limit Exceeded for your account."
details = "Limit for resource '%s' exceeded for your account."\
" Current value: %s, Limit: %s, Requested: %s"\
% (resource, current, limit, requested)
return msg, details
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