Best Python code snippet using localstack_python
orbit.py
Source: orbit.py
1import logging2from spacel.model.aws import VALID_REGIONS, INSTANCE_TYPES3logger = logging.getLogger('spacel.model.orbit')4NAT_CONFIGURATIONS = {5 'disabled', # No NAT, don't even try6 'enabled', # Single NAT gateway for every AZ (default)7 'per-az' # NAT gateway per AZ (suggested for production)8}9class Orbit(object):10 def __init__(self, name=None, regions=(), **kwargs):11 self.name = name12 self.regions = {}13 for region in regions:14 if region in VALID_REGIONS:15 self.regions[region] = OrbitRegion(self, region, **kwargs)16 continue17 logger.warning(18 'Orbit "%s" has invalid region "%s". Valid regions: %s',19 name, region, ', '.join(VALID_REGIONS))20 @property21 def valid(self):22 if not self.name or not self.regions:23 return False24 for orbit_region in self.regions.values():25 if not orbit_region.valid:26 return False27 return True28class OrbitRegion(object):29 def __init__(self,30 orbit,31 region,32 bastion_instance_count=1,33 bastion_instance_type='t2.nano',34 bastion_sources=('0.0.0.0/0',),35 deploy_stack=None,36 domain=None,37 parent_stack=None,38 nat='enabled',39 private_network='192.168',40 provider='spacel'):41 self.orbit = orbit42 self.region = region43 self.provider = provider44 # provider: spacel:45 self.bastion_instance_count = bastion_instance_count46 self.bastion_instance_type = bastion_instance_type47 self.bastion_sources = bastion_sources48 self.domain = domain49 self.nat = nat50 self.private_network = private_network51 # provider: GDH:52 self.deploy_stack = deploy_stack53 self.parent_stack = parent_stack54 # Queried from EC2:55 self._azs = {}56 # Output from VPC:57 self.vpc_id = None58 self.nat_eips = []59 self.private_cache_subnet_group = None60 self.private_rds_subnet_group = None61 self.public_rds_subnet_group = None62 self.spot_fleet_role = None63 self.bastion_eips = []64 self.bastion_sg = None65 @property66 def azs(self):67 return self._azs68 @property69 def az_keys(self):70 return sorted(self._azs.keys())71 @az_keys.setter72 def az_keys(self, value):73 self._azs = {az: OrbitRegionAz() for az in value}74 @property75 def private_elb_subnets(self):76 return [self._azs[az_key].private_elb_subnet77 for az_key in self.az_keys]78 @property79 def private_instance_subnets(self):80 return [self._azs[az_key].private_instance_subnet81 for az_key in self.az_keys]82 @property83 def public_elb_subnets(self):84 return [self._azs[az_key].public_elb_subnet85 for az_key in self.az_keys]86 @property87 def public_instance_subnets(self):88 return [self._azs[az_key].public_instance_subnet89 for az_key in self.az_keys]90 @property91 def private_nat_gateway(self):92 return self.nat != 'disabled'93 @property94 def nat_per_az(self):95 return self.nat == 'per-az'96 @property97 def valid(self):98 name = (self.orbit and self.orbit.name) or '(no name)'99 valid = True100 if self.provider == 'spacel':101 valid = valid and self._valid_spacel(name)102 elif self.provider == 'gdh':103 valid = valid and self._valid_gdh(name)104 else:105 logger.error('App "%s" has invalid "provider": %s', name,106 self.provider)107 valid = False108 return valid109 def _valid_spacel(self, name):110 valid = True111 if self.bastion_instance_type not in INSTANCE_TYPES:112 logger.error('App "%s" has invalid "bastion_instance_type": %s',113 name, self.provider)114 valid = False115 if self.nat not in NAT_CONFIGURATIONS:116 logger.error('App "%s" has invalid "nat": %s',117 name, self.provider)118 valid = False119 return valid120 def _valid_gdh(self, name):121 valid = True122 if not self.deploy_stack:123 logger.error('App "%s" is missing "deploy_stack".', name)124 valid = False125 if not self.parent_stack:126 logger.error('App "%s" is missing "parent_stack".', name)127 valid = False128 return valid129class OrbitRegionAz(object):130 def __init__(self,131 private_elb_subnet=None,132 private_instance_subnet=None,133 public_elb_subnet=None,134 public_instance_subnet=None):135 self.private_elb_subnet = private_elb_subnet136 self.private_instance_subnet = private_instance_subnet137 self.public_elb_subnet = public_elb_subnet...
deploy.py
Source: deploy.py
...23 formatted_secrets.append(24 {"ParameterKey": "StackName", "ParameterValue": STACK_NAME}25 )26 return formatted_secrets27def deploy_stack(session, secrets):28 """29 Deploy the stack using CloudFormation30 :param session: AWS boto3 session31 :param secrets: Stack secrets32 :return:33 """34 with open('scripts/cf_stack.yml') as template:35 template_data = template.read()36 try:37 cloudformation = session.client('cloudformation')38 stack = cloudformation.update_stack(39 StackName=STACK_NAME,40 TemplateBody=template_data,41 Parameters=secrets42 )43 print(stack)44 except ClientError as ex:45 error_message = ex.response['Error']['Message']46 if error_message.endswith('does not exist'):47 print('Stack does not exist, creating')48 stack = cloudformation.create_stack(49 StackName=STACK_NAME,50 TemplateBody=template_data,51 Parameters=secrets52 )53 print(stack)54 else:55 raise56if len(sys.argv) == 2:57 session = boto3.session.Session(58 profile_name=sys.argv[1]59 )60else:61 session = boto3.session.Session()62deploy_stack(63 session,64 get_secrets(session, 'drive/datatrust/dev')...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!