fix: IP-Bereiche mit korrekten Adresstypen erstellen
- Start- und Endadressen als netaddr-Objekte übergeben - Fehler einzelner IP-Adressen beim Abgleich protokollieren - IP-Netzübersicht direkt im IPAM-Menü registrieren - Plugin-Version auf 1.2.1 erhöhen
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import ipaddress
|
||||
import logging
|
||||
|
||||
import netaddr
|
||||
from django.db import transaction
|
||||
from ipam.models import IPRange
|
||||
from netbox.plugins import get_plugin_config
|
||||
@@ -46,8 +47,10 @@ def ensure_range_for_ip(ip, *, config=None):
|
||||
elif network.version == 6 and network.prefixlen < 127:
|
||||
first += 1
|
||||
|
||||
start_address = f"{ipaddress.ip_address(first)}/{network.prefixlen}"
|
||||
end_address = f"{ipaddress.ip_address(last)}/{network.prefixlen}"
|
||||
# IPRange.save() performs arithmetic on the field values before Django's
|
||||
# field conversion runs, so these must be netaddr objects rather than strings.
|
||||
start_address = netaddr.IPNetwork(f"{ipaddress.ip_address(first)}/{network.prefixlen}")
|
||||
end_address = netaddr.IPNetwork(f"{ipaddress.ip_address(last)}/{network.prefixlen}")
|
||||
lookup = {
|
||||
"start_address": start_address,
|
||||
"end_address": end_address,
|
||||
|
||||
Reference in New Issue
Block a user