Exemple #1
0
def generate_eip_map_by_tagged_instances(prefix,dryrun ):
    c = InstanceController( dryrun=dryrun, region='us-east-1', aws_access_key_id = aws_access_key_id, aws_secret_access_key =aws_secret_access_key)
    # Find all the instances
    n=1;
    s = c.get_tagged_instances( tag= prefix+"*" )
    addresses = c.get_all_addresses()
    clause=['"none":   { "ip": "",      "eip": "none" }']
    for i in s:
        for addr in addresses:
            if i.ip_address == addr.public_ip:
                try:
                    if i.tags["Role"] == "worker":
                        name = "worker{0}".format(n)
                        n=n+1
                    elif i.tags["Role"] == "mysql":
                        name = "db"
                    else:
                        name =  i.tags["Role"]
                    clause.append('\n"%s": { "ip":"%s", "eip":"%s" }' % ( name, addr.public_ip, addr.allocation_id))
                except:
                    name = i.tags["Name"]
                    clause.append('\n"%s": { "ip":"%s", "eip":"%s" }' % ( name, addr.public_ip, addr.allocation_id))
    print('"ElasticIp": {')
    print( ",".join(clause))
    print('} ')
Exemple #2
0
def generate_eip_map_by_tagged_instances(prefix, dryrun):
    c = InstanceController(dryrun=dryrun,
                           region='us-east-1',
                           aws_access_key_id=aws_access_key_id,
                           aws_secret_access_key=aws_secret_access_key)
    # Find all the instances
    n = 1
    s = c.get_tagged_instances(tag=prefix + "*")
    addresses = c.get_all_addresses()
    clause = ['"none":   { "ip": "",      "eip": "none" }']
    for i in s:
        for addr in addresses:
            if i.ip_address == addr.public_ip:
                try:
                    if i.tags["Role"] == "worker":
                        name = "worker{0}".format(n)
                        n = n + 1
                    elif i.tags["Role"] == "mysql":
                        name = "db"
                    else:
                        name = i.tags["Role"]
                    clause.append('\n"%s": { "ip":"%s", "eip":"%s" }' %
                                  (name, addr.public_ip, addr.allocation_id))
                except:
                    name = i.tags["Name"]
                    clause.append('\n"%s": { "ip":"%s", "eip":"%s" }' %
                                  (name, addr.public_ip, addr.allocation_id))
    print('"ElasticIp": {')
    print(",".join(clause))
    print('} ')
Exemple #3
0
def disassociate_tagged_instances(prefix, dryrun):
    c = InstanceController(dryrun=dryrun,
                           region='us-east-1',
                           aws_access_key_id=aws_access_key_id,
                           aws_secret_access_key=aws_secret_access_key)
    # Find all the instances
    mm = re.compile("build")
    s = c.get_tagged_instances(tag=prefix + "*")
    for i in s:
        if mm.search(i.tags["Name"]):
            logger.debug("ignore " + i.tags["Name"])
            s.remove(i)
        else:
            logger.debug("Remove EIP from " + i.tags["Name"])
    now = datetime.now()
    dt = datetime.strftime(now, "%b%d")
    logger.info("Retag old cluster with prefix " + "Remove_" + dt + "_")
    if dryrun:
        for i in s:
            logger.debug("Dryrun: retag old cluster " + "Remove_" + dt + "_" +
                         i.tags["Name"])
    else:
        c.append_tag_instances(s, "Name", "Remove_" + dt + "_")
    logger.info("Remove eip association and stop instance")
    if not dryrun:
        c.remove_instance_by_tagging(s, "remove")
Exemple #4
0
def disassociate_tagged_instances(prefix, dryrun):
    c = InstanceController( dryrun=dryrun, region='us-east-1',aws_access_key_id =  aws_access_key_id , aws_secret_access_key =aws_secret_access_key)
    # Find all the instances
    mm = re.compile("build")
    s = c.get_tagged_instances( tag= prefix+"*" )
    for i in s:
        if mm.search(i.tags["Name"]):
             logger.debug("ignore "+ i.tags["Name"])
             s.remove(i)
        else:
             logger.debug("Remove EIP from "+ i.tags["Name"])
    now = datetime.now()
    dt = datetime.strftime( now, "%b%d")
    logger.info("Retag old cluster with prefix "+ "Remove_"+dt+"_")
    if dryrun:
        for i in s:
            logger.debug("Dryrun: retag old cluster "+ "Remove_"+dt+"_"+i.tags["Name"])
    else:
        c.append_tag_instances( s, "Name", "Remove_"+dt+"_")
    logger.info("Remove eip association and stop instance")
    if not dryrun:
        c.remove_instance_by_tagging( s, "remove" )