Best Python code snippet using localstack_python
getecsip.py
Source:getecsip.py
...82 describe_network_interfaces_request = ecs_20140526_models.DescribeNetworkInterfacesRequest(83 region_id='ap-southeast-1',84 instance_id=ecsidlist1[i]85 )86 client.describe_network_interfaces(describe_network_interfaces_request)87 data = client.describe_network_interfaces(describe_network_interfaces_request)88 with open('eiplist1.json', 'w') as f:89 print(data, file=f)90 data_dict = read_file('eiplist1.json')91 parse_data(data_dict, 'ecsiplist1.txt')92 @staticmethod93 async def main_async(94 args: List[str],95 ) -> None:96 client = aliclient.create_client('accessKeyId', 'accessKeySecret')97 for i in range(len(ecsidlist1)):98 describe_network_interfaces_request = ecs_20140526_models.DescribeNetworkInterfacesRequest(99 region_id='ap-southeast-1',100 instance_id=ecsidlist1[i]101 )102 client.describe_network_interfaces(describe_network_interfaces_request)103 data = client.describe_network_interfaces(describe_network_interfaces_request)104 with open('eiplist1.json', 'w') as f:105 print(data, file=f)106 data_dict = read_file('eiplist1.json')107 parse_data(data_dict, 'ecsiplist1.txt')108 await client.describe_network_interfaces_async(describe_network_interfaces_request)109class proxies2:110 def __init__(self):111 pass112 @staticmethod113 def main(114 args: List[str],115 ) -> None:116 client = aliclient.create_client('accessKeyId', 'accessKeySecret')117 for i in range(len(ecsidlist2)):118 describe_network_interfaces_request = ecs_20140526_models.DescribeNetworkInterfacesRequest(119 region_id='ap-southeast-1',120 instance_id=ecsidlist2[i]121 )122 client.describe_network_interfaces(describe_network_interfaces_request)123 data = client.describe_network_interfaces(describe_network_interfaces_request)124 with open('plist2.json', 'w') as f:125 print(data, file=f)126 data_dict = read_file('eiplist2.json')127 parse_data(data_dict, 'ecsiplist2.txt')128 @staticmethod129 async def main_async(130 args: List[str],131 ) -> None:132 client = aliclient.create_client('accessKeyId', 'accessKeySecret')133 for i in range(len(ecsidlist2)):134 describe_network_interfaces_request = ecs_20140526_models.DescribeNetworkInterfacesRequest(135 region_id='ap-southeast-1',136 instance_id=ecsidlist2[i]137 )138 client.describe_network_interfaces(describe_network_interfaces_request)139 data = client.describe_network_interfaces(describe_network_interfaces_request)140 with open('eiplist2.json', 'w') as f:141 print(data, file=f)142 data_dict = read_file('eiplist2.json')143 parse_data(data_dict, 'ecsiplist2.txt')144 await client.describe_network_interfaces_async(describe_network_interfaces_request)145if __name__ == '__main__':146 truncatefiles()147 proxies1.main(sys.argv[1:])148 proxies2.main(sys.argv[1:])149 clearoldiplist()150 writeiptoredis1()...
test_ec2_network_interfaces.py
Source:test_ec2_network_interfaces.py
1import cartography.intel.aws.ec22import tests.data.aws.ec2.network_interfaces3TEST_ACCOUNT_ID = '000000000000'4TEST_REGION = 'eu-north-1'5TEST_UPDATE_TAG = 1234567896def test_load_network_interfaces(neo4j_session):7 data = tests.data.aws.ec2.network_interfaces.DESCRIBE_NETWORK_INTERFACES8 cartography.intel.aws.ec2.network_interfaces.load(9 neo4j_session,10 data,11 TEST_REGION,12 TEST_ACCOUNT_ID,13 TEST_UPDATE_TAG,14 )15 expected_nodes = {16 "eni-0e106a07c15ff7d14",17 "eni-0d9877f559c240362",18 "eni-04b4289e1be7634e4",19 }20 nodes = neo4j_session.run(21 """22 MATCH (ni:NetworkInterface) RETURN ni.id;23 """,24 )25 actual_nodes = {n['ni.id'] for n in nodes}26 assert actual_nodes == expected_nodes27def test_ec2_private_ips(neo4j_session):28 data = tests.data.aws.ec2.network_interfaces.DESCRIBE_NETWORK_INTERFACES29 cartography.intel.aws.ec2.network_interfaces.load(30 neo4j_session,31 data,32 TEST_REGION,33 TEST_ACCOUNT_ID,34 TEST_UPDATE_TAG,35 )36 expected_nodes = {37 "eni-0e106a07c15ff7d14:10.0.4.180",38 "eni-0d9877f559c240362:10.0.4.96",39 "eni-04b4289e1be7634e4:10.0.4.5",40 "eni-04b4289e1be7634e4:10.0.4.12",41 }42 nodes = neo4j_session.run(43 """44 MATCH (ni:EC2PrivateIp) RETURN ni.id;45 """,46 )47 actual_nodes = {n['ni.id'] for n in nodes}48 assert actual_nodes == expected_nodes49def test_network_interface_relationships(neo4j_session):50 data = tests.data.aws.ec2.network_interfaces.DESCRIBE_NETWORK_INTERFACES51 cartography.intel.aws.ec2.network_interfaces.load(52 neo4j_session,53 data,54 TEST_REGION,55 TEST_ACCOUNT_ID,56 TEST_UPDATE_TAG,57 )58 expected_nodes = {59 ('eni-0e106a07c15ff7d14', 'eni-0e106a07c15ff7d14:10.0.4.180'),60 ('eni-0d9877f559c240362', 'eni-0d9877f559c240362:10.0.4.96'),61 ('eni-04b4289e1be7634e4', 'eni-04b4289e1be7634e4:10.0.4.5'),62 ('eni-04b4289e1be7634e4', 'eni-04b4289e1be7634e4:10.0.4.12'),63 }64 # Fetch relationships65 result = neo4j_session.run(66 """67 MATCH (n1:NetworkInterface)-[:PRIVATE_IP_ADDRESS]->(n2:EC2PrivateIp) RETURN n1.id, n2.id;68 """,69 )70 actual = {71 (r['n1.id'], r['n2.id']) for r in result72 }73 assert actual == expected_nodes74def test_network_interface_to_account(neo4j_session):75 neo4j_session.run('MERGE (:AWSAccount{id:{ACC_ID}})', ACC_ID=TEST_ACCOUNT_ID)76 data = tests.data.aws.ec2.network_interfaces.DESCRIBE_NETWORK_INTERFACES77 cartography.intel.aws.ec2.network_interfaces.load(78 neo4j_session,79 data,80 TEST_REGION,81 TEST_ACCOUNT_ID,82 TEST_UPDATE_TAG,83 )84 expected_nodes = {85 ('eni-0e106a07c15ff7d14', TEST_ACCOUNT_ID),86 ('eni-0d9877f559c240362', TEST_ACCOUNT_ID),87 ('eni-04b4289e1be7634e4', TEST_ACCOUNT_ID),88 ('eni-04b4289e1be7634e4', TEST_ACCOUNT_ID),89 }90 # Fetch relationships91 result = neo4j_session.run(92 """93 MATCH (n1:NetworkInterface)<-[:RESOURCE]-(n2:AWSAccount) RETURN n1.id, n2.id;94 """,95 )96 actual = {97 (r['n1.id'], r['n2.id']) for r in result98 }...
aws_collector.py
Source:aws_collector.py
...21 for eni in enis:22 for sg in eni['Groups']:23 enis_set.add(SecurityGroup(sg['GroupName'], sg['GroupId'], self.get_key()))24 def _get_network_interfaces_sgs(self)->set:25 # resp = self.client.describe_network_interfaces()26 enis_sgs = set()27 done, token = False, None28 try:29 while done == False:30 resp = self._token_handler(self.client.describe_network_interfaces,token)31 self._take_sgs_from_enis(enis_sgs, resp['NetworkInterfaces']) 32 if 'NextToken' in resp:33 token = resp['NextToken']34 else:35 done = True36 return enis_sgs37 except Exception as e:38 print(f"ParseAWSResponseError: Could not parse AWS describe_network_interfaces response into Rule Groups: {e}")39 raise ParseAWSResponseError(e)...
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!!