Add API endpoint for listing and allocating available prefixes within a prefix #1388

Closed
opened 2025-12-29 16:31:58 +01:00 by adam · 2 comments
Owner

Originally created by @jeremystretch on GitHub (Nov 7, 2017).

Issue type

[x] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.2.4

Description

Currently, NetBox provides an API endpoint at /api/ipam/prefixes/<pk>/available-ips/. A GET request will return a list of available IPs within the prefix, and a POST request will automatically create the first available IP. This feature request is to replicate this behavior for child prefixes.

A new API endpoint will be introduced at /api/ipam/prefixes/<pk>/available-prefixes/. A GET request will return an optimized list of available prefixes (similar to the prefixes marked as "available" within the child prefixes table of a parent prefix). For example, a parent prefix of 192.0.2.0/24 with an existing child of 192.0.2.64/26 would return 192.0.2.0/26 and 192.0.2.128/25 as available prefixes.

A POST request to this endpoint will create the first available prefix. Unlike IP addresses, a request to create the next available prefix must specify the desired mask length. For example:

POST /api/ipam/prefixes/1234/available-prefixes/
{
    "mask_length": "24"
}

This would create the first available /24 prefix within the parent, or, if one is not available, return an error (ideally indicating the maximum available size).

Originally created by @jeremystretch on GitHub (Nov 7, 2017). ### Issue type [x] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.2.4 ### Description Currently, NetBox provides an API endpoint at `/api/ipam/prefixes/<pk>/available-ips/`. A GET request will return a list of available IPs within the prefix, and a POST request will automatically create the first available IP. This feature request is to replicate this behavior for child prefixes. A new API endpoint will be introduced at `/api/ipam/prefixes/<pk>/available-prefixes/`. A GET request will return an optimized list of available prefixes (similar to the prefixes marked as "available" within the child prefixes table of a parent prefix). For example, a parent prefix of 192.0.2.0/24 with an existing child of 192.0.2.64/26 would return 192.0.2.0/26 and 192.0.2.128/25 as available prefixes. A POST request to this endpoint will create the first available prefix. Unlike IP addresses, a request to create the next available prefix must specify the desired mask length. For example: ``` POST /api/ipam/prefixes/1234/available-prefixes/ { "mask_length": "24" } ``` This would create the first available /24 prefix within the parent, or, if one is not available, return an error (ideally indicating the maximum available size).
adam added the type: feature label 2025-12-29 16:31:58 +01:00
adam closed this issue 2025-12-29 16:31:58 +01:00
Author
Owner

@dirtycajunrice commented on GitHub (Nov 8, 2017):

This. Meant to put this in a week ago.

@dirtycajunrice commented on GitHub (Nov 8, 2017): This. Meant to put this in a week ago.
Author
Owner

@jeremystretch commented on GitHub (Nov 9, 2017):

I've got this working for the most part, but I want to use serializers for validation of the request data.

@jeremystretch commented on GitHub (Nov 9, 2017): I've got this working for the most part, but I want to use serializers for validation of the request data.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1388