def allowed_instances(context, requested_instances, instance_type):
    project_id = context.project_id
    context = context.elevated()
    requested_cores = requested_instances * instance_type['vcpus']
    requested_ram = requested_instances * instance_type['memory_mb']
    usage = db.instance_data_get_for_project(context, project_id)
    used_instances, used_cores, used_ram = usage
    quota = get_project_quotas(context, project_id)
    allowed_instances = _get_request_allotment(requested_instances,
                                               used_instances,
                                               quota['instances'])
    allowed_cores = _get_request_allotment(requested_cores, used_cores,
                                           quota['cores'])
    allowed_ram = _get_request_allotment(requested_ram, used_ram, quota['ram'])
    allowed_instances = min(allowed_instances,
                            allowed_cores // instance_type['vcpus'],
                            allowed_ram // instance_type['memory_mb'])
    return min(requested_instances, allowed_instances)
The commit_on_success context manager also works with a using argument.
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/quota.py/allowed_instances--crossover with--dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.5/tests/modeltests/transactions/tests.py/TransactionContextManagerTests.test_commit_on_success_with_using