Fetching the Next /31 Prefix in a Larger Prefix #17937
Replies: 1 comment 1 reply
-
If you look at the source of
Therefore you could call get_available_prefixes(), iterate over them ignoring any which are not /31, and take the first which is /31. However, I think you might have misunderstood what
This returns all the address space which is not consumed by a child prefix in the database. So for example, if the prefix is 192.0.2.0/24, and there's also a prefix 192.0.2.0/26 in Netbox, then the "available prefixes" under 192.0.2.0/24 will cover the space 192.0.2.64 .. 192.0.2.255, which is returned as 192.0.2.64/26 and 192.0.2.128/25 (even though those prefixes don't exist in Netbox). There are no /31's at all, but of course you could allocate a /31 within either of those. So it's not really clear to me what you want:
In the latter case there are various algorithms. A reasonable one (which aims to minimise fragmentation) is to call If there might be multiple prefixes in the database with tag "inter-co" then you should do that across all of them, to minimise fragmentation and to avoid starvation when the first one becomes full. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I'm looking for a way to directly retrieve the next available /31 prefix within a larger prefix in NetBox. Currently, using the following code only returns the next available prefix, but it defaults to a larger size:
In my case, this returns:
However, I specifically need the next available /31 prefix, not a /29. Is there a built-in way to specify the desired prefix length without additional workaround code?
Here's what I’m currently considering as a workaround:
If anyone has a cleaner or more direct approach, I'd greatly appreciate it!
Beta Was this translation helpful? Give feedback.
All reactions