@@ -0,0 +1,1423 @@
+from service.allocation import check_allocation%0A%0Afrom api import get_esh_driver%0Afrom core.models import IdentityMembership, Identity%0A%0Afrom threepio import logger%0A%0Adef get_current_quota(identity_id):%0A    driver = get_esh_driver(Identity.objects.get(id=identity_id))%0A    cpu = ram = disk = 0%0A    for instance in driver.list_instances():%0A        size = instance.size%0A        cpu += size.cpu%0A        ram += size.ram%0A        disk += size._size.disk%0A    return %7B'cpu':cpu, 'ram':ram, 'disk':disk%7D%0A%0Adef check_quota(username, identity_id, esh_size):%0A    membership = IdentityMembership.objects.get(identity__id=identity_id,%0A                                                member__name=username)%0A    quota_limit = membership.quota%0A    current = get_current_quota(identity_id)%0A    cur_cpu, cur_ram, cur_disk = current%5B'cpu'%5D, current%5B'ram'%5D, current%5B'disk'%5D%0A    new_cpu, new_ram, new_disk = esh_size.cpu, esh_size.ram, esh_size._size.disk%0A    if cur_cpu + new_cpu %3E quota_limit.cpu:%0A        logger.debug(%22Current:%25s + New: %25s %3E Quota: %25s%22%5C%0A                    %25 (cur_cpu, new_cpu, quota_limit.cpu))%0A        return False%0A    if cur_ram + new_ram %3E quota_limit.memory * 1024:  # Quota memory GB -%3E MB%0A        logger.debug(%22Current:%25s + New: %25s %3E Quota: %25s%22%5C%0A                    %25 (cur_ram, new_ram, quota_limit.memory*1024))%0A        return False%0A    if not check_allocation(username, identity_id):%0A        return False%0A    return True%0A

Add the service.quota module. new file: service/quota.py