[refactor] cleaning up uncloud_net for Wireguardvpn
This commit is contained in:
parent
074cffcbd7
commit
10d5a72c5a
82 changed files with 403 additions and 2180 deletions
|
|
@ -1,7 +1,9 @@
|
|||
from django.db.models import Count
|
||||
from django.db import transaction
|
||||
from django.db.models import Count, F
|
||||
|
||||
|
||||
from .models import *
|
||||
|
||||
@transaction.atomic
|
||||
def get_suitable_pool(subnetwork_size):
|
||||
"""
|
||||
Find suitable pools for a certain network size.
|
||||
|
|
@ -21,3 +23,20 @@ def get_suitable_pool(subnetwork_size):
|
|||
max_reservations=2**(F('subnetwork_size')-F('network_size'))).filter(
|
||||
num_reservations__lt=F('max_reservations'),
|
||||
subnetwork_size=subnetwork_size)
|
||||
|
||||
|
||||
def allowed_vpn_network_reservation_size():
|
||||
"""
|
||||
Find all possible sizes of subnetworks that are available.
|
||||
|
||||
Select all pools with free networks.
|
||||
|
||||
Get their subnetwork sizes, reduce to a set
|
||||
|
||||
"""
|
||||
|
||||
pools = VPNPool.objects.annotate(num_reservations=Count('vpnnetworkreservation'),
|
||||
max_reservations=2**(F('subnetwork_size')-F('network_size'))).filter(
|
||||
num_reservations__lt=F('max_reservations'))
|
||||
|
||||
return set([ pool.subnetwork_size for pool in pools ])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue