in-between commit

This commit is contained in:
Nico Schottelius 2020-04-11 21:37:36 +02:00
parent d3f2a3e071
commit 50b8b7a5f6

View file

@ -1,4 +1,5 @@
import uuid
import ipaddress
from django.db import models
from django.contrib.auth import get_user_model
@ -65,9 +66,13 @@ class VPNPool(UncloudModel):
free_net = self.vpnnetworkreservation_set.objects.filter(vpnpool=self,
status='free')
last_net = self.vpnnetworkreservation_set.objects.filter(vpnpool=self,
used_net = self.vpnnetworkreservation_set.objects.filter(vpnpool=self,
status='used')
this_net = ipaddress.ip_network("{}/{}".format(
self.network, self.network_size))
if num_free_networks == 0:
raise Exception("No free networks")
@ -84,10 +89,17 @@ class VPNPool(UncloudModel):
next:
"""
last_ip = last_net.address
# next_ip =
last_net = ipaddress.ip_network(self.used_networks.last())
last_net_ip = last_net[0]
if last_net_ip.version == 6:
offset_to_next = 2**(128 - self.subnetwork_size)
elif last_net_ip.version == 4:
offset_to_next = 2**(32 - self.subnetwork_size)
next_net_ip = last_net_ip + offset_to_next
return next_net_ip