API: Better free range finding algorithm
This commit is contained in:
parent
c0a65be9d0
commit
f8ed94d725
19
api/views.py
19
api/views.py
|
@ -8,6 +8,9 @@ from whoisdb.models import ASBlock, ASNumber, InetNum
|
||||||
from domains.models import Domain, ReverseZone
|
from domains.models import Domain, ReverseZone
|
||||||
from dnmgmt.settings import TLD_NAMESERVERS
|
from dnmgmt.settings import TLD_NAMESERVERS
|
||||||
|
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def asblockFreeAS(request):
|
def asblockFreeAS(request):
|
||||||
|
|
||||||
|
@ -97,6 +100,22 @@ def freeSubnet(request):
|
||||||
# candidateNet =
|
# candidateNet =
|
||||||
# and (biggestNet.getNetwork().broadcast_address.:
|
# and (biggestNet.getNetwork().broadcast_address.:
|
||||||
|
|
||||||
|
# try using next network in range
|
||||||
|
# ordering does not work, as order_by sorts alphabetically
|
||||||
|
# ==> the set is short, we can iterate through all. no sense in unpacking the SQL magic
|
||||||
|
#biggestNets = parentRange.inetnum_set.order_by("-address")
|
||||||
|
biggestNet = None
|
||||||
|
for ipRange in parentRange.inetnum_set.all():
|
||||||
|
if not biggestNet or ipRange.getNetwork() > biggestNet:
|
||||||
|
biggestNet = ipRange.getNetwork()
|
||||||
|
|
||||||
|
if biggestNet:
|
||||||
|
candidateNet = ipaddress.ip_network("%s/%s" % (biggestNet.broadcast_address + 1, biggestNet.prefixlen))
|
||||||
|
print("biggest net", biggestNet, "candidate", candidateNet)
|
||||||
|
if candidateNet.network_address in parentRange.getNetwork():
|
||||||
|
usableNet = candidateNet
|
||||||
|
|
||||||
|
# check if there are still networks left in range
|
||||||
if not usableNet:
|
if not usableNet:
|
||||||
# search for free network
|
# search for free network
|
||||||
nets = list(parentRange.getNetwork().subnets())
|
nets = list(parentRange.getNetwork().subnets())
|
||||||
|
|
Loading…
Reference in New Issue