2014-08-27 11:17:06 -04:00
|
|
|
from __future__ import unicode_literals
|
2013-02-21 23:13:01 -05:00
|
|
|
from jinja2 import Template
|
|
|
|
|
2013-12-29 08:25:13 -05:00
|
|
|
from moto.core.responses import BaseResponse
|
2014-08-26 13:25:37 -07:00
|
|
|
from moto.ec2.utils import filters_from_querystring
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
|
2013-12-29 08:25:13 -05:00
|
|
|
class Subnets(BaseResponse):
|
2013-02-21 23:13:01 -05:00
|
|
|
def create_subnet(self):
|
2013-03-05 22:53:53 -05:00
|
|
|
vpc_id = self.querystring.get('VpcId')[0]
|
|
|
|
cidr_block = self.querystring.get('CidrBlock')[0]
|
2014-10-23 22:36:05 -04:00
|
|
|
subnet = self.ec2_backend.create_subnet(vpc_id, cidr_block)
|
2013-03-05 22:53:53 -05:00
|
|
|
template = Template(CREATE_SUBNET_RESPONSE)
|
|
|
|
return template.render(subnet=subnet)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def delete_subnet(self):
|
2013-03-05 22:53:53 -05:00
|
|
|
subnet_id = self.querystring.get('SubnetId')[0]
|
2014-10-23 22:36:05 -04:00
|
|
|
subnet = self.ec2_backend.delete_subnet(subnet_id)
|
2014-08-25 10:54:47 -07:00
|
|
|
template = Template(DELETE_SUBNET_RESPONSE)
|
|
|
|
return template.render(subnet=subnet)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def describe_subnets(self):
|
2014-08-26 13:25:37 -07:00
|
|
|
filters = filters_from_querystring(self.querystring)
|
2014-10-23 22:36:05 -04:00
|
|
|
subnets = self.ec2_backend.get_all_subnets(filters)
|
2013-03-05 22:53:53 -05:00
|
|
|
template = Template(DESCRIBE_SUBNETS_RESPONSE)
|
|
|
|
return template.render(subnets=subnets)
|
|
|
|
|
|
|
|
|
|
|
|
CREATE_SUBNET_RESPONSE = """
|
|
|
|
<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<subnet>
|
|
|
|
<subnetId>{{ subnet.id }}</subnetId>
|
|
|
|
<state>pending</state>
|
2014-03-28 16:37:55 -04:00
|
|
|
<vpcId>{{ subnet.vpc_id }}</vpcId>
|
2013-03-05 22:53:53 -05:00
|
|
|
<cidrBlock>{{ subnet.cidr_block }}</cidrBlock>
|
|
|
|
<availableIpAddressCount>251</availableIpAddressCount>
|
|
|
|
<availabilityZone>us-east-1a</availabilityZone>
|
2014-05-11 19:00:28 -04:00
|
|
|
<tagSet>
|
|
|
|
{% for tag in subnet.get_tags() %}
|
|
|
|
<item>
|
|
|
|
<resourceId>{{ tag.resource_id }}</resourceId>
|
|
|
|
<resourceType>{{ tag.resource_type }}</resourceType>
|
|
|
|
<key>{{ tag.key }}</key>
|
|
|
|
<value>{{ tag.value }}</value>
|
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</tagSet>
|
2013-03-05 22:53:53 -05:00
|
|
|
</subnet>
|
|
|
|
</CreateSubnetResponse>"""
|
|
|
|
|
|
|
|
DELETE_SUBNET_RESPONSE = """
|
|
|
|
<DeleteSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</DeleteSubnetResponse>"""
|
|
|
|
|
|
|
|
DESCRIBE_SUBNETS_RESPONSE = """
|
|
|
|
<DescribeSubnetsResponse xmlns="http://ec2.amazonaws.com/doc/2012-12-01/">
|
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<subnetSet>
|
|
|
|
{% for subnet in subnets %}
|
|
|
|
<item>
|
|
|
|
<subnetId>{{ subnet.id }}</subnetId>
|
|
|
|
<state>available</state>
|
2014-03-28 16:37:55 -04:00
|
|
|
<vpcId>{{ subnet.vpc_id }}</vpcId>
|
2013-03-05 22:53:53 -05:00
|
|
|
<cidrBlock>{{ subnet.cidr_block }}</cidrBlock>
|
|
|
|
<availableIpAddressCount>251</availableIpAddressCount>
|
|
|
|
<availabilityZone>us-east-1a</availabilityZone>
|
2014-05-11 19:00:28 -04:00
|
|
|
<tagSet>
|
|
|
|
{% for tag in subnet.get_tags() %}
|
|
|
|
<item>
|
|
|
|
<resourceId>{{ tag.resource_id }}</resourceId>
|
|
|
|
<resourceType>{{ tag.resource_type }}</resourceType>
|
|
|
|
<key>{{ tag.key }}</key>
|
|
|
|
<value>{{ tag.value }}</value>
|
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</tagSet>
|
2013-03-05 22:53:53 -05:00
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</subnetSet>
|
|
|
|
</DescribeSubnetsResponse>"""
|