mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
12180 available objects api (#12935)
* Introduce AvailableObjectsView and refactor 'available objects' API views * Restore advisory PostgreSQL locks * Move get_next_available_prefix() * Apply OpenAPI decorators for get() and post()
This commit is contained in:
@ -1,7 +1,15 @@
|
||||
import netaddr
|
||||
|
||||
from .constants import *
|
||||
from .models import ASN, Prefix, VLAN
|
||||
from .models import Prefix, VLAN
|
||||
|
||||
__all__ = (
|
||||
'add_available_ipaddresses',
|
||||
'add_available_vlans',
|
||||
'add_requested_prefixes',
|
||||
'get_next_available_prefix',
|
||||
'rebuild_prefixes',
|
||||
)
|
||||
|
||||
|
||||
def add_requested_prefixes(parent, prefix_list, show_available=True, show_assigned=True):
|
||||
@ -184,3 +192,15 @@ def rebuild_prefixes(vrf):
|
||||
|
||||
# Final flush of any remaining Prefixes
|
||||
Prefix.objects.bulk_update(update_queue, ['_depth', '_children'])
|
||||
|
||||
|
||||
def get_next_available_prefix(ipset, prefix_size):
|
||||
"""
|
||||
Given a prefix length, allocate the next available prefix from an IPSet.
|
||||
"""
|
||||
for available_prefix in ipset.iter_cidrs():
|
||||
if prefix_size >= available_prefix.prefixlen:
|
||||
allocated_prefix = f"{available_prefix.network}/{prefix_size}"
|
||||
ipset.remove(allocated_prefix)
|
||||
return allocated_prefix
|
||||
return None
|
||||
|
Reference in New Issue
Block a user