def create_resources(self): # Create Dynamo and user dynamo_allocator = DynamoAllocator() self.create_table() dynamo_table = dynamo_allocator.table('Autobahn') ec2_client = EC2Allocator().client('eu-west-1') vpc_response = ec2_client.create_vpc(CidrBlock='10.1.0.0/24', AmazonProvidedIpv6CidrBlock=False, DryRun=False, InstanceTenancy='default') self.vpc_id = vpc_response['Vpc']['VpcId'] ec2_client.create_tags(DryRun=False, Resources=[self.vpc_id], Tags=[{ 'Key': 'Name', 'Value': "vpc-test" }]) acl_response = ec2_client.create_network_acl(DryRun=False, VpcId=self.vpc_id) self.acl_id = acl_response['NetworkAcl']['NetworkAclId'] entry_response = ec2_client.create_network_acl_entry( CidrBlock='244.244.244.244/32', DryRun=False, Egress=False, NetworkAclId=self.acl_id, Protocol='-1', RuleAction='deny', RuleNumber=77) return self.vpc_id, self.acl_id
def tearDown(self): # Create Dynamo and user dynamo_allocator = DynamoAllocator() dynamo_table = dynamo_allocator.table('Autobahn') ec2_client = EC2Allocator().client('eu-west-1') try: acl_response = ec2_client.delete_network_acl( DryRun=False, NetworkAclId=self.acl_id) except: pass
def create_resources(self): # Create Dynamo and user dynamo_allocator = DynamoAllocator() dynamo_resource = dynamo_allocator.resource() self.create_table() dynamo_table = dynamo_allocator.table('Autobahn') ec2_client = EC2Allocator().client('eu-west-1') vpc_response = ec2_client.create_vpc(CidrBlock='10.1.0.0/24', AmazonProvidedIpv6CidrBlock=False, DryRun=False, InstanceTenancy='default') self.vpc_id = vpc_response['Vpc']['VpcId'] ec2_client.create_tags(DryRun=False, Resources=[self.vpc_id], Tags=[{ 'Key': 'Name', 'Value': "vpc-test" }]) acl_response = ec2_client.create_network_acl(DryRun=False, VpcId=self.vpc_id) self.acl_id = acl_response['NetworkAcl']['NetworkAclId'] entry_response = ec2_client.create_network_acl_entry( CidrBlock='244.244.244.244/32', DryRun=False, Egress=False, NetworkAclId=self.acl_id, Protocol='-1', RuleAction='deny', RuleNumber=77) struct_time = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M") epoch = UTC_time_to_epoch(struct_time) table = dynamo_resource.Table('Autobahn') table.put_item( Item={ 'ip': '244.244.244.244', 'last_seen': epoch - 99100, 'times_seen': 1, 'banned': True }) return self.vpc_id, self.acl_id
def create_resources(self): # Create Dynamo and user dynamo_allocator = DynamoAllocator() self.create_table() dynamo_table = dynamo_allocator.table('Autobahn') ec2_client = EC2Allocator().client('eu-west-1') vpc_response = ec2_client.create_vpc(CidrBlock='10.1.0.0/24', AmazonProvidedIpv6CidrBlock=False, DryRun=False, InstanceTenancy='default') self.vpc_id = vpc_response['Vpc']['VpcId'] nacls = ec2_client.describe_network_acls( Filters=[{ 'Name': 'vpc-id', 'Values': [self.vpc_id] }]) for nacl in nacls['NetworkAcls']: try: ec2_client.delete_network_acl( DryRun=False, NetworkAclId=nacl['NetworkAclId']) except: pass acl_response = ec2_client.create_network_acl(DryRun=False, VpcId=self.vpc_id) self.acl_id = acl_response['NetworkAcl']['NetworkAclId'] entry_response = ec2_client.create_network_acl_entry( CidrBlock='244.244.244.244/32', DryRun=False, Egress=False, NetworkAclId=self.acl_id, Protocol='-1', RuleAction='deny', RuleNumber=77) return self.vpc_id