Ejemplo n.º 1
0
def check_over_instance_quota(
    username,
    identity_uuid,
    esh_size=None,
    include_networking=False,
    raise_exc=True
):
    """
    Checks quota based on current limits (and an instance of size, if passed).
    param - esh_size - if included, update the CPU and Memory totals & increase instance_count
    param - launch_networking - if True, increase floating_ip_count
    param - raise_exc - if True, raise ValidationError, otherwise return False

    return True if passing
    return False if ValidationError occurs and raise_exc=False
    By default, allow ValidationError to raise.

    return or raise exc
    """
    memberships_available = IdentityMembership.objects.filter(
        identity__uuid=identity_uuid,
        member__memberships__user__username=username
    )
    if memberships_available:
        membership = memberships_available.first()
    identity = membership.identity
    quota = identity.quota
    driver = get_cached_driver(identity=identity)
    new_port = new_floating_ip = new_instance = new_cpu = new_ram = 0
    if esh_size:
        new_cpu += esh_size.cpu
        new_ram += esh_size.ram
        new_instance += 1
        new_port += 1
    if include_networking:
        new_floating_ip += 1
    # Will throw ValidationError if false.
    try:
        has_cpu_quota(driver, quota, new_cpu)
        has_mem_quota(driver, quota, new_ram)
        has_instance_count_quota(driver, quota, new_instance)
        has_floating_ip_count_quota(driver, quota, new_floating_ip)
        has_port_count_quota(identity, driver, quota, new_port)
        return True
    except ValidationError:
        if raise_exc:
            raise
        return False
Ejemplo n.º 2
0
def check_over_instance_quota(
        username, identity_uuid, esh_size=None,
        include_networking=False, raise_exc=True):
    """
    Checks quota based on current limits (and an instance of size, if passed).
    param - esh_size - if included, update the CPU and Memory totals & increase instance_count
    param - launch_networking - if True, increase floating_ip_count
    param - raise_exc - if True, raise ValidationError, otherwise return False

    return True if passing
    return False if ValidationError occurs and raise_exc=False
    By default, allow ValidationError to raise.

    return or raise exc
    """
    memberships_available = IdentityMembership.objects.filter(
        identity__uuid=identity_uuid,
        member__memberships__user__username=username)
    if memberships_available:
        membership = memberships_available.first()
    identity = membership.identity
    quota = identity.quota
    driver = get_cached_driver(identity=identity)
    new_port = new_floating_ip = new_instance = new_cpu = new_ram = 0
    if esh_size:
        new_cpu += esh_size.cpu
        new_ram += esh_size.ram
        new_instance += 1
        new_port += 1
    if include_networking:
        new_floating_ip += 1
    # Will throw ValidationError if false.
    try:
        has_cpu_quota(driver, quota, new_cpu)
        has_mem_quota(driver, quota, new_ram)
        has_instance_count_quota(driver, quota, new_instance)
        has_floating_ip_count_quota(driver, quota, new_floating_ip)
        has_port_count_quota(identity, driver, quota, new_port)
        return True
    except ValidationError:
        if raise_exc:
            raise
        return False