Skip to content

Commit

Permalink
Fixes #2173: Fixed IndexError when automaticating allocating IP addre…
Browse files Browse the repository at this point in the history
…sses from large IPv6 prefixes
  • Loading branch information
jeremystretch committed Jun 29, 2018
1 parent 8d4c686 commit d98aa03
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions netbox/ipam/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def available_ips(self, request, pk=None):
requested_ips = request.data if isinstance(request.data, list) else [request.data]

# Determine if the requested number of IPs is available
available_ips = list(prefix.get_available_ips())
if len(available_ips) < len(requested_ips):
available_ips = prefix.get_available_ips()
if available_ips.size < len(requested_ips):
return Response(
{
"detail": "An insufficient number of IP addresses are available within the prefix {} ({} "
Expand All @@ -171,8 +171,9 @@ def available_ips(self, request, pk=None):
)

# Assign addresses from the list of available IPs and copy VRF assignment from the parent prefix
available_ips = iter(available_ips)
for requested_ip in requested_ips:
requested_ip['address'] = available_ips.pop(0)
requested_ip['address'] = next(available_ips)
requested_ip['vrf'] = prefix.vrf.pk if prefix.vrf else None

# Initialize the serializer with a list or a single object depending on what was requested
Expand Down

0 comments on commit d98aa03

Please sign in to comment.