in-between commit
This commit is contained in:
parent
d3f2a3e071
commit
50b8b7a5f6
1 changed files with 15 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue