2014-08-27 11:17:06 -04:00
|
|
|
from __future__ import unicode_literals
|
2013-12-29 08:25:13 -05:00
|
|
|
from moto.core.responses import BaseResponse
|
2016-05-12 22:36:09 +02:00
|
|
|
from moto.core.utils import camelcase_to_underscores
|
2017-09-16 17:08:21 +05:30
|
|
|
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 VPCs(BaseResponse):
|
2017-02-23 21:37:43 -05:00
|
|
|
|
2013-02-21 23:13:01 -05:00
|
|
|
def create_vpc(self):
|
2017-09-16 18:31:30 +05:30
|
|
|
cidr_block = self._get_param('CidrBlock')
|
|
|
|
instance_tenancy = self._get_param('InstanceTenancy', if_none='default')
|
2017-02-08 21:23:49 -05:00
|
|
|
vpc = self.ec2_backend.create_vpc(cidr_block, instance_tenancy)
|
2014-12-12 12:46:07 -08:00
|
|
|
template = self.response_template(CREATE_VPC_RESPONSE)
|
2013-03-05 22:33:41 -05:00
|
|
|
return template.render(vpc=vpc)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def delete_vpc(self):
|
2017-09-16 18:31:30 +05:30
|
|
|
vpc_id = self._get_param('VpcId')
|
2014-10-23 22:26:52 -04:00
|
|
|
vpc = self.ec2_backend.delete_vpc(vpc_id)
|
2014-12-12 12:46:07 -08:00
|
|
|
template = self.response_template(DELETE_VPC_RESPONSE)
|
2014-08-25 10:54:47 -07:00
|
|
|
return template.render(vpc=vpc)
|
2013-02-21 23:13:01 -05:00
|
|
|
|
|
|
|
def describe_vpcs(self):
|
2017-09-16 17:08:21 +05:30
|
|
|
vpc_ids = self._get_multi_param('VpcId')
|
2014-09-30 17:07:09 +03:00
|
|
|
filters = filters_from_querystring(self.querystring)
|
2014-10-23 22:26:52 -04:00
|
|
|
vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
|
2014-12-12 12:46:07 -08:00
|
|
|
template = self.response_template(DESCRIBE_VPCS_RESPONSE)
|
2013-03-05 22:33:41 -05:00
|
|
|
return template.render(vpcs=vpcs)
|
|
|
|
|
2016-05-12 22:36:09 +02:00
|
|
|
def describe_vpc_attribute(self):
|
2017-09-16 18:31:30 +05:30
|
|
|
vpc_id = self._get_param('VpcId')
|
|
|
|
attribute = self._get_param('Attribute')
|
2016-05-12 22:36:09 +02:00
|
|
|
attr_name = camelcase_to_underscores(attribute)
|
|
|
|
value = self.ec2_backend.describe_vpc_attribute(vpc_id, attr_name)
|
|
|
|
template = self.response_template(DESCRIBE_VPC_ATTRIBUTE_RESPONSE)
|
|
|
|
return template.render(vpc_id=vpc_id, attribute=attribute, value=value)
|
|
|
|
|
|
|
|
def modify_vpc_attribute(self):
|
2017-09-16 18:31:30 +05:30
|
|
|
vpc_id = self._get_param('VpcId')
|
2016-05-12 22:36:09 +02:00
|
|
|
|
|
|
|
for attribute in ('EnableDnsSupport', 'EnableDnsHostnames'):
|
|
|
|
if self.querystring.get('%s.Value' % attribute):
|
|
|
|
attr_name = camelcase_to_underscores(attribute)
|
|
|
|
attr_value = self.querystring.get('%s.Value' % attribute)[0]
|
2017-02-23 21:37:43 -05:00
|
|
|
self.ec2_backend.modify_vpc_attribute(
|
|
|
|
vpc_id, attr_name, attr_value)
|
2016-05-12 22:36:09 +02:00
|
|
|
return MODIFY_VPC_ATTRIBUTE_RESPONSE
|
|
|
|
|
2013-03-05 22:33:41 -05:00
|
|
|
|
|
|
|
CREATE_VPC_RESPONSE = """
|
2016-02-02 16:15:18 +03:00
|
|
|
<CreateVpcResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
2013-03-05 22:33:41 -05:00
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<vpc>
|
|
|
|
<vpcId>{{ vpc.id }}</vpcId>
|
|
|
|
<state>pending</state>
|
|
|
|
<cidrBlock>{{ vpc.cidr_block }}</cidrBlock>
|
2016-10-08 10:37:57 +01:00
|
|
|
<dhcpOptionsId>{% if vpc.dhcp_options %}{{ vpc.dhcp_options.id }}{% else %}dopt-1a2b3c4d2{% endif %}</dhcpOptionsId>
|
2017-02-08 21:23:49 -05:00
|
|
|
<instanceTenancy>{{ vpc.instance_tenancy }}</instanceTenancy>
|
2014-05-11 19:00:28 -04:00
|
|
|
<tagSet>
|
|
|
|
{% for tag in vpc.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:33:41 -05:00
|
|
|
</vpc>
|
|
|
|
</CreateVpcResponse>"""
|
|
|
|
|
|
|
|
DESCRIBE_VPCS_RESPONSE = """
|
2016-02-02 16:15:18 +03:00
|
|
|
<DescribeVpcsResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
2013-03-05 22:33:41 -05:00
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<vpcSet>
|
|
|
|
{% for vpc in vpcs %}
|
|
|
|
<item>
|
|
|
|
<vpcId>{{ vpc.id }}</vpcId>
|
2014-10-12 21:51:12 -04:00
|
|
|
<state>{{ vpc.state }}</state>
|
2013-03-05 22:33:41 -05:00
|
|
|
<cidrBlock>{{ vpc.cidr_block }}</cidrBlock>
|
2016-10-08 10:34:55 +01:00
|
|
|
<dhcpOptionsId>{% if vpc.dhcp_options %}{{ vpc.dhcp_options.id }}{% else %}dopt-7a8b9c2d{% endif %}</dhcpOptionsId>
|
2017-02-08 21:23:49 -05:00
|
|
|
<instanceTenancy>{{ vpc.instance_tenancy }}</instanceTenancy>
|
2015-12-06 20:58:54 +01:00
|
|
|
<isDefault>{{ vpc.is_default }}</isDefault>
|
2014-05-11 19:00:28 -04:00
|
|
|
<tagSet>
|
|
|
|
{% for tag in vpc.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:33:41 -05:00
|
|
|
</item>
|
|
|
|
{% endfor %}
|
|
|
|
</vpcSet>
|
|
|
|
</DescribeVpcsResponse>"""
|
|
|
|
|
|
|
|
DELETE_VPC_RESPONSE = """
|
2016-02-02 16:15:18 +03:00
|
|
|
<DeleteVpcResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
2013-03-05 22:33:41 -05:00
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</DeleteVpcResponse>
|
|
|
|
"""
|
2016-05-12 22:36:09 +02:00
|
|
|
|
|
|
|
DESCRIBE_VPC_ATTRIBUTE_RESPONSE = """
|
|
|
|
<DescribeVpcAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<vpcId>{{ vpc_id }}</vpcId>
|
|
|
|
<{{ attribute }}>
|
|
|
|
<value>{{ value }}</value>
|
|
|
|
</{{ attribute }}>
|
|
|
|
</DescribeVpcAttributeResponse>"""
|
|
|
|
|
|
|
|
MODIFY_VPC_ATTRIBUTE_RESPONSE = """
|
|
|
|
<ModifyVpcAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
|
|
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
|
|
|
<return>true</return>
|
|
|
|
</ModifyVpcAttributeResponse>"""
|