From 040cbef9be9c158f968fc8c1679c196121413990 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 5 Jan 2019 16:09:41 -0600 Subject: [PATCH] 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. --- moto/ec2/models.py | 1 + moto/ec2/responses/subnets.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/moto/ec2/models.py b/moto/ec2/models.py index efbbeb6fe..dc12f8eba 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -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 diff --git a/moto/ec2/responses/subnets.py b/moto/ec2/responses/subnets.py index c42583f23..e11984e52 100644 --- a/moto/ec2/responses/subnets.py +++ b/moto/ec2/responses/subnets.py @@ -53,7 +53,7 @@ CREATE_SUBNET_RESPONSE = """ pending {{ subnet.vpc_id }} {{ subnet.cidr_block }} - 251 + {{ subnet.available_ip_addresses }} {{ subnet._availability_zone.name }} {{ subnet._availability_zone.zone_id }} {{ subnet.default_for_az }} @@ -81,7 +81,7 @@ DESCRIBE_SUBNETS_RESPONSE = """ available {{ subnet.vpc_id }} {{ subnet.cidr_block }} - 251 + {{ subnet.available_ip_addresses }} {{ subnet._availability_zone.name }} {{ subnet._availability_zone.zone_id }} {{ subnet.default_for_az }}