Best Python code snippet using localstack_python
elastic_network_interfaces.py
Source:elastic_network_interfaces.py
...89 private_ip_address = self._get_multi_param("PrivateIpAddress")90 eni = self.ec2_backend.unassign_private_ip_addresses(eni_id, private_ip_address)91 template = self.response_template(UNASSIGN_PRIVATE_IP_ADDRESSES)92 return template.render(eni=eni)93 def assign_ipv6_addresses(self):94 eni_id = self._get_param("NetworkInterfaceId")95 ipv6_count = self._get_int_param("Ipv6AddressCount", 0)96 ipv6_addresses = self._get_multi_param("Ipv6Addresses")97 eni = self.ec2_backend.assign_ipv6_addresses(98 eni_id, ipv6_addresses, ipv6_count,99 )100 template = self.response_template(ASSIGN_IPV6_ADDRESSES)101 return template.render(eni=eni)102 def unassign_ipv6_addresses(self):103 eni_id = self._get_param("NetworkInterfaceId")104 ips = self._get_multi_param("Ipv6Addresses")105 eni, unassigned_ips = self.ec2_backend.unassign_ipv6_addresses(eni_id, ips)106 template = self.response_template(UNASSIGN_IPV6_ADDRESSES)107 return template.render(eni=eni, unassigned_ips=unassigned_ips)108ASSIGN_PRIVATE_IP_ADDRESSES = """<AssignPrivateIpAddressesResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/">109 <requestId>3fb591ba-558c-48f8-ae6b-c2f9d6d06425</requestId>110 <networkInterfaceId>{{ eni.id }}</networkInterfaceId>111 <assignedPrivateIpAddressesSet>112 {% for address in eni.private_ip_addresses %}113 <item>114 <privateIpAddress>{{ address.PrivateIpAddress }}</privateIpAddress>115 </item>116 {% endfor %}117 </assignedPrivateIpAddressesSet>118 <return>true</return>119</AssignPrivateIpAddressesResponse>"""...
assign-secondary-ip.py
Source:assign-secondary-ip.py
...36 tprint("ENI of ipv6 not attached yet, no need to release")37 else:38 for j in response['NetworkInterfaces']:39 network_interface_id = j['NetworkInterfaceId']40 response = client.unassign_ipv6_addresses(41 Ipv6Addresses=ip6List,42 NetworkInterfaceId = network_interface_id43 )44 tprint("Finished releasing ip6List: " + str(ip6List)) 4546## This function, assigns/moves the list of secondary ipv4 addresses to the given ENI 47# The AllowReassignment flag = True , enables the force move of secondary ip addresses f=if they are assigned to soem other ENI 48# If there are any error, Exception is thrown which is handled in the main block. 49def assign_ip_to_nic(ipList,network_interface_id,client): 50 tprint("Going to reassign iplist: " + str(ipList) + " to ENI:" +network_interface_id ) 5152 response = client.assign_private_ip_addresses(53 AllowReassignment=True,54 NetworkInterfaceId=network_interface_id,55 PrivateIpAddresses = ipList 56 )57 58## This function, assigns the list of secondary ipv6 addresses to the given ENI 59# If there are any error, Exception is thrown which is handled in the main block 60def assign_ip6_to_nic(ip6List,network_interface_id,client): 61 tprint("Going to assign ip6List: " + str(ip6List) + " to ENI:" +network_interface_id ) 62 response = client.assign_ipv6_addresses(63 Ipv6Addresses=ip6List,64 NetworkInterfaceId=network_interface_id,65 )66## This function gets the metadata token67def get_metadata_token():68 token_url="http://169.254.169.254/latest/api/token"69 headers = {'X-aws-ec2-metadata-token-ttl-seconds': '21600'}70 r= requests.put(token_url,headers=headers,timeout=(2, 5))71 return r.text7273def get_instance_id():74 instance_identity_url = "http://169.254.169.254/latest/dynamic/instance-identity/document"75 session = requests.Session()76 retries = Retry(total=3, backoff_factor=0.3)
...
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!!