Unable to get available prefixes from unsaved Prefix object #6413
-
NetBox versionv2.11.3 Python version3.8 Steps to Reproduce
from ipam.models import Prefix
Prefix(prefix="10.0.0.0/8").get_available_prefixes() If you get the prefix object from the db and call the function everything works as expected: from ipam.models import Prefix
Prefix(prefix="10.0.0.0/8").save()
Prefix.objects.get(prefix="10.0.0.0/8").get_available_prefixes()
IPSet(['10.0.0.0/8']) Expected BehaviorIPSet(['10.0.0.0/8']) Observed BehaviorTraceback (most recent call last):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 125, in str_to_int
return _struct.unpack('>I', _inet_pton(AF_INET, addr))[0]
OSError: illegal IP address string passed to inet_pton
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 311, in __init__
self._value = self._module.str_to_int(addr, flags)
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 129, in str_to_int
raise AddrFormatError('%r is not a valid IPv4 address string!' % (addr,))
netaddr.core.AddrFormatError: '.' is not a valid IPv4 address string!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 799, in parse_ip_network
ip = IPAddress(val1, module.version, flags=INET_PTON)
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 313, in __init__
raise AddrFormatError('base address %r is not IPv%d'
netaddr.core.AddrFormatError: base address '.' is not IPv4
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in expand_partial_address
tokens = ['%d' % int(o) for o in addr.split('.')]
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 263, in <listcomp>
tokens = ['%d' % int(o) for o in addr.split('.')]
ValueError: invalid literal for int() with base 10: ''
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 942, in __init__
value, prefixlen = parse_ip_network(module, addr,
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 803, in parse_ip_network
expanded_addr = _ipv4.expand_partial_address(val1)
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/strategy/ipv4.py", line 267, in expand_partial_address
raise error
netaddr.core.AddrFormatError: invalid partial IPv4 address: '.'!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/netbox-2.11.3/netbox/ipam/models/ip.py", line 415, in get_available_prefixes
prefix = netaddr.IPSet(self.prefix)
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/sets.py", line 121, in __init__
for cidr in cidr_merge(mergeable):
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 1600, in cidr_merge
net = IPNetwork(ip)
File "/opt/netbox-2.11.3/venv/lib64/python3.8/site-packages/netaddr/ip/__init__.py", line 953, in __init__
raise AddrFormatError('invalid IPNetwork %s' % (addr,))
netaddr.core.AddrFormatError: invalid IPNetwork . |
Beta Was this translation helpful? Give feedback.
Answered by
jeremystretch
May 13, 2021
Replies: 1 comment
-
This is expected, because you've specified a string when instantiating the Prefix. If you don't need to create a Prefix, just use netaddr's IPNetwork object directly. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ryanmerolle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is expected, because you've specified a string when instantiating the Prefix. If you don't need to create a Prefix, just use netaddr's IPNetwork object directly.