def describe_dhcp_options(self): dhcp_opt_ids = dhcp_opt_ids_from_querystring(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 describe_dhcp_options(self): dhcp_opt_ids = self._get_multi_param("DhcpOptionsId") 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 describe_network_acls(self): network_acl_ids = network_acl_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) network_acls = self.ec2_backend.get_all_network_acls( network_acl_ids, filters) template = self.response_template(DESCRIBE_NETWORK_ACL_RESPONSE) return template.render(network_acls=network_acls)
def describe_tags(self): filters = filters_from_querystring(querystring_dict=self.querystring) tags = self.ec2_backend.describe_tags(filters=filters) for tag in tags: tag['value'] = escape(tag['value']) template = self.response_template(DESCRIBE_RESPONSE) return template.render(tags=tags)
def describe_route_tables(self): route_table_ids = route_table_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) route_tables = self.ec2_backend.get_all_route_tables( route_table_ids, filters) template = self.response_template(DESCRIBE_ROUTE_TABLES_RESPONSE) return template.render(route_tables=route_tables)
def describe_images(self): ami_ids = image_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) images = self.ec2_backend.describe_images( ami_ids=ami_ids, filters=filters) template = self.response_template(DESCRIBE_IMAGES_RESPONSE) return template.render(images=images)
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 describe_vpcs(self): vpc_ids = self._get_multi_param('VpcId') filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15' template = self.response_template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs, doc_date=doc_date)
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_managed_prefix_lists(self): prefix_list_ids = self._get_multi_param("PrefixListId") filters = filters_from_querystring(self.querystring) managed_prefix_lists = self.ec2_backend.describe_managed_prefix_lists( prefix_list_ids=prefix_list_ids, filters=filters ) template = self.response_template(DESCRIBE_MANAGED_PREFIX_LIST) return template.render(managed_prefix_lists=managed_prefix_lists)
def describe_vpc_endpoints(self): vpc_end_points_ids = self._get_multi_param("VpcEndpointId") filters = filters_from_querystring(self.querystring) vpc_end_points = self.ec2_backend.get_vpc_end_point( vpc_end_point_ids=vpc_end_points_ids, filters=filters ) template = self.response_template(DESCRIBE_VPC_ENDPOINT_RESPONSE) return template.render(vpc_end_points=vpc_end_points, account_id=ACCOUNT_ID)
def describe_instance_type_offerings(self): location_type_filters = self._get_param("LocationType") filter_dict = filters_from_querystring(self.querystring) offerings = self.ec2_backend.describe_instance_type_offerings( location_type_filters, filter_dict ) template = self.response_template(EC2_DESCRIBE_INSTANCE_TYPE_OFFERINGS) return template.render(instance_type_offerings=offerings)
def describe_vpc_classic_link_dns_support(self): vpc_ids = self._get_multi_param("VpcIds") filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) doc_date = self._get_doc_date() template = self.response_template( DESCRIBE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE) return template.render(vpcs=vpcs, doc_date=doc_date)
def describe_vpcs(self): vpc_ids = self._get_multi_param("VpcId") filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) doc_date = ("2013-10-15" if "Boto/" in self.headers.get( "user-agent", "") else "2016-11-15") template = self.response_template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs, doc_date=doc_date)
def describe_egress_only_internet_gateways(self): egress_only_igw_ids = self._get_multi_param("EgressOnlyInternetGatewayId") filters = filters_from_querystring(self.querystring) egress_only_igws = self.ec2_backend.describe_egress_only_internet_gateways( egress_only_igw_ids, filters, ) template = self.response_template(DESCRIBE_EGRESS_ONLY_IGW_RESPONSE) return template.render(egress_only_igws=egress_only_igws)
def describe_images(self): ami_ids = self._get_multi_param('ImageId') filters = filters_from_querystring(self.querystring) exec_users = self._get_multi_param('ExecutableBy') images = self.ec2_backend.describe_images( ami_ids=ami_ids, filters=filters, exec_users=exec_users) template = self.response_template(DESCRIBE_IMAGES_RESPONSE) return template.render(images=images)
def describe_vpcs(self): vpc_ids = self._get_multi_param('VpcId') filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) doc_date = '2013-10-15' if 'Boto/' in self.headers.get( 'user-agent', '') else '2016-11-15' template = self.response_template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs, doc_date=doc_date)
def describe_addresses(self): allocation_ids = self._get_multi_param("AllocationId") public_ips = self._get_multi_param("PublicIp") filters = filters_from_querystring(self.querystring) addresses = self.ec2_backend.describe_addresses( allocation_ids, public_ips, filters) template = self.response_template(DESCRIBE_ADDRESS_RESPONSE) return template.render(addresses=addresses)
def describe_vpn_connections(self): vpn_connection_ids = self._get_multi_param("VpnConnectionId") 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 describe_addresses(self): allocation_ids = self._get_multi_param('AllocationId') public_ips = self._get_multi_param('PublicIp') filters = filters_from_querystring(self.querystring) addresses = self.ec2_backend.describe_addresses( allocation_ids, public_ips, filters) template = self.response_template(DESCRIBE_ADDRESS_RESPONSE) return template.render(addresses=addresses)
def describe_volumes(self): filters = filters_from_querystring(self.querystring) # querystring for multiple volumeids results in VolumeId.1, VolumeId.2 etc volume_ids = ','.join([','.join(v[1]) for v in self.querystring.items() if 'VolumeId' in v[0]]) volumes = self.ec2_backend.describe_volumes(filters=filters) # Describe volumes to handle filter on volume_ids volumes = [v for v in volumes if v.id in volume_ids] if volume_ids else volumes template = self.response_template(DESCRIBE_VOLUMES_RESPONSE) return template.render(volumes=volumes)
def describe_security_groups(self): groupnames = self._get_multi_param("GroupName") group_ids = self._get_multi_param("GroupId") filters = filters_from_querystring(self.querystring) groups = self.ec2_backend.describe_security_groups(group_ids=group_ids, groupnames=groupnames, filters=filters) template = self.response_template(DESCRIBE_SECURITY_GROUPS_RESPONSE) return template.render(groups=groups)
def describe_snapshots(self): filters = filters_from_querystring(self.querystring) # querystring for multiple snapshotids results in SnapshotId.1, SnapshotId.2 etc snapshot_ids = ','.join([','.join(s[1]) for s in self.querystring.items() if 'SnapshotId' in s[0]]) snapshots = self.ec2_backend.describe_snapshots(filters=filters) # Describe snapshots to handle filter on snapshot_ids snapshots = [s for s in snapshots if s.id in snapshot_ids] if snapshot_ids else snapshots template = self.response_template(DESCRIBE_SNAPSHOTS_RESPONSE) return template.render(snapshots=snapshots)
def describe_key_pairs(self): names = keypair_names_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) if len(filters) > 0: raise NotImplementedError('Using filters in KeyPairs.describe_key_pairs is not yet implemented') keypairs = self.ec2_backend.describe_key_pairs(names) template = self.response_template(DESCRIBE_KEY_PAIRS_RESPONSE) return template.render(keypairs=keypairs)
def get_transit_gateway_route_table_associations(self): transit_gateway_route_table_id = self._get_param( "TransitGatewayRouteTableId") filters = filters_from_querystring(self.querystring) transit_gateway_route_table_associations = self.ec2_backend.get_all_transit_gateway_route_table_associations( transit_gateway_route_table_id, filters) template = self.response_template( GET_TRANSIT_GATEWAY_ROUTE_TABLE_ASSOCIATIONS_RESPONSE) return template.render(transit_gateway_route_table_associations= transit_gateway_route_table_associations)
def describe_transit_gateway_route_tables(self): filters = filters_from_querystring(self.querystring) transit_gateway_route_table_ids = ( self._get_multi_param("TransitGatewayRouteTableIds") or None) transit_gateway_route_tables = self.ec2_backend.get_all_transit_gateway_route_tables( transit_gateway_route_table_ids, filters) template = self.response_template( DESCRIBE_TRANSIT_GATEWAY_ROUTE_TABLE_RESPONSE) return template.render( transit_gateway_route_tables=transit_gateway_route_tables)
def describe_instances(self): filter_dict = filters_from_querystring(self.querystring) instance_ids = instance_ids_from_querystring(self.querystring) if instance_ids: reservations = self.ec2_backend.get_reservations_by_instance_ids(instance_ids, filters=filter_dict) else: reservations = self.ec2_backend.all_reservations(make_copy=True, filters=filter_dict) template = self.response_template(EC2_DESCRIBE_INSTANCES) return template.render(reservations=reservations)
def describe_security_groups(self): groupnames = self._get_multi_param("GroupName") group_ids = self._get_multi_param("GroupId") filters = filters_from_querystring(self.querystring) groups = self.ec2_backend.describe_security_groups( group_ids=group_ids, groupnames=groupnames, filters=filters) template = self.response_template(DESCRIBE_SECURITY_GROUPS_RESPONSE) return template.render(groups=groups)
def describe_network_interfaces(self): # Partially implemented. Supports only network-interface-id and group-id filters filters = filters_from_querystring(self.querystring) eni_ids = self._get_multi_param("NetworkInterfaceId.") if "network-interface-id" not in filters and eni_ids: # Network interfaces can be filtered by passing the 'network-interface-id' # filter or by passing the NetworkInterfaceId parameter filters["network-interface-id"] = eni_ids enis = self.ec2_backend.describe_network_interfaces(filters) template = self.response_template(DESCRIBE_NETWORK_INTERFACES_RESPONSE) return template.render(enis=enis)
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 = Template(DESCRIBE_INTERNET_GATEWAYS_RESPONSE) return template.render(internet_gateways=igws)
def describe_network_interfaces(self): # Partially implemented. Supports only network-interface-id and group-id filters filters = filters_from_querystring(self.querystring) eni_ids = self._get_multi_param('NetworkInterfaceId.') if 'network-interface-id' not in filters and eni_ids: # Network interfaces can be filtered by passing the 'network-interface-id' # filter or by passing the NetworkInterfaceId parameter filters['network-interface-id'] = eni_ids enis = self.ec2_backend.describe_network_interfaces(filters) template = self.response_template(DESCRIBE_NETWORK_INTERFACES_RESPONSE) return template.render(enis=enis)
def describe_security_groups(self): groupnames = process_groupnames_from_querystring(self.querystring) group_ids = process_group_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) groups = ec2_backend.describe_security_groups(group_ids=group_ids, groupnames=groupnames, filters=filters) template = Template(DESCRIBE_SECURITY_GROUPS_RESPONSE) return template.render(groups=groups)
def describe_internet_gateways(self): filter_dict = filters_from_querystring(self.querystring) if "InternetGatewayId.1" in self.querystring: igw_ids = self._get_multi_param("InternetGatewayId") 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)
def search_transit_gateway_routes(self): transit_gateway_route_table_id = self._get_param( "TransitGatewayRouteTableId") filters = filters_from_querystring(self.querystring) max_results = self._get_param("MaxResults") transit_gateway_routes = self.ec2_backend.search_transit_gateway_routes( transit_gateway_route_table_id=transit_gateway_route_table_id, filters=filters, max_results=max_results, ) template = self.response_template( SEARCH_TRANSIT_GATEWAY_ROUTES_RESPONSE) return template.render(transit_gateway_routes=transit_gateway_routes)
def describe_security_groups(self): groupnames = process_groupnames_from_querystring(self.querystring) group_ids = process_group_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) groups = ec2_backend.describe_security_groups( group_ids=group_ids, groupnames=groupnames, filters=filters ) template = Template(DESCRIBE_SECURITY_GROUPS_RESPONSE) return template.render(groups=groups)
def describe_transit_gateway_attachments(self): transit_gateways_attachment_ids = self._get_multi_param( "TransitGatewayAttachmentIds") filters = filters_from_querystring(self.querystring) max_results = self._get_param("MaxResults") transit_gateway_attachments = self.ec2_backend.describe_transit_gateway_attachments( transit_gateways_attachment_ids=transit_gateways_attachment_ids, filters=filters, max_results=max_results, ) template = self.response_template(DESCRIBE_TRANSIT_GATEWAY_ATTACHMENTS) return template.render( transit_gateway_attachments=transit_gateway_attachments)
def describe_images(self): ami_ids = self._get_multi_param("ImageId") filters = filters_from_querystring(self.querystring) owners = self._get_multi_param("Owner") exec_users = self._get_multi_param("ExecutableBy") images = self.ec2_backend.describe_images( ami_ids=ami_ids, filters=filters, exec_users=exec_users, owners=owners, context=self, ) template = self.response_template(DESCRIBE_IMAGES_RESPONSE) return template.render(images=images)
def describe_key_pairs(self): names = keypair_names_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) if len(filters) > 0: raise NotImplementedError('Using filters in KeyPairs.describe_key_pairs is not yet implemented') try: keypairs = ec2_backend.describe_key_pairs(names) except InvalidIdError as exc: template = Template(CREATE_KEY_PAIR_NOT_FOUND) return template.render(keypair_id=exc.id), dict(status=400) else: template = Template(DESCRIBE_KEY_PAIRS_RESPONSE) return template.render(keypairs=keypairs)
def describe_subnets(self): filters = filters_from_querystring(self.querystring) subnet_ids = [] idx = 1 key = 'SubnetId.{0}'.format(idx) while key in self.querystring: v = self.querystring[key] subnet_ids.append(v[0]) idx += 1 key = 'SubnetId.{0}'.format(idx) subnets = self.ec2_backend.get_all_subnets(subnet_ids, filters) template = self.response_template(DESCRIBE_SUBNETS_RESPONSE) return template.render(subnets=subnets)
def describe_key_pairs(self): names = keypair_names_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) if len(filters) > 0: raise NotImplementedError( 'Using filters in KeyPairs.describe_key_pairs is not yet implemented' ) try: keypairs = ec2_backend.describe_key_pairs(names) except InvalidIdError as exc: template = Template(CREATE_KEY_PAIR_NOT_FOUND) return template.render(keypair_id=exc.id), dict(status=400) else: template = Template(DESCRIBE_KEY_PAIRS_RESPONSE) return template.render(keypairs=keypairs)
def describe_instances(self): instance_ids = instance_ids_from_querystring(self.querystring) if instance_ids: try: reservations = ec2_backend.get_reservations_by_instance_ids(instance_ids) except InvalidIdError as exc: template = Template(EC2_INVALID_INSTANCE_ID) return template.render(instance_id=exc.id), dict(status=400) else: reservations = ec2_backend.all_reservations(make_copy=True) filter_dict = filters_from_querystring(self.querystring) reservations = filter_reservations(reservations, filter_dict) template = Template(EC2_DESCRIBE_INSTANCES) return template.render(reservations=reservations)
def describe_instances(self): instance_ids = instance_ids_from_querystring(self.querystring) if instance_ids: try: reservations = ec2_backend.get_reservations_by_instance_ids(instance_ids) except InvalidIdError as exc: template = Template(EC2_INVALID_INSTANCE_ID) return template.render(instance_id=exc.instance_id), dict(status=400) else: reservations = ec2_backend.all_reservations(make_copy=True) filter_dict = filters_from_querystring(self.querystring) reservations = filter_reservations(reservations, filter_dict) template = Template(EC2_DESCRIBE_INSTANCES) return template.render(reservations=reservations)
def describe_launch_templates(self): max_results = self._get_int_param("MaxResults", 15) template_names = self._get_multi_param("LaunchTemplateName") template_ids = self._get_multi_param("LaunchTemplateId") filters = filters_from_querystring(self.querystring) if self.is_not_dryrun("DescribeLaunchTemplates"): tree = ElementTree.Element("DescribeLaunchTemplatesResponse") templates_node = ElementTree.SubElement(tree, "launchTemplates") templates = self.ec2_backend.get_launch_templates( template_names=template_names, template_ids=template_ids, filters=filters, ) templates = templates[:max_results] for template in templates: xml_serialize( templates_node, "item", { "createTime": template.create_time, "createdBy": "arn:aws:iam::{OWNER_ID}:root".format( OWNER_ID=OWNER_ID), "defaultVersionNumber": template.default_version_number, "latestVersionNumber": template.latest_version_number, "launchTemplateId": template.id, "launchTemplateName": template.name, }, ) return pretty_xml(tree)
def describe_instances(self): filter_dict = filters_from_querystring(self.querystring) instance_ids = self._get_multi_param('InstanceId') token = self._get_param("NextToken") if instance_ids: reservations = self.ec2_backend.get_reservations_by_instance_ids( instance_ids, filters=filter_dict) else: reservations = self.ec2_backend.all_reservations(filters=filter_dict) reservation_ids = [reservation.id for reservation in reservations] if token: start = reservation_ids.index(token) + 1 else: start = 0 max_results = int(self._get_param('MaxResults', 100)) reservations_resp = reservations[start:start + max_results] next_token = None if max_results and len(reservations) > (start + max_results): next_token = reservations_resp[-1].id template = self.response_template(EC2_DESCRIBE_INSTANCES) return template.render(reservations=reservations_resp, next_token=next_token).replace('True', 'true').replace('False', 'false')
def describe_vpn_gateways(self): filters = filters_from_querystring(self.querystring) vpn_gateways = self.ec2_backend.get_all_vpn_gateways(filters) template = self.response_template(DESCRIBE_VPN_GATEWAYS_RESPONSE) return template.render(vpn_gateways=vpn_gateways)
def describe_subnets(self): filters = filters_from_querystring(self.querystring) subnets = self.ec2_backend.get_all_subnets(filters) template = self.response_template(DESCRIBE_SUBNETS_RESPONSE) return template.render(subnets=subnets)
def describe_tags(self): filters = filters_from_querystring(querystring_dict=self.querystring) tags = self.ec2_backend.describe_tags(filters=filters) template = self.response_template(DESCRIBE_RESPONSE) return template.render(tags=tags)
def describe_customer_gateways(self): filters = filters_from_querystring(self.querystring) customer_gateways = self.ec2_backend.get_all_customer_gateways(filters) template = self.response_template(DESCRIBE_CUSTOMER_GATEWAYS_RESPONSE) return template.render(customer_gateways=customer_gateways)
def describe_vpcs(self): vpc_ids = self._get_multi_param('VpcId') filters = filters_from_querystring(self.querystring) vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) template = self.response_template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs)
def describe_tags(self): filters = filters_from_querystring(querystring_dict=self.querystring) tags = self.ec2_backend.describe_tags(filters=filters) template = Template(DESCRIBE_RESPONSE) return template.render(tags=tags)
def describe_spot_instance_requests(self): filters = filters_from_querystring(self.querystring) requests = self.ec2_backend.describe_spot_instance_requests( filters=filters) template = self.response_template(DESCRIBE_SPOT_INSTANCES_TEMPLATE) return template.render(requests=requests)
def describe_vpcs(self): vpc_ids = vpc_ids_from_querystring(self.querystring) filters = filters_from_querystring(self.querystring) vpcs = ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters) template = Template(DESCRIBE_VPCS_RESPONSE) return template.render(vpcs=vpcs)