Merge pull request #578 from yannlambret/add-modify-subnet-attribute-support
Add support for 'ModifySubnetAttribute' action
This commit is contained in:
commit
608df89bde
@ -1857,13 +1857,15 @@ class VPCPeeringConnectionBackend(object):
|
|||||||
|
|
||||||
|
|
||||||
class Subnet(TaggedEC2Resource):
|
class Subnet(TaggedEC2Resource):
|
||||||
def __init__(self, ec2_backend, subnet_id, vpc_id, cidr_block, availability_zone, defaultForAz):
|
def __init__(self, ec2_backend, subnet_id, vpc_id, cidr_block, availability_zone, defaultForAz,
|
||||||
|
map_public_ip_on_launch):
|
||||||
self.ec2_backend = ec2_backend
|
self.ec2_backend = ec2_backend
|
||||||
self.id = subnet_id
|
self.id = subnet_id
|
||||||
self.vpc_id = vpc_id
|
self.vpc_id = vpc_id
|
||||||
self.cidr_block = cidr_block
|
self.cidr_block = cidr_block
|
||||||
self._availability_zone = availability_zone
|
self._availability_zone = availability_zone
|
||||||
self.defaultForAz = defaultForAz
|
self.defaultForAz = defaultForAz
|
||||||
|
self.map_public_ip_on_launch = map_public_ip_on_launch
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
def create_from_cloudformation_json(cls, resource_name, cloudformation_json, region_name):
|
||||||
@ -1955,7 +1957,8 @@ class SubnetBackend(object):
|
|||||||
subnet_id = random_subnet_id()
|
subnet_id = random_subnet_id()
|
||||||
vpc = self.get_vpc(vpc_id) # Validate VPC exists
|
vpc = self.get_vpc(vpc_id) # Validate VPC exists
|
||||||
defaultForAz = "true" if vpc.is_default else "false"
|
defaultForAz = "true" if vpc.is_default else "false"
|
||||||
subnet = Subnet(self, subnet_id, vpc_id, cidr_block, availability_zone, defaultForAz)
|
map_public_ip_on_launch = "true" if vpc.is_default else "false"
|
||||||
|
subnet = Subnet(self, subnet_id, vpc_id, cidr_block, availability_zone, defaultForAz, map_public_ip_on_launch)
|
||||||
|
|
||||||
# AWS associates a new subnet with the default Network ACL
|
# AWS associates a new subnet with the default Network ACL
|
||||||
self.associate_default_network_acl_with_subnet(subnet_id)
|
self.associate_default_network_acl_with_subnet(subnet_id)
|
||||||
@ -1973,6 +1976,11 @@ class SubnetBackend(object):
|
|||||||
raise InvalidSubnetIdError(subnet_id)
|
raise InvalidSubnetIdError(subnet_id)
|
||||||
return deleted
|
return deleted
|
||||||
|
|
||||||
|
def modify_subnet_attribute(self, subnet_id, map_public_ip):
|
||||||
|
subnet = self.get_subnet(subnet_id)
|
||||||
|
if map_public_ip not in ('true', 'false'):
|
||||||
|
raise InvalidParameterValueError(map_public_ip)
|
||||||
|
subnet.map_public_ip_on_launch = map_public_ip
|
||||||
|
|
||||||
class SubnetRouteTableAssociation(object):
|
class SubnetRouteTableAssociation(object):
|
||||||
def __init__(self, route_table_id, subnet_id):
|
def __init__(self, route_table_id, subnet_id):
|
||||||
|
@ -31,6 +31,12 @@ class Subnets(BaseResponse):
|
|||||||
template = self.response_template(DESCRIBE_SUBNETS_RESPONSE)
|
template = self.response_template(DESCRIBE_SUBNETS_RESPONSE)
|
||||||
return template.render(subnets=subnets)
|
return template.render(subnets=subnets)
|
||||||
|
|
||||||
|
def modify_subnet_attribute(self):
|
||||||
|
subnet_id = self.querystring.get('SubnetId')[0]
|
||||||
|
map_public_ip = self.querystring.get('MapPublicIpOnLaunch.Value')[0]
|
||||||
|
self.ec2_backend.modify_subnet_attribute(subnet_id, map_public_ip)
|
||||||
|
return MODIFY_SUBNET_ATTRIBUTE_RESPONSE
|
||||||
|
|
||||||
|
|
||||||
CREATE_SUBNET_RESPONSE = """
|
CREATE_SUBNET_RESPONSE = """
|
||||||
<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||||
@ -74,6 +80,7 @@ DESCRIBE_SUBNETS_RESPONSE = """
|
|||||||
<availableIpAddressCount>251</availableIpAddressCount>
|
<availableIpAddressCount>251</availableIpAddressCount>
|
||||||
<availabilityZone>{{ subnet.availability_zone }}</availabilityZone>
|
<availabilityZone>{{ subnet.availability_zone }}</availabilityZone>
|
||||||
<defaultForAz>{{ subnet.defaultForAz }}</defaultForAz>
|
<defaultForAz>{{ subnet.defaultForAz }}</defaultForAz>
|
||||||
|
<mapPublicIpOnLaunch>{{ subnet.map_public_ip_on_launch }}</mapPublicIpOnLaunch>
|
||||||
<tagSet>
|
<tagSet>
|
||||||
{% for tag in subnet.get_tags() %}
|
{% for tag in subnet.get_tags() %}
|
||||||
<item>
|
<item>
|
||||||
@ -88,3 +95,9 @@ DESCRIBE_SUBNETS_RESPONSE = """
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</subnetSet>
|
</subnetSet>
|
||||||
</DescribeSubnetsResponse>"""
|
</DescribeSubnetsResponse>"""
|
||||||
|
|
||||||
|
MODIFY_SUBNET_ATTRIBUTE_RESPONSE = """
|
||||||
|
<ModifySubnetAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||||
|
<requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId>
|
||||||
|
<return>true</return>
|
||||||
|
</ModifySubnetAttributeResponse>"""
|
||||||
|
@ -3,9 +3,11 @@ from __future__ import unicode_literals
|
|||||||
import tests.backport_assert_raises # noqa
|
import tests.backport_assert_raises # noqa
|
||||||
from nose.tools import assert_raises
|
from nose.tools import assert_raises
|
||||||
|
|
||||||
|
import boto3
|
||||||
import boto
|
import boto
|
||||||
import boto.vpc
|
import boto.vpc
|
||||||
from boto.exception import EC2ResponseError
|
from boto.exception import EC2ResponseError
|
||||||
|
from botocore.exceptions import ParamValidationError
|
||||||
import json
|
import json
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
@ -69,6 +71,29 @@ def test_subnet_should_have_proper_availability_zone_set():
|
|||||||
subnetA = conn.create_subnet(vpcA.id, "10.0.0.0/24", availability_zone='us-west-1b')
|
subnetA = conn.create_subnet(vpcA.id, "10.0.0.0/24", availability_zone='us-west-1b')
|
||||||
subnetA.availability_zone.should.equal('us-west-1b')
|
subnetA.availability_zone.should.equal('us-west-1b')
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_modify_subnet_attribute():
|
||||||
|
ec2 = boto3.resource('ec2', region_name='us-west-1')
|
||||||
|
client = boto3.client('ec2', region_name='us-west-1')
|
||||||
|
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
|
||||||
|
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
|
||||||
|
|
||||||
|
subnet.map_public_ip_on_launch.should.be.false
|
||||||
|
|
||||||
|
client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': True})
|
||||||
|
subnet.reload()
|
||||||
|
|
||||||
|
subnet.map_public_ip_on_launch.should.be.true
|
||||||
|
|
||||||
|
@mock_ec2
|
||||||
|
def test_modify_subnet_attribute_validation():
|
||||||
|
ec2 = boto3.resource('ec2', region_name='us-west-1')
|
||||||
|
client = boto3.client('ec2', region_name='us-west-1')
|
||||||
|
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
|
||||||
|
subnet = ec2.create_subnet(VpcId=vpc.id, CidrBlock='10.0.0.0/24', AvailabilityZone='us-west-1a')
|
||||||
|
|
||||||
|
with assert_raises(ParamValidationError):
|
||||||
|
client.modify_subnet_attribute(SubnetId=subnet.id, MapPublicIpOnLaunch={'Value': 'invalid'})
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_get_subnets_filtering():
|
def test_get_subnets_filtering():
|
||||||
|
Loading…
Reference in New Issue
Block a user