Fix:EC2-Create-Subnet availability Zone Id support (#3198)
* Fix:EC2-Create-Subnet availability Zone Id support * Linting * Fix:fixed build errors * linting Co-authored-by: Bert Blommers <bblommers@users.noreply.github.com> Co-authored-by: Bert Blommers <info@bertblommers.nl> Co-authored-by: usmankb <usman@krazybee.com>
This commit is contained in:
parent
49d92861c0
commit
1c939a5f06
3 changed files with 55 additions and 16 deletions
|
|
@ -3402,7 +3402,14 @@ class SubnetBackend(object):
|
|||
return subnets[subnet_id]
|
||||
raise InvalidSubnetIdError(subnet_id)
|
||||
|
||||
def create_subnet(self, vpc_id, cidr_block, availability_zone, context=None):
|
||||
def create_subnet(
|
||||
self,
|
||||
vpc_id,
|
||||
cidr_block,
|
||||
availability_zone=None,
|
||||
availability_zone_id=None,
|
||||
context=None,
|
||||
):
|
||||
subnet_id = random_subnet_id()
|
||||
vpc = self.get_vpc(
|
||||
vpc_id
|
||||
|
|
@ -3430,15 +3437,25 @@ class SubnetBackend(object):
|
|||
# consider it the default
|
||||
default_for_az = str(availability_zone not in self.subnets).lower()
|
||||
map_public_ip_on_launch = default_for_az
|
||||
if availability_zone is None:
|
||||
|
||||
if availability_zone is None and not availability_zone_id:
|
||||
availability_zone = "us-east-1a"
|
||||
try:
|
||||
availability_zone_data = next(
|
||||
zone
|
||||
for zones in RegionsAndZonesBackend.zones.values()
|
||||
for zone in zones
|
||||
if zone.name == availability_zone
|
||||
)
|
||||
if availability_zone:
|
||||
availability_zone_data = next(
|
||||
zone
|
||||
for zones in RegionsAndZonesBackend.zones.values()
|
||||
for zone in zones
|
||||
if zone.name == availability_zone
|
||||
)
|
||||
elif availability_zone_id:
|
||||
availability_zone_data = next(
|
||||
zone
|
||||
for zones in RegionsAndZonesBackend.zones.values()
|
||||
for zone in zones
|
||||
if zone.zone_id == availability_zone_id
|
||||
)
|
||||
|
||||
except StopIteration:
|
||||
raise InvalidAvailabilityZoneError(
|
||||
availability_zone,
|
||||
|
|
|
|||
|
|
@ -9,12 +9,14 @@ class Subnets(BaseResponse):
|
|||
def create_subnet(self):
|
||||
vpc_id = self._get_param("VpcId")
|
||||
cidr_block = self._get_param("CidrBlock")
|
||||
availability_zone = self._get_param(
|
||||
"AvailabilityZone",
|
||||
if_none=random.choice(self.ec2_backend.describe_availability_zones()).name,
|
||||
)
|
||||
availability_zone = self._get_param("AvailabilityZone")
|
||||
availability_zone_id = self._get_param("AvailabilityZoneId")
|
||||
if not availability_zone and not availability_zone_id:
|
||||
availability_zone = random.choice(
|
||||
self.ec2_backend.describe_availability_zones()
|
||||
).name
|
||||
subnet = self.ec2_backend.create_subnet(
|
||||
vpc_id, cidr_block, availability_zone, context=self
|
||||
vpc_id, cidr_block, availability_zone, availability_zone_id, context=self
|
||||
)
|
||||
template = self.response_template(CREATE_SUBNET_RESPONSE)
|
||||
return template.render(subnet=subnet)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue