Exemple #1
0
def create_nat_instance(ami_id, key_name, instance_type, security_group_ids,
                        subnet_id, private_ip_address, tag_name=None):
    logger = logging.getLogger(__name__)
    try:
        logger.debug("create EC2 connection")
        c = get_ec2_connection()
        reservation = c.run_instances(ami_id,
                                      key_name=key_name,
                                      instance_type=instance_type,
                                      security_group_ids=security_group_ids,
                                      subnet_id=subnet_id,
                                      private_ip_address=private_ip_address)
        instance_id = reservation.instances[0].id
        logger.info("NAT instance id is : %s" % instance_id)
        logger.debug("set sourceDestCheck false")
        c.modify_instance_attribute(instance_id,
                                    "sourceDestCheck",
                                    False)
        if tag_name is not None:
            logger.info("create tag Name : %s" % tag_name)
            c.create_tags(instance_id,
                          tags={"Name": "nat_testing"})
        logger.debug("close EC2 connection")
        c.close()
        return instance_id
    except Exception, e:
        logger.error(e)
Exemple #2
0
def old_associate_new_eip_to_nat(nat_id):
    logger = logging.getLogger(__name__)
    try:
        logger.debug("create EC2 connection")
        c = get_ec2_connection()
        logger.info("allocate new EIP")
        eip = c.allocate_address()
        logger.info("EIP : %s" % eip.public_ip)
        logger.info("associate this EIP to NAT %s" % nat_id)
        result = eip.associate(nat_id)
        logger.debug("close EC2 connection")
        c.close()
        return result
    except Exception, e:
        logger.error(e)