Best Python code snippet using localstack_python
redshift.py
Source:redshift.py
1from asyncio import Lock2from botocore.utils import ClientError3from wpaudit.core.console import print_exception4from wpaudit.providers.aws.facade.basefacade import AWSBaseFacade5from wpaudit.providers.aws.facade.utils import AWSFacadeUtils6from wpaudit.providers.aws.utils import ec2_classic7class RedshiftFacade(AWSBaseFacade):8 regional_cluster_cache_locks = {}9 clusters_cache = {}10 async def get_clusters(self, region: str, vpc: str):11 try:12 await self.cache_clusters(region)13 return [cluster for cluster in self.clusters_cache[region] if cluster['VpcId'] == vpc]14 except Exception as e:15 print_exception(f'Failed to get Redshift clusters: {e}')16 return []17 async def cache_clusters(self, region):18 async with self.regional_cluster_cache_locks.setdefault(region, Lock()):19 if region in self.clusters_cache:20 return21 self.clusters_cache[region] = await AWSFacadeUtils.get_all_pages(22 'redshift', region, self.session, 'describe_clusters', 'Clusters')23 for cluster in self.clusters_cache[region]:24 cluster['VpcId'] = \25 cluster['VpcId'] if 'VpcId' in cluster and cluster['VpcId'] else ec2_classic26 async def get_cluster_parameter_groups(self, region: str):27 try:28 return await AWSFacadeUtils.get_all_pages(29 'redshift', region, self.session, 'describe_cluster_parameter_groups', 'ParameterGroups')30 except Exception as e:31 print_exception(f'Failed to get Redshift parameter groups: {e}')32 return []33 async def get_cluster_security_groups(self, region: str):34 # For VPC-by-default customers, describe_cluster_parameters will throw an exception. Just try and ignore it:35 try:36 return await AWSFacadeUtils.get_all_pages(37 'redshift', region, self.session, 'describe_cluster_security_groups', 'ClusterSecurityGroups')38 except ClientError as e:39 if e.response['Error']['Code'] != 'InvalidParameterValue':40 print_exception(f'Failed to describe cluster security groups: {e}')41 return []42 async def get_cluster_parameters(self, region: str, parameter_group: str):43 return await AWSFacadeUtils.get_all_pages(44 'redshift', region, self.session, 'describe_cluster_parameters', 'Parameters',...
resources.py
Source:resources.py
1from conftest import botocore_client2def redshift_clusters():3 "botocore.readthedocs.io/en/latest/reference/services/redshift.html#Redshift.Client.describe_clusters"4 return (5 botocore_client.get("redshift", "describe_clusters", [], {})6 .extract_key("Clusters")7 .flatten()8 .values()9 )10def redshift_cluster_security_groups():11 "http://botocore.readthedocs.io/en/latest/reference/services/redshift.html#Redshift.Client.describe_cluster_security_groups" # NOQA12 return (13 botocore_client.get(14 "redshift",15 "describe_cluster_security_groups",16 [],17 {},18 result_from_error=lambda error, call: {"ClusterSecurityGroups": []},19 )20 .extract_key("ClusterSecurityGroups")21 .flatten()22 .values()...
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!!