How to use _attach_gateway method in localstack

Best Python code snippet using localstack_python

ec2.py

Source:ec2.py Github

copy

Full Screen

...172 result = "%s-%s" % (gw_id, attachment.get("VpcId"))173 return result174 @classmethod175 def get_deploy_templates(cls):176 def _attach_gateway(resource_id, resources, *args, **kwargs):177 client = aws_stack.connect_to_service("ec2")178 resource = cls(resources[resource_id])179 props = resource.props180 igw_id = props.get("InternetGatewayId")181 vpngw_id = props.get("VpnGatewayId")182 vpc_id = props.get("VpcId")183 if igw_id:184 client.attach_internet_gateway(VpcId=vpc_id, InternetGatewayId=igw_id)185 elif vpngw_id:186 client.attach_vpn_gateway(VpcId=vpc_id, VpnGatewayId=vpngw_id)187 return {"create": {"function": _attach_gateway}}188class SecurityGroup(GenericBaseModel):189 @staticmethod190 def cloudformation_type():...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

1#2# Copyright (C) 2015 Lance Linder3#4import re5import troposphere6import troposphere.ec27import troposphere_ext8import collections9import yaml10from troposphere import Ref, Join, Base6411from troposphere.ec2 import SubnetRouteTableAssociation12from troposphere.ec2 import SubnetNetworkAclAssociation13class VPC(troposphere.ec2.VPC):14 def __init__(self, title, template=None, **kwargs):15 helper_keys = ['NetworkAclEntries', 'NetworkAcls',16 'Subnets', 'AttachGateway', 'RouteTables',17 'SecurityGroups']18 clean_kwargs = {k: v for k, v in kwargs.iteritems()19 if k not in helper_keys}20 self._network_acl_entries = kwargs.get('NetworkAclEntries', [])21 self._network_acls = kwargs.get('NetworkAcls', [])22 self._subnets = kwargs.get('Subnets', [])23 self._attach_gateway = kwargs.get('AttachGateway')24 self._route_tables = kwargs.get('RouteTables', [])25 self._security_groups = kwargs.get('SecurityGroups', [])26 super(VPC, self).__init__(title, template, **clean_kwargs)27 if template is not None:28 # gatey attachment29 if self._attach_gateway is not None:30 attachment = self._attach_gateway31 attachment.title = '{}{}'.format(self.title, attachment.title)32 attachment.VpcId = troposphere.Ref(self)33 template._register_resource(attachment)34 # network ACLs35 for acl in self._network_acls:36 acl.title = '{}{}'.format(self.title, acl.title)37 acl.VpcId = troposphere.Ref(self)38 # network ACL entries39 for entry in acl.network_acl_entries:40 entry.title = '{}{}'.format(acl.title, entry.title)41 entry.NetworkAclId = troposphere.Ref(acl)42 template._register_resource(entry)43 template._register_resource(acl)44 # route tables45 for route_table in self._route_tables:46 route_table.title = '{}{}'.format(self.title,47 route_table.title)48 route_table.VpcId = Ref(self)49 # routes50 for route in route_table.routes:51 route.title = '{}{}'.format(route_table.title,52 route.title)53 route.RouteTableId = Ref(route_table)54 template._register_resource(route)55 template._register_resource(route_table)56 # subnets57 for subnet in self._subnets:58 subnet.title = '{}{}'.format(self.title, subnet.title)59 subnet.VpcId = Ref(self)60 # route table associations61 for route_table in subnet.route_tables:62 route_table_assoc = SubnetRouteTableAssociation(63 '{}{}Assoc'.format(subnet.title,64 route_table.get_ref().title),65 SubnetId=Ref(subnet),66 RouteTableId=route_table)67 template._register_resource(route_table_assoc)68 # network ACL associations69 for acl in subnet.network_acls:70 network_acl_assoc = SubnetNetworkAclAssociation(71 '{}{}Assoc'.format(subnet.title, acl.get_ref().title),72 SubnetId=troposphere.Ref(subnet),73 NetworkAclId=acl)74 template._register_resource(network_acl_assoc)75 template._register_resource(subnet)76 # security groups77 for security_group in self._security_groups:78 security_group.VpcId = troposphere.Ref(self)79 template._register_resource(security_group)80 @property81 def network_acl_entries(self):82 return self._network_acl_entries83 @property84 def network_acls(self):85 return self._network_acls86 @property87 def subnets(self):88 return self._subnets89 @property90 def attach_gateway(self):91 return self._attach_gateway92 @property93 def route_table(self):94 return self._route_table95 @property96 def security_groups(self):97 return self._security_groups98class RouteTable(troposphere.ec2.RouteTable):99 def __init__(self, title, template=None, **kwargs):100 helper_keys = ['Routes']101 clean_kwargs = {k: v for k, v in kwargs.iteritems()102 if k not in helper_keys}103 self._routes = kwargs.get('Routes', [])104 super(RouteTable, self).__init__(title, template, **clean_kwargs)105 @property106 def routes(self):107 return self._routes108class Route(troposphere.ec2.Route):109 def JSONrepr(self):110 depends_on = self.resource.get('DependsOn')111 if isinstance(depends_on, troposphere_ext.TRef):112 self.resource['DependsOn'] = depends_on.get_ref().title113 return super(Route, self).JSONrepr()114class Subnet(troposphere.ec2.Subnet):115 def __init__(self, title, template=None, **kwargs):116 helper_keys = ['NetworkAcls', 'RouteTables']117 clean_kwargs = {k: v for k, v in kwargs.iteritems()118 if k not in helper_keys}119 self._network_acls = kwargs.get('NetworkAcls', [])120 self._route_tables = kwargs.get('RouteTables', [])121 super(Subnet, self).__init__(title, template, **clean_kwargs)122 @property123 def network_acls(self):124 return self._network_acls125 @property126 def route_tables(self):127 return self._route_tables128class NetworkAcl(troposphere.ec2.NetworkAcl):129 def __init__(self, title, template=None, **kwargs):130 helper_keys = ['NetworkAclEntries']131 clean_kwargs = {k: v for k, v in kwargs.iteritems()132 if k not in helper_keys}133 self._network_acl_entries = kwargs.get('NetworkAclEntries', [])134 super(NetworkAcl, self).__init__(title, template, **clean_kwargs)135 @property136 def network_acl_entries(self):137 return self._network_acl_entries138class CloudConfig(troposphere.AWSHelperFn):139 def __init__(self, config):140 self.config = config141 def JSONrepr(self):142 result = yaml.dump(self.config, default_flow_style=False)143 result = '#cloud-config\n' + result144 return Base64(result)145class UserData(troposphere.AWSHelperFn):146 def __init__(self, *args):147 self.data = args148 def _strip_margin(self, value):149 return re.sub('\n[ \t]*\|', '\n', value)150 def JSONrepr(self):151 # flatten array152 data = [x for y in self.data153 for x in (y if isinstance(y, list) else [y])]154 # strip margin from the strings155 data = [self._strip_margin(v) if isinstance(v, str) else v156 for v in data]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful