Skip to content

Commit

Permalink
Fixes #1689: Disregard IP address mask when filtering for child IPs o…
Browse files Browse the repository at this point in the history
…f a prefix
  • Loading branch information
jeremystretch committed Nov 6, 2017
1 parent 73cd769 commit d306e76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 2 additions & 4 deletions netbox/ipam/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def get_child_ips(self):
"""
Return all IPAddresses within this Prefix.
"""
return IPAddress.objects.filter(address__net_contained_or_equal=str(self.prefix), vrf=self.vrf)
return IPAddress.objects.filter(address__net_host_contained=self.prefix, vrf=self.vrf)

def get_available_ips(self):
"""
Expand Down Expand Up @@ -314,9 +314,7 @@ def get_utilization(self):
child_prefixes = netaddr.IPSet([p.prefix for p in queryset])
return int(float(child_prefixes.size) / self.prefix.size * 100)
else:
child_count = IPAddress.objects.filter(
address__net_contained_or_equal=str(self.prefix), vrf=self.vrf
).count()
child_count = self.get_child_ips().count()
prefix_size = self.prefix.size
if self.family == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
prefix_size -= 2
Expand Down
8 changes: 2 additions & 6 deletions netbox/ipam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,7 @@ def get(self, request, pk):
aggregate = None

# Count child IP addresses
ipaddress_count = IPAddress.objects.filter(
vrf=prefix.vrf, address__net_host_contained=str(prefix.prefix)
).count()
ipaddress_count = prefix.get_child_ips().count()

# Parent prefixes table
parent_prefixes = Prefix.objects.filter(
Expand Down Expand Up @@ -530,9 +528,7 @@ def get(self, request, pk):
prefix = get_object_or_404(Prefix.objects.all(), pk=pk)

# Find all IPAddresses belonging to this Prefix
ipaddresses = IPAddress.objects.filter(
vrf=prefix.vrf, address__net_host_contained=str(prefix.prefix)
).select_related(
ipaddresses = prefix.get_child_ips().select_related(
'vrf', 'interface__device', 'primary_ip4_for', 'primary_ip6_for'
)
ipaddresses = add_available_ipaddresses(prefix.prefix, ipaddresses, prefix.is_pool)
Expand Down

0 comments on commit d306e76

Please sign in to comment.