from __future__ import unicode_literals
from moto.core.responses import BaseResponse
from moto.ec2.utils import filters_from_querystring
class Subnets(BaseResponse):
def create_subnet(self):
vpc_id = self.querystring.get('VpcId')[0]
cidr_block = self.querystring.get('CidrBlock')[0]
subnet = self.ec2_backend.create_subnet(vpc_id, cidr_block)
template = self.response_template(CREATE_SUBNET_RESPONSE)
return template.render(subnet=subnet)
def delete_subnet(self):
subnet_id = self.querystring.get('SubnetId')[0]
subnet = self.ec2_backend.delete_subnet(subnet_id)
template = self.response_template(DELETE_SUBNET_RESPONSE)
return template.render(subnet=subnet)
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)
CREATE_SUBNET_RESPONSE = """
7a62c49f-347e-4fc4-9331-6e8eEXAMPLE
{{ subnet.id }}
pending
{{ subnet.vpc_id }}
{{ subnet.cidr_block }}
251
us-east-1a
{% for tag in subnet.get_tags() %}
-
{{ tag.resource_id }}
{{ tag.resource_type }}
{{ tag.key }}
{{ tag.value }}
{% endfor %}
"""
DELETE_SUBNET_RESPONSE = """
7a62c49f-347e-4fc4-9331-6e8eEXAMPLE
true
"""
DESCRIBE_SUBNETS_RESPONSE = """
7a62c49f-347e-4fc4-9331-6e8eEXAMPLE
{% for subnet in subnets %}
-
{{ subnet.id }}
available
{{ subnet.vpc_id }}
{{ subnet.cidr_block }}
251
us-east-1a
{% for tag in subnet.get_tags() %}
-
{{ tag.resource_id }}
{{ tag.resource_type }}
{{ tag.key }}
{{ tag.value }}
{% endfor %}
{% endfor %}
"""