Ejemplo n.º 1
0
    def resolve_security_groups(self):
        filters = {}
        self.log.info("Resolving security groups")
        
        # If the server is being spun up in a vpc, search only that vpc
        exists = lambda s: s in [group.name for group in
                                 self.ec2.get_all_security_groups()
                                 if self.vpc_id == group.vpc_id]

        for index, group in enumerate(self.security_groups):
            
            if not exists(group):
                self.log.info('Security Group {group} does not exist'.format(
                                group=group))
                if self.subnet_id is None:
                    self.ec2.create_security_group(group, group)
                else:
                    vpc_conn = VPCConnection()
                    vpc_conn.create_security_group(
                        group, group, vpc_id=self.vpc_id)
                self.log.info('Created security group {group}'.format(
                                group=group))
            else:
                self.log.info('Security Group {group} already exists'.format(
                                group=group))
Ejemplo n.º 2
0
    def resolve_security_groups(self):
        self.log.info("Resolving security groups")

        # If the server is being spun up in a vpc, search only that vpc
        exists = lambda s: s in [
            group.name for group in self.ec2.get_all_security_groups()
            if self.vpc_id == group.vpc_id
        ]

        for index, group in enumerate(self.security_groups):

            if not exists(group):
                self.log.info('Security Group {group} does not exist'.format(
                    group=group))
                if self.subnet_id is None:
                    self.ec2.create_security_group(group, group)
                else:
                    vpc_conn = VPCConnection()
                    vpc_conn.create_security_group(group,
                                                   group,
                                                   vpc_id=self.vpc_id)
                self.log.info(
                    'Created security group {group}'.format(group=group))
            else:
                self.log.info('Security Group {group} already exists'.format(
                    group=group))
Ejemplo n.º 3
0
print ("created vpc", private_cloud.id)

private_subnet = connection.create_subnet(private_cloud.id, green_subnet)
time.sleep(2) #fix race condition later
private_subnet.add_tag('Name', 'green_subnet')
public_subnet = connection.create_subnet(private_cloud.id, blue_subnet)
time.sleep(2)
public_subnet.add_tag('Name', 'blue_subnet')
print "created public and private subnets"

igw = connection.create_internet_gateway()
connection.attach_internet_gateway(igw.id, private_cloud.id)

print "created and attached internet gateway"

host_security_group = connection.create_security_group('private_cloud_sg', 'private_cloud_sg', private_cloud.id)
host_security_group.authorize('tcp', 80, 80, '0.0.0.0/0')
host_security_group.authorize('tcp', 22, 22, '0.0.0.0/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)
Ejemplo n.º 4
0
private_subnet = connection.create_subnet(private_cloud.id, green_subnet)
time.sleep(2)  #fix race condition later
private_subnet.add_tag('Name', 'green_subnet')
public_subnet = connection.create_subnet(private_cloud.id, blue_subnet)
time.sleep(2)
public_subnet.add_tag('Name', 'blue_subnet')
print "created public and private subnets"

igw = connection.create_internet_gateway()
connection.attach_internet_gateway(igw.id, private_cloud.id)

print "created and attached internet gateway"

host_security_group = connection.create_security_group('private_cloud_sg',
                                                       'private_cloud_sg',
                                                       private_cloud.id)
host_security_group.authorize('tcp', 80, 80, '0.0.0.0/0')
host_security_group.authorize('tcp', 22, 22, '0.0.0.0/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,