def describe_addresses(self): template = self.response_template(DESCRIBE_ADDRESS_RESPONSE) if "Filter.1.Name" in self.querystring: filter_by = sequence_from_querystring("Filter.1.Name", self.querystring)[0] filter_value = sequence_from_querystring("Filter.1.Value", self.querystring) if filter_by == 'instance-id': addresses = filter(lambda x: x.instance.id == filter_value[0], self.ec2_backend.describe_addresses()) else: raise NotImplementedError( "Filtering not supported in describe_address.") elif "PublicIp.1" in self.querystring: public_ips = sequence_from_querystring("PublicIp", self.querystring) addresses = self.ec2_backend.address_by_ip(public_ips) elif "AllocationId.1" in self.querystring: allocation_ids = sequence_from_querystring("AllocationId", self.querystring) addresses = self.ec2_backend.address_by_allocation(allocation_ids) else: addresses = self.ec2_backend.describe_addresses() return template.render(addresses=addresses)
def describe_addresses(self): template = self.response_template(DESCRIBE_ADDRESS_RESPONSE) if "Filter.1.Name" in self.querystring: filter_by = sequence_from_querystring( "Filter.1.Name", self.querystring)[0] filter_value = sequence_from_querystring( "Filter.1.Value", self.querystring) if filter_by == 'instance-id': addresses = filter(lambda x: x.instance.id == filter_value[ 0], self.ec2_backend.describe_addresses()) else: raise NotImplementedError( "Filtering not supported in describe_address.") elif "PublicIp.1" in self.querystring: public_ips = sequence_from_querystring( "PublicIp", self.querystring) addresses = self.ec2_backend.address_by_ip(public_ips) elif "AllocationId.1" in self.querystring: allocation_ids = sequence_from_querystring( "AllocationId", self.querystring) addresses = self.ec2_backend.address_by_allocation(allocation_ids) else: addresses = self.ec2_backend.describe_addresses() return template.render(addresses=addresses)
def describe_addresses(self): template = Template(DESCRIBE_ADDRESS_RESPONSE) if "Filter.1.Name" in self.querystring: raise NotImplementedError("Filtering not supported in describe_address.") elif "PublicIp.1" in self.querystring: public_ips = sequence_from_querystring("PublicIp", self.querystring) addresses = ec2_backend.address_by_ip(public_ips) elif "AllocationId.1" in self.querystring: allocation_ids = sequence_from_querystring("AllocationId", self.querystring) addresses = ec2_backend.address_by_allocation(allocation_ids) else: addresses = ec2_backend.describe_addresses() return template.render(addresses=addresses)
def delete_tags(self): resource_ids = sequence_from_querystring('ResourceId', self.querystring) validate_resource_ids(resource_ids) tags = tags_from_query_string(self.querystring) self.ec2_backend.delete_tags(resource_ids, tags) return DELETE_RESPONSE
def describe_network_interfaces(self): eni_ids = sequence_from_querystring('NetworkInterfaceId', self.querystring) filters = filters_from_querystring(self.querystring) enis = self.ec2_backend.get_all_network_interfaces(eni_ids, filters) template = self.response_template(DESCRIBE_NETWORK_INTERFACES_RESPONSE) return template.render(enis=enis)
def describe_dhcp_options(self): dhcp_opt_ids = sequence_from_querystring("DhcpOptionsId", self.querystring) if filters_from_querystring(self.querystring): raise NotImplementedError("Filtering not supported in describe_dhcp_options.") dhcp_opts = self.ec2_backend.get_all_dhcp_options(dhcp_opt_ids, None) template = self.response_template(DESCRIBE_DHCP_OPTIONS_RESPONSE) return template.render(dhcp_options=dhcp_opts)
def create_tags(self): resource_ids = sequence_from_querystring('ResourceId', self.querystring) validate_resource_ids(resource_ids) self.ec2_backend.do_resources_exist(resource_ids) tags = tags_from_query_string(self.querystring) self.ec2_backend.create_tags(resource_ids, tags) return CREATE_RESPONSE
def delete_tags(self): resource_ids = sequence_from_querystring('ResourceId', self.querystring) validate_resource_ids(resource_ids) tags = tags_from_query_string(self.querystring) if self.is_not_dryrun('DeleteTags'): self.ec2_backend.delete_tags(resource_ids, tags) return DELETE_RESPONSE
def describe_network_interfaces(self): eni_ids = sequence_from_querystring( 'NetworkInterfaceId', self.querystring) filters = filters_from_querystring(self.querystring) enis = self.ec2_backend.get_all_network_interfaces(eni_ids, filters) template = self.response_template(DESCRIBE_NETWORK_INTERFACES_RESPONSE) return template.render(enis=enis)
def describe_vpn_connections(self): vpn_connection_ids = sequence_from_querystring('VpnConnectionId', self.querystring) filters = filters_from_querystring(self.querystring) vpn_connections = self.ec2_backend.get_all_vpn_connections( vpn_connection_ids=vpn_connection_ids, filters=filters) template = self.response_template(DESCRIBE_VPN_CONNECTION_RESPONSE) return template.render(vpn_connections=vpn_connections)
def create_network_interface(self): subnet_id = self.querystring.get('SubnetId')[0] private_ip_address = self.querystring.get('PrivateIpAddress', [None])[0] groups = sequence_from_querystring('SecurityGroupId', self.querystring) subnet = self.ec2_backend.get_subnet(subnet_id) eni = self.ec2_backend.create_network_interface(subnet, private_ip_address, groups) template = self.response_template(CREATE_NETWORK_INTERFACE_RESPONSE) return template.render(eni=eni)
def describe_dhcp_options(self): dhcp_opt_ids = sequence_from_querystring("DhcpOptionsId", self.querystring) filters = filters_from_querystring(self.querystring) dhcp_opts = self.ec2_backend.get_all_dhcp_options( dhcp_opt_ids, filters) template = self.response_template(DESCRIBE_DHCP_OPTIONS_RESPONSE) return template.render(dhcp_options=dhcp_opts)
def create_network_interface(self): subnet_id = self.querystring.get("SubnetId")[0] private_ip_address = self.querystring.get("PrivateIpAddress", [None])[0] groups = sequence_from_querystring("SecurityGroupId", self.querystring) subnet = self.ec2_backend.get_subnet(subnet_id) eni = self.ec2_backend.create_network_interface(subnet, private_ip_address, groups) template = self.response_template(CREATE_NETWORK_INTERFACE_RESPONSE) return template.render(eni=eni)
def modify_image_attribute(self): ami_id = self.querystring.get('ImageId')[0] operation_type = self.querystring.get('OperationType')[0] group = self.querystring.get('UserGroup.1', [None])[0] user_ids = sequence_from_querystring('UserId', self.querystring) if (operation_type == 'add'): self.ec2_backend.add_launch_permission(ami_id, user_ids=user_ids, group=group) elif (operation_type == 'remove'): self.ec2_backend.remove_launch_permission(ami_id, user_ids=user_ids, group=group) return MODIFY_IMAGE_ATTRIBUTE_RESPONSE
def describe_dhcp_options(self): if "Filter.1.Name" in self.querystring: raise NotImplementedError("Filtering not supported in describe_dhcp_options.") elif "DhcpOptionsId.1" in self.querystring: dhcp_opt_ids = sequence_from_querystring("DhcpOptionsId", self.querystring) dhcp_opt = ec2_backend.describe_dhcp_options(dhcp_opt_ids) else: dhcp_opt = ec2_backend.describe_dhcp_options() template = Template(DESCRIBE_DHCP_OPTIONS_RESPONSE) return template.render(dhcp_options=dhcp_opt)
def describe_internet_gateways(self): if "Filter.1.Name" in self.querystring: raise NotImplementedError( "Filtering not supported in describe_internet_gateways.") elif "InternetGatewayId.1" in self.querystring: igw_ids = sequence_from_querystring("InternetGatewayId", self.querystring) igws = ec2_backend.describe_internet_gateways(igw_ids) else: igws = ec2_backend.describe_internet_gateways() template = Template(DESCRIBE_INTERNET_GATEWAYS_RESPONSE) return template.render(internet_gateways=igws)
def describe_internet_gateways(self): filter_dict = filters_from_querystring(self.querystring) if "InternetGatewayId.1" in self.querystring: igw_ids = sequence_from_querystring("InternetGatewayId", self.querystring) igws = self.ec2_backend.describe_internet_gateways( igw_ids, filters=filter_dict) else: igws = self.ec2_backend.describe_internet_gateways( filters=filter_dict) template = self.response_template(DESCRIBE_INTERNET_GATEWAYS_RESPONSE) return template.render(internet_gateways=igws)