Beispiel #1
0
def search(redis_handler, host):
    index_value = get_index(redis_handler, host)
    if not index_value:
        return None
    ## Initial search
    match_found = {}
    for hash_key in index_value.split(','):
        if not hash_key.strip():
            continue
        details = redis_handler.get_details(hash_key)
        if not details:
            continue
        match_found[hash_key] = [details, False]  ## False to indicate
                                                  ## further search can be done
    ## Full search
    while True:
        match_keys = [ key for key in match_found.keys()
                       if match_found[key][1] == False ]
        if len(match_keys) == 0:
            break
        hash_key = match_keys.pop()
        match_found[hash_key][1] = True
        ## Check for clues in initial search results
        details = match_found[hash_key][0]
        ## Search indexed items
        for key, comma_sep_values in details.items():
            for value in comma_sep_values.split(','):
                if key not in LOOKUP_INDEX:
                    continue
                if not value:
                    continue
                if redis_handler.get_index_hash_key(value) in match_found:
                    continue
                index_value = get_index(redis_handler, value)
                if index_value is None:
                    continue
                for new_hash_key in index_value.split(','):
                    if new_hash_key in match_found:
                        continue
                    details = redis_handler.get_details(new_hash_key)
                    if not details:
                        continue
                    match_found[new_hash_key] = [details, False]
    categorize_match = {
        'route53': [],
        'instance': [],
        'elb': [],
        'elastic_ip': [],
    }
    for k, v in match_found.items():
        if k.startswith(redis_handler.route53_hash_prefix):
            categorize_match['route53'].append(v[0])
        elif k.startswith(redis_handler.instance_hash_prefix):
            categorize_match['instance'].append(v[0])
        elif k.startswith(redis_handler.elb_hash_prefix):
            categorize_match['elb'].append(v[0])
        elif k.startswith(redis_handler.elastic_ip_hash_prefix):
            categorize_match['elastic_ip'].append(v[0])
    return categorize_match
Beispiel #2
0
def index_records(redis_handler, expire):
    global index_keys
    for hash_key in index_keys:
        details = redis_handler.get_details(hash_key)
        for key, value in details.items():
            if key not in INDEX:
                continue
            ## SRV records may contain ','. We need to separate values for
            ## effective indexing
            for v in value.split(','):
                v = v.split(' ')[-1]
                save_index(redis_handler, hash_key, v)
                redis_handler.expire_index(v, expire)
Beispiel #3
0
def index_records(redis_handler, expire):
    global index_keys
    for hash_key in index_keys:
        details = redis_handler.get_details(hash_key)
        for key, value in details.items():
            if key not in INDEX:
                continue
            ## SRV records may contain ','. We need to separate values for
            ## effective indexing
            for v in value.split(','):
                v = v.split(' ')[-1]
                save_index(redis_handler, hash_key, v)
                redis_handler.expire_index(v, expire)