예제 #1
0
class DiscoEIP(object):
    """
    A simple class to manage EIP's
    """
    def __init__(self):
        self.vpc_conn = VPCConnection()

    def list(self):
        """Returns all of our currently allocated EIPs"""
        return self.vpc_conn.get_all_addresses()

    def allocate(self):
        """Allocates a new VPC EIP"""
        return self.vpc_conn.allocate_address(domain='vpc')

    def release(self, eip_address, force=False):
        """
        Releases an EIP.

        If it is currently associated with a machine we do not release it unless
        the force param is set.
        """
        eip = self.vpc_conn.get_all_addresses([eip_address])[0]

        if eip.association_id:
            if force:
                eip.disassociate()
            else:
                return False

        return eip.release()
예제 #2
0
class DiscoEIP(object):
    """
    A simple class to manage EIP's
    """

    def __init__(self):
        self.vpc_conn = VPCConnection()

    def list(self):
        """Returns all of our currently allocated EIPs"""
        return self.vpc_conn.get_all_addresses()

    def allocate(self):
        """Allocates a new VPC EIP"""
        return self.vpc_conn.allocate_address(domain='vpc')

    def release(self, eip_address, force=False):
        """
        Releases an EIP.

        If it is currently associated with a machine we do not release it unless
        the force param is set.
        """
        eip = self.vpc_conn.get_all_addresses([eip_address])[0]

        if eip.association_id:
            if force:
                eip.disassociate()
            else:
                return False

        return eip.release()
예제 #3
0
class DiscoEIP(object):
    """
    A simple class to manage EIP's
    """
    def __init__(self):
        self.vpc_conn = VPCConnection()
        self.ec2_conn = boto3.client('ec2')

    def list(self):
        """Returns all of our currently allocated EIPs"""
        return self.vpc_conn.get_all_addresses()

    def allocate(self):
        """Allocates a new VPC EIP"""
        return self.vpc_conn.allocate_address(domain='vpc')

    def tag_dynamic(self, eip_allocation_id):
        """
        Tag an EIP as dynamic
        "Tags": [
            {
                "Key": "dynamic",
                "Value": "true"
            }
        ]
        """
        return throttled_call(self.ec2_conn.create_tags,
                              Resources=[eip_allocation_id],
                              Tags=[{
                                  'Key': 'dynamic',
                                  'Value': 'true'
                              }])

    def release(self, eip_address, force=False):
        """
        Releases an EIP.

        If it is currently associated with a machine we do not release it unless
        the force param is set.
        """
        eip = self.vpc_conn.get_all_addresses([eip_address])[0]

        if eip.association_id:
            if force:
                eip.disassociate()
            else:
                return False

        return eip.release()

    def find_eip_address(self, eip):
        """ Finds the EIP Address for the public eip specified. """
        address_filter = {'public-ip': eip}
        try:
            return self.vpc_conn.get_all_addresses(filters=address_filter)[0]
        except IndexError:
            return None
예제 #4
0
class DiscoEIP(object):
    """
    A simple class to manage EIP's
    """

    def __init__(self):
        self.vpc_conn = VPCConnection()
        self.ec2_conn = boto3.client('ec2')

    def list(self):
        """Returns all of our currently allocated EIPs"""
        return self.vpc_conn.get_all_addresses()

    def allocate(self):
        """Allocates a new VPC EIP"""
        return self.vpc_conn.allocate_address(domain='vpc')

    def tag_dynamic(self, eip_allocation_id):
        """
        Tag an EIP as dynamic
        "Tags": [
            {
                "Key": "dynamic",
                "Value": "true"
            }
        ]
        """
        return throttled_call(self.ec2_conn.create_tags, Resources=[eip_allocation_id],
                              Tags=[{'Key': 'dynamic', 'Value': 'true'}])

    def release(self, eip_address, force=False):
        """
        Releases an EIP.

        If it is currently associated with a machine we do not release it unless
        the force param is set.
        """
        eip = self.vpc_conn.get_all_addresses([eip_address])[0]

        if eip.association_id:
            if force:
                eip.disassociate()
            else:
                return False

        return eip.release()

    def find_eip_address(self, eip):
        """ Finds the EIP Address for the public eip specified. """
        address_filter = {'public-ip': eip}
        try:
            return self.vpc_conn.get_all_addresses(filters=address_filter)[0]
        except IndexError:
            return None
예제 #5
0
print "created security groups"

reservation = connection.run_instances(image_id=nat_linux_image, instance_type='t2.micro', key_name='kaihon', subnet_id=public_subnet.id, security_group_ids=[host_security_group.id])
instance = reservation.instances[0]

connection.modify_instance_attribute(instance.id, attribute='sourceDestCheck', value=False)

print "modified instance to ignore source and destination checks"

## the following does not work
while instance.state == 'pending':
	time.sleep(5)
	instance.update()

instance.add_tag('Name', 'Nat-Instance')

public_route_table	= connection.create_route_table(private_cloud.id)
print "created public route table"
private_route_table = connection.create_route_table(private_cloud.id)
print "created private route table"

connection.create_route(public_route_table.id, '0.0.0.0/0', igw.id, None, None, None, False)
connection.create_route(private_route_table.id, '0.0.0.0/0', None, instance.id, None, None, False)

connection.associate_route_table(private_route_table.id, private_subnet.id)
connection.associate_route_table(public_route_table.id, public_subnet.id)

elastic_ip = connection.allocate_address(domain=None, dry_run=False)
elastic_ip.associate(instance_id=instance.id, network_interface_id=None, private_ip_address=None, allow_reassociation=False, dry_run=False)

예제 #6
0
                                     value=False)

print "modified instance to ignore source and destination checks"

## the following does not work
while instance.state == 'pending':
    time.sleep(5)
    instance.update()

instance.add_tag('Name', 'Nat-Instance')

public_route_table = connection.create_route_table(private_cloud.id)
print "created public route table"
private_route_table = connection.create_route_table(private_cloud.id)
print "created private route table"

connection.create_route(public_route_table.id, '0.0.0.0/0', igw.id, None, None,
                        None, False)
connection.create_route(private_route_table.id, '0.0.0.0/0', None, instance.id,
                        None, None, False)

connection.associate_route_table(private_route_table.id, private_subnet.id)
connection.associate_route_table(public_route_table.id, public_subnet.id)

elastic_ip = connection.allocate_address(domain=None, dry_run=False)
elastic_ip.associate(instance_id=instance.id,
                     network_interface_id=None,
                     private_ip_address=None,
                     allow_reassociation=False,
                     dry_run=False)