示例#1
0
def report(instances):
    if not instances:
        raise Exception("Internal error: instances not found!")

    oneinstance = instances[list(instances.keys())[0]]
    infraid = oneinstance['infra_id']
    nodename = oneinstance['resolved_node_definition']['name']
    count = len(instances)

    target_count = int(
        util.coalesce(main_uds.get_scaling_target_count(infraid, nodename),
                      count))
    target_count += len(
        list(main_uds.get_scaling_createnode(infraid, nodename).keys()))
    target_count -= len(
        list(main_uds.get_scaling_destroynode(infraid, nodename).keys()))

    target_min, target_max = get_scaling_limits(
        oneinstance['node_description'])
    target_count = keep_limits_for_scaling(target_count,
                                           oneinstance['node_description'])

    return dict(actual=count,
                target=target_count,
                min=target_min,
                max=target_max)
示例#2
0
def process_drop_node_requests_with_ids(node, targetcount, dynamic_state):
    nodename = node['name']
    infraid = node['infra_id']
    #log.info('Calling process_drop_node_requests_with_ids({0}{1})...'.format(infraid,nodename))
    #log.info('        targetcount: {0}'.format(targetcount))

    existing_nodes_with_ips = {}
    existing_ips_with_nodes = {}
    for _, instance, in list(dynamic_state.items()):
        existing_nodes_with_ips[
            instance['node_id']] = instance['resource_address']
        if isinstance(instance['resource_address'], list):
            for nra in instance['resource_address']:
                existing_ips_with_nodes[nra] = instance['node_id']
        else:
            existing_ips_with_nodes[
                instance['resource_address']] = instance['node_id']
    #log.info('EXISTING NODES WITH IPS: {0}'.format(existing_nodes_with_ips))
    #log.info('EXISTING IPS WITH NODES: {0}'.format(existing_ips_with_nodes))

    #Collecting nodeids and requestids
    dnlist = main_uds.get_scaling_destroynode(infraid, nodename)
    #log.info('DNLIST: {0}'.format(dnlist))
    request_ids_with_destroy_node_id = dict()
    destroy_node_ids_with_request_id = dict()
    for keyid, nodeid in list(dnlist.items()):
        if nodeid != "":
            #Convert ipaddress to nodeid
            if nodeid.count('.') > 2:
                main_uds.del_scaling_destroynode(infraid, nodename, keyid)
                if nodeid in list(existing_ips_with_nodes):
                    ipaddress = nodeid
                    nodeid = existing_ips_with_nodes[ipaddress]
                    keyid = main_uds.set_scaling_destroynode(
                        infraid, nodename, nodeid)
                    request_ids_with_destroy_node_id[keyid] = nodeid
                    destroy_node_ids_with_request_id[nodeid] = keyid
            #Check if nodid is valid
            elif nodeid in list(existing_nodes_with_ips):
                request_ids_with_destroy_node_id[keyid] = nodeid
                destroy_node_ids_with_request_id[nodeid] = keyid
            else:
                main_uds.del_scaling_destroynode(infraid, nodename, keyid)
    #log.info('REQUEST_IDS_WITH_DESTROY_NODE_ID: {0}'.format(request_ids_with_destroy_node_id))
    #log.info('DESTROY_NODE_IDS_WITH_REQUEST_ID: {0}'.format(destroy_node_ids_with_request_id))
    if len(list(request_ids_with_destroy_node_id.keys())) > 0:
        targetmin, targetmax = get_scaling_limits(node)
        targetcount -= len(list(request_ids_with_destroy_node_id.keys()))
        #remove all destroy requests below minimum
        if targetcount < targetmin:
            log.warning(
                'Scaling: request(s) ignored, minimum count (%i) reached for node \'%s\'',
                targetmin, nodename)
            for keyid in list(
                    request_ids_with_destroy_node_id.keys())[:targetmin -
                                                             targetcount]:
                main_uds.del_scaling_destroynode(infraid, nodename, keyid)
        targetcount = max(targetcount, targetmin)
        main_uds.set_scaling_target_count(infraid, nodename, targetcount)
    return targetcount
示例#3
0
def process_drop_node_requests_with_no_ids(node, targetcount):
    nodename = node['name']
    infraid = node['infra_id']
    dnlist = main_uds.get_scaling_destroynode(infraid,nodename)
    destroynodes = dict()
    for keyid, nodeid in dnlist.iteritems():
        if nodeid == "":
            destroynodes[keyid]=nodeid
    if len(destroynodes.keys()) > 0:
        targetmin = node['scaling']['min']
        targetcount -= len(destroynodes.keys())
        #remove all destroy requests below minimum
        if targetcount < targetmin:
            for keyid in destroynodes.keys()[:targetmin-targetcount]:
                log.warning('Scaling: DROP node request ignored, minimum count reached for node \'%s\'', nodename )
                main_uds.del_scaling_destroynode(infraid,nodename,keyid)
        targetcount = max(targetcount,targetmin)
        main_uds.set_scaling_target_count(infraid,nodename,targetcount)
    return targetcount
示例#4
0
def process_drop_node_requests_with_no_ids(node, targetcount):
    nodename = node['name']
    infraid = node['infra_id']
    dnlist = main_uds.get_scaling_destroynode(infraid, nodename)
    destroynodes = dict()
    for keyid, nodeid in list(dnlist.items()):
        if nodeid == "":
            destroynodes[keyid] = nodeid
    if len(list(destroynodes.keys())) > 0:
        targetmin, targetmax = get_scaling_limits(node)
        targetcount -= len(list(destroynodes.keys()))
        #remove all destroy requests below minimum
        if targetcount < targetmin:
            log.warning(
                'Scaling: request(s) ignored, minimum count (%i) reached for node \'%s\'',
                targetmin, nodename)
            for keyid in list(destroynodes.keys())[:targetmin - targetcount]:
                main_uds.del_scaling_destroynode(infraid, nodename, keyid)
        targetcount = max(targetcount, targetmin)
        main_uds.set_scaling_target_count(infraid, nodename, targetcount)
    return targetcount
示例#5
0
def report(instances):
    if not instances:
        raise Exception("Internal error: instances not found!")
    
    oneinstance = instances[instances.keys()[0]]
    infraid = oneinstance['infra_id']
    nodename = oneinstance['resolved_node_definition']['name']
    count = len(instances)
    
    target_count = int(util.coalesce(main_uds.get_scaling_target_count(infraid,nodename),
                    count))
    target_count += len(main_uds.get_scaling_createnode(infraid,nodename).keys())
    target_count -= len(main_uds.get_scaling_destroynode(infraid,nodename).keys())

    target_min = oneinstance['node_description'].get('scaling',dict()).get('min',1)
    target_max = oneinstance['node_description'].get('scaling',dict()).get('max',1)

    target_count = max(target_count,target_min)
    target_count = min(target_count,target_max)

    return dict(actual=count, target=target_count, min=target_min,
            max=target_max)