Displays the correct number of available IP addresses for a subnet

create_subnet and describe_subnets displays the correct number of
available IP addresses. The module currently has '251' hardcoded.
This fix shows available IPs minus 5, which are reserved in each
subnet by AWS.
This commit is contained in:
Your Name 2019-01-05 16:09:41 -06:00 committed by Bert Blommers
parent 0c3d7c4f04
commit 040cbef9be
2 changed files with 3 additions and 2 deletions

View File

@ -2819,6 +2819,7 @@ class Subnet(TaggedEC2Resource):
self.vpc_id = vpc_id
self.cidr_block = cidr_block
self.cidr = ipaddress.IPv4Network(six.text_type(self.cidr_block), strict=False)
self.available_ips = ipaddress.IPv4Network(cidr_block).num_addresses - 5
self._availability_zone = availability_zone
self.default_for_az = default_for_az
self.map_public_ip_on_launch = map_public_ip_on_launch

View File

@ -53,7 +53,7 @@ CREATE_SUBNET_RESPONSE = """
<state>pending</state>
<vpcId>{{ subnet.vpc_id }}</vpcId>
<cidrBlock>{{ subnet.cidr_block }}</cidrBlock>
<availableIpAddressCount>251</availableIpAddressCount>
<availableIpAddressCount>{{ subnet.available_ip_addresses }}</availableIpAddressCount>
<availabilityZone>{{ subnet._availability_zone.name }}</availabilityZone>
<availabilityZoneId>{{ subnet._availability_zone.zone_id }}</availabilityZoneId>
<defaultForAz>{{ subnet.default_for_az }}</defaultForAz>
@ -81,7 +81,7 @@ DESCRIBE_SUBNETS_RESPONSE = """
<state>available</state>
<vpcId>{{ subnet.vpc_id }}</vpcId>
<cidrBlock>{{ subnet.cidr_block }}</cidrBlock>
<availableIpAddressCount>251</availableIpAddressCount>
<availableIpAddressCount>{{ subnet.available_ip_addresses }}</availableIpAddressCount>
<availabilityZone>{{ subnet._availability_zone.name }}</availabilityZone>
<availabilityZoneId>{{ subnet._availability_zone.zone_id }}</availabilityZoneId>
<defaultForAz>{{ subnet.default_for_az }}</defaultForAz>