Пример #1
0
def over_allocation_test(identity, esh_instances):
    from api import get_esh_driver
    from core.models.instance import convert_esh_instance
    from atmosphere import settings
    over_allocated, time_diff = check_over_allocation(
        identity.created_by.username, identity.id,
        time_period=relativedelta(day=1, months=1))
    logger.info("Overallocation Test: %s - %s - %s\tInstances:%s"
                % (identity.created_by.username, over_allocated, time_diff, esh_instances))
    if not over_allocated:
        # Nothing changed, bail.
        return False
    if settings.DEBUG:
        logger.info('Do not enforce allocations in DEBUG mode')
        return False
    driver = get_esh_driver(identity)
    running_instances = []
    for instance in esh_instances:
        #Suspend active instances, update the task in the DB
        try:
            if driver._is_active_instance(instance):
                driver.suspend_instance(instance)
        except Exception, e:
            if 'in vm_state suspended' not in e.message:
                raise
        updated_esh = driver.get_instance(instance.id)
        updated_core = convert_esh_instance(driver, updated_esh,
                                            identity.provider.id,
                                            identity.id,
                                            identity.created_by)
        running_instances.append(updated_core)
Пример #2
0
def over_allocation_test(identity, esh_instances):
    from api import get_esh_driver
    from core.models.instance import convert_esh_instance
    from atmosphere import settings
    over_allocated, time_diff = check_over_allocation(
        identity.created_by.username,
        identity.id,
        time_period=relativedelta(day=1, months=1))
    logger.info("Overallocation Test: %s - %s - %s\tInstances:%s" %
                (identity.created_by.username, over_allocated, time_diff,
                 esh_instances))
    if not over_allocated:
        # Nothing changed, bail.
        return False
    if settings.DEBUG:
        logger.info('Do not enforce allocations in DEBUG mode')
        return False
    driver = get_esh_driver(identity)
    running_instances = []
    for instance in esh_instances:
        #Suspend active instances, update the task in the DB
        try:
            if driver._is_active_instance(instance):
                driver.suspend_instance(instance)
        except Exception, e:
            if 'in vm_state suspended' not in e.message:
                raise
        updated_esh = driver.get_instance(instance.id)
        updated_core = convert_esh_instance(driver, updated_esh,
                                            identity.provider.id, identity.id,
                                            identity.created_by)
        running_instances.append(updated_core)
Пример #3
0
def check_quota(username, identity_id, esh_size, resuming=False):
    (over_quota, resource, requested, used, allowed) = check_over_quota(
        username, identity_id, esh_size, resuming=resuming
    )
    if over_quota:
        raise OverQuotaError(resource, requested, used, allowed)
    (over_allocation, time_diff) = check_over_allocation(username, identity_id, time_period=settings.FIXED_WINDOW)
    if over_allocation and not settings.DEBUG:
        raise OverAllocationError(time_diff)
Пример #4
0
def check_quota(username, identity_id, esh_size, resuming=False):
    (over_quota, resource,
     requested, used, allowed) = check_over_quota(username,
                                                  identity_id,
                                                  esh_size, resuming=resuming)
    if over_quota:
        raise OverQuotaError(resource, requested, used, allowed)

    (over_allocation, time_diff) = check_over_allocation(username,
                                                         identity_id)
    if over_allocation:
        raise OverAllocationError(time_diff)
Пример #5
0
def check_quota(username, identity_id, esh_size, resuming=False):
    (over_quota, resource,
     requested, used, allowed) = check_over_quota(username,
                                                  identity_id,
                                                  esh_size, resuming=resuming)
    if over_quota:
        raise OverQuotaError(resource, requested, used, allowed)
    (over_allocation, time_diff) =\
        check_over_allocation(username,
                              identity_id,
                              time_period=relativedelta(day=1, months=1))
    if over_allocation and not settings.DEBUG:
        raise OverAllocationError(time_diff)
Пример #6
0
def check_quota(username, identity_id, esh_size, resuming=False):
    (over_quota, resource,
     requested, used, allowed) = check_over_quota(username,
                                                  identity_id,
                                                  esh_size, resuming=resuming)
    if over_quota:
        raise OverQuotaError(resource, requested, used, allowed)
    (over_allocation, time_diff) =\
        check_over_allocation(username,
                              identity_id,
                              time_period=settings.FIXED_WINDOW)
    if over_allocation and not settings.DEBUG:
        raise OverAllocationError(time_diff)
Пример #7
0
def over_allocation_test(identity, esh_instances):
    from api import get_esh_driver
    from core.models.instance import convert_esh_instance
    over_allocated, time_diff = check_over_allocation(
        identity.created_by.username, identity.id)
    if not over_allocated:
        # Nothing changed, bail.
        return False
    driver = get_esh_driver(identity)
    for instance in esh_instances:
        #Suspend, get updated status/task, and update the DB
        try:
            driver.suspend_instance(instance)
        except Exception, e:
            if 'in vm_state suspended' not in e.message:
                raise
        updated_esh = driver.get_instance(instance.id)
        updated_core = convert_esh_instance(driver, updated_esh,
                                            identity.provider.id,
                                            identity.id,
                                            identity.created_by)
        updated_core.update_history(updated_esh.extra['status'],
                                    updated_esh.extra.get('task'))