Revision 5a70b1a3 snf-cyclades-app/synnefo/quotas/__init__.py

b/snf-cyclades-app/synnefo/quotas/__init__.py
72 72
                user_vm_limit = VMS_USER_QUOTA.get(userid, MAX_VMS_PER_USER)
73 73
                log.debug("Users VMs %s User Limits %s", user_vms,
74 74
                          user_vm_limit)
75
                if user_vms + size >= user_vm_limit:
76
                    raise NoQuantityError()
75
                if user_vms + size > user_vm_limit:
76
                    raise NoQuantityError(source='cyclades',
77
                                          target=userid,
78
                                          resource=resource,
79
                                          requested=size,
80
                                          current=user_vms,
81
                                          limit=user_vm_limit)
77 82
            if resource == "cyclades.network.private" and size > 0:
78 83
                user_networks = Network.objects.filter(userid=userid,
79 84
                                                       deleted=False).count()
80 85
                user_network_limit =\
81 86
                    NETWORKS_USER_QUOTA.get(userid, MAX_NETWORKS_PER_USER)
82
                if user_networks + size >= user_network_limit:
83
                    raise NoQuantityError()
87
                if user_networks + size > user_network_limit:
88
                    raise NoQuantityError(source='cyclades',
89
                                          target=userid,
90
                                          resource=resource,
91
                                          requested=size,
92
                                          current=user_networks,
93
                                          limit=user_network_limit)
84 94

  
85 95
        return None
86 96

  
......
187 197
    with get_quota_holder() as qh:
188 198
        try:
189 199
            serial = qh.issue_commission(**commission_info)
190
        except (NoCapacityError, NoQuantityError):
191
            raise OverLimit("Limit exceeded for your account")
200
        except (NoCapacityError, NoQuantityError) as e:
201
            msg, details = render_quotaholder_exception(e)
202
            raise OverLimit(msg, details=details)
192 203
        except CallError as e:
193
            if e.call_error in ["NoCapacityError", "NoQuantityError"]:
194
                raise OverLimit("Limit exceeded for your account")
204
            log.exception("Unexpected error")
195 205
            raise
196 206

  
197 207
    if serial:
......
318 328
        pending_serials = qh.get_pending_commissions(context={},
319 329
                                                     clientkey='cyclades')
320 330
    return pending_serials
331

  
332

  
333
def render_quotaholder_exception(e):
334
    resource_name = {"vm": "Virtual Machine",
335
                     "cpu": "CPU",
336
                     "ram": "RAM",
337
                     "network.private": "Private Network"}
338
    res = e.resource.replace("cyclades.", "", 1)
339
    try:
340
        resource = resource_name[res]
341
    except KeyError:
342
        resource = res
343

  
344
    requested = e.requested
345
    current = e.current
346
    limit = e.limit
347
    msg = "Resource Limit Exceeded for your account."
348
    details = "Limit for resource '%s' exceeded for your account."\
349
              " Current value: %s, Limit: %s, Requested: %s"\
350
              % (resource, current, limit, requested)
351
    return msg, details

Also available in: Unified diff