Esempio n. 1
0
def update_quota(data, cloud, operation):
    """Update the avaiable quota of a cloud"""

    if operation == ('delete' or 'remove'):
        ram, vcpus, instances = calculate_usage(cloud, data)
        cloud['quota']['available']['ram'] += ram
        cloud['quota']['available']['vcpus'] += vcpus
        cloud['quota']['available']['instances'] += instances

    if operation == ('add' or 'create'):
        ram, vcpus, instances = calculate_usage(cloud, data)
        cloud['quota']['available']['ram'] -= ram
        cloud['quota']['available']['vcpus'] -= vcpus
        cloud['quota']['available']['instances'] -= instances

    conf = config.read_conf()

    for i in range(0, len(conf['clouds'])):
        if conf['clouds'][i]['id'] == cloud['id']:
            conf['clouds'][i] = cloud

    db.flush_data_to_mongo('conf', conf)
Esempio n. 2
0
def update_quota(data, cloud, operation):
    """Update the avaiable quota of a cloud"""

    if operation == ('delete' or 'remove'):
        ram, vcpus, instances = calculate_usage(cloud, data)
        cloud['quota']['available']['ram'] += ram
        cloud['quota']['available']['vcpus'] += vcpus
        cloud['quota']['available']['instances'] += instances

    if operation == ('add' or 'create'):
        ram, vcpus, instances = calculate_usage(cloud, data)
        cloud['quota']['available']['ram'] -= ram
        cloud['quota']['available']['vcpus'] -= vcpus
        cloud['quota']['available']['instances'] -= instances

    conf = config.read_conf()
    
    for i in range(0, len(conf['clouds'])):
        if conf['clouds'][i]['id'] == cloud['id']:
            conf['clouds'][i] = cloud

    db.flush_data_to_mongo('conf', conf)
Esempio n. 3
0
def schedule(data, operation):
    """Schedules based on certain filters"""

    if operation == 'create':
        conf = config.read_conf()

        clouds = filter_quota(data, conf)
        if clouds == []:
            return False

        cloud = filter_priority(clouds)
        if cloud is None:
            return False

        data['job']['cloud'] = cloud['name']
        db.flush_data_to_mongo('job', data)

        update_quota(data, cloud, operation)
        Process(target=cluster.create,
                args=(data, cloud, conf['general'])).start()

    elif operation == 'delete':

        job_id = data['job']['id']

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == data['job']['cloud']:
                break

        Process(target=cluster.delete, args=(job_id, cloud)).start()
        update_quota(data, cloud, operation)

    elif operation == 'add':

        job_id = data['id']
        if multistack.services.job.info(job_id)[0]:
            job_obj = multistack.services.job.info(job_id)[1]
        else:
            return False

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == job_obj['job']['cloud']:
                break

        new_req_obj = dict()
        new_req_obj['job'] = data

        update_quota(new_req_obj, cloud, operation)
        Process(target=cluster.add_nodes,
                args=(data, cloud, job_id, conf['general'])).start()

    elif operation == 'remove':

        job_id = data['id']
        if multistack.services.job.info(job_id)[0]:
            job_obj = multistack.services.job.info(job_id)[1]
        else:
            return False

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == job_obj['job']['cloud']:
                break

        new_req_obj = dict()
        new_req_obj['job'] = data

        Process(target=cluster.remove_nodes,
                args=(data, cloud, job_id)).start()
        update_quota(new_req_obj, cloud, operation)

    return True
Esempio n. 4
0
def schedule(data, operation):
    """Schedules based on certain filters"""

    if operation == 'create':
        conf = config.read_conf()

        clouds = filter_quota(data, conf)
        if clouds == []:
            return False

        cloud = filter_priority(clouds)
        if cloud is None:
            return False

        data['job']['cloud'] = cloud['name']
        db.flush_data_to_mongo('job', data)

        update_quota(data, cloud, operation)
        Process(target = cluster.create, args = (data, cloud, conf['general'])).start()

    elif operation == 'delete':

        job_id = data['job']['id']

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == data['job']['cloud']:
                break

        Process(target = cluster.delete, args = (job_id, cloud)).start()
        update_quota(data, cloud, operation)

    elif operation == 'add':

        job_id = data['id']
        if multistack.services.job.info(job_id)[0]:
            job_obj = multistack.services.job.info(job_id)[1]
        else:
            return False

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == job_obj['job']['cloud']:
                break

        new_req_obj = dict()
        new_req_obj['job'] = data

        update_quota(new_req_obj, cloud, operation)
        Process(target = cluster.add_nodes, args = (data, cloud, job_id, conf['general'])).start()

    elif operation == 'remove':

        job_id = data['id']
        if multistack.services.job.info(job_id)[0]:
            job_obj = multistack.services.job.info(job_id)[1]
        else:
            return False

        conf = config.read_conf()
        for cloud in conf['clouds']:
            if cloud['name'] == job_obj['job']['cloud']:
                break

        new_req_obj = dict()
        new_req_obj['job'] = data

        Process(target = cluster.remove_nodes, args = (data, cloud, job_id)).start()
        update_quota(new_req_obj, cloud, operation)

    return True