Ejemplo n.º 1
0
def sync_ec2_elbs(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        elb_list = ec2_handler.fetch_all_elbs()
    except Exception as e:
        print "Exception for ELB in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for elb in elb_list:
        details, instance_id_list = ec2_handler.get_elb_details(elb)
        details['timestamp'] = int(time.time())
        for instance_id in instance_id_list:
            instance_elb_names = redis_handler.get_instance_item_value(
                region=details['region'], instance_id=instance_id,
                key='instance_elb_names'
            ) or ''
            instance_elb_names = set(instance_elb_names.split(','))
            if '' in instance_elb_names:
                instance_elb_names.remove('')
            instance_elb_names.add(elb.name)
            instance_elb_names = ','.join(instance_elb_names)
            redis_handler.add_instance_details(
                region=details['region'], instance_id=instance_id,
                key='instance_elb_names', value=instance_elb_names,
            )
        hash_key, status = redis_handler.save_elb_details(details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "ELB sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 2
0
def sync_ec2_elbs(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        elb_list = ec2_handler.fetch_all_elbs()
    except Exception as e:
        print "Exception for ELB in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for elb in elb_list:
        details, instance_id_list = ec2_handler.get_elb_details(elb)
        details['timestamp'] = int(time.time())
        for instance_id in instance_id_list:
            instance_elb_names = redis_handler.get_instance_item_value(
                region=details['region'],
                instance_id=instance_id,
                key='instance_elb_names') or ''
            instance_elb_names = set(instance_elb_names.split(','))
            if '' in instance_elb_names:
                instance_elb_names.remove('')
            instance_elb_names.add(elb.name)
            instance_elb_names = ','.join(instance_elb_names)
            redis_handler.add_instance_details(
                region=details['region'],
                instance_id=instance_id,
                key='instance_elb_names',
                value=instance_elb_names,
            )
        hash_key, status = redis_handler.save_elb_details(details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "ELB sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 3
0
def sync_ec2_instances(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        instance_list = ec2_handler.fetch_all_instances()
    except Exception as e:
        print "Exception for EC2 in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for instance in instance_list:
        instance_details = ec2_handler.get_instance_details(instance)
        instance_details['timestamp'] = int(time.time())
        hash_key, status = redis_handler.save_instance_details(instance_details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Instance sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 4
0
def sync_elastic_ips(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        elastic_ip_list = ec2_handler.fetch_elastic_ips()
    except Exception as e:
        print "Exception for Elastic IPs in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for elastic_ip in elastic_ip_list:
        details = ec2_handler.get_elastic_ip_detail(elastic_ip)
        details['timestamp'] = int(time.time())
        hash_key, status = redis_handler.save_elastic_ip_details(details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Elastic ip sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 5
0
def sync_elastic_ips(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        elastic_ip_list = ec2_handler.fetch_elastic_ips()
    except Exception as e:
        print "Exception for Elastic IPs in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for elastic_ip in elastic_ip_list:
        details = ec2_handler.get_elastic_ip_detail(elastic_ip)
        details['timestamp'] = int(time.time())
        hash_key, status = redis_handler.save_elastic_ip_details(details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Elastic ip sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 6
0
def sync_ec2_instances(redis_handler, ec2_handler, expire):
    global index_keys
    try:
        instance_list = ec2_handler.fetch_all_instances()
    except Exception as e:
        print "Exception for EC2 in Region: %s, message: %s" \
              % (ec2_handler.region, e.message)
        return
    for instance in instance_list:
        instance_details = ec2_handler.get_instance_details(instance)
        instance_details['timestamp'] = int(time.time())
        hash_key, status = redis_handler.save_instance_details(
            instance_details)
        index_keys.append(hash_key)
        if expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Instance sync complete for ec2 region: %s" % ec2_handler.region
Ejemplo n.º 7
0
def sync_route53_zone(route53_handler, redis_handler, zone_name, zone_id,
                      expire, ttl):
    try:
        record_sets = route53_handler.fetch_all_route53dns_rsets(zone_id)
    except Exception as e:
        print "Exception for Route53 Zone: %s, message: %s" % (zone_name,
                                                               e.message)
        return
    for record in record_sets:
        item_details = {}
        item_details['name'] = record.name
        item_details['ttl'] = record.ttl
        item_details['type'] = record.type
        item_details['value'] = record.to_print()
        item_details['timestamp'] = int(time.time())
        if record.alias_dns_name is not None:
            item_details['type'] = '%s (Alias)' % record.type
            item_details['value'] = record.alias_dns_name
        hash_key, status = redis_handler.save_route53_details(item_details)
        index_keys.append(hash_key)
        if ttl:
            try:
                redis_handler.expire(hash_key, int(item_details['ttl']))
            except ValueError:
                redis_handler.expire(hash_key, expire)
        elif expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Sync complete for Route53 zone: %s" % zone_name
Ejemplo n.º 8
0
def sync_route53_zone(route53_handler, redis_handler, zone_name, zone_id,
                      expire, ttl):
    try:
        record_sets = route53_handler.fetch_all_route53dns_rsets(zone_id)
    except Exception as e:
        print "Exception for Route53 Zone: %s, message: %s" % (zone_name,
                                                               e.message)
        return
    for record in record_sets:
        item_details = {}
        item_details['name'] = record.name
        item_details['ttl'] = record.ttl
        item_details['type'] = record.type
        item_details['value'] = record.to_print()
        item_details['timestamp'] = int(time.time())
        if record.alias_dns_name is not None:
            item_details['type'] = '%s (Alias)' % record.type
            item_details['value'] = record.alias_dns_name
        hash_key, status = redis_handler.save_route53_details(item_details)
        index_keys.append(hash_key)
        if ttl:
            try:
                redis_handler.expire(hash_key, int(item_details['ttl']))
            except ValueError:
                redis_handler.expire(hash_key, expire)
        elif expire > 0:
            redis_handler.expire(hash_key, expire)
    print "Sync complete for Route53 zone: %s" % zone_name