Metadata-Version: 2.4
Name: netbox-windows-dhcp
Version: 1.0.1
Summary: NetBox plugin for full integration with Windows DHCP Server via PowerShell Universal
Author-email: Avery Abbott <averyhabbott@yahoo.com>
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship made available under
              the License, as indicated by a copyright notice that is included in
              or attached to the work (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other transformations
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean, as submitted to the Licensor for inclusion
              in the Work by the copyright owner or by an individual or Legal Entity
              authorized to submit on behalf of the copyright owner. For the purposes
              of this definition, "submitted" means any form of electronic, verbal,
              or written communication sent to the Licensor or its representatives,
              including but not limited to communication on electronic mailing lists,
              source code control systems, and issue tracking systems that are managed
              by, or on behalf of, the Licensor for the purpose of discussing and
              improving the Work, but excluding communication that is conspicuously
              marked or designated in writing by the copyright owner as "Not a
              Contribution."
        
              "Contributor" shall mean Licensor and any Legal Entity on behalf of
              whom a Contribution has been received by the Licensor and included
              within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by the combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a cross-claim
              or counterclaim in a lawsuit) alleging that the Work or any such
              Contribution constitutes direct or contributory patent infringement,
              then any patent licenses granted to You under this License for that
              Work shall terminate as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or Derivative
                  Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, You must include a readable copy of the
                  attribution notices contained within such NOTICE file, in
                  at least one of the following places: within a NOTICE text
                  file distributed as part of the Derivative Works; within
                  the Source form or documentation, if provided along with the
                  Derivative Works; or, within a display generated by the
                  Derivative Works, if and wherever such third-party notices
                  normally appear. The contents of the NOTICE file are for
                  informational purposes only and do not modify the License.
                  You may add Your own attribution notices within Derivative
                  Works that You distribute, alongside or in addition to the
                  NOTICE text from the Work, provided that such additional
                  attribution notices cannot be construed as modifying the
                  License.
        
              You may add Your own license statement for Your modifications and
              may provide additional grant of rights to use, copy, modify, merge,
              publish, distribute, sublicense, and/or sell copies of the
              Contribution, either on an "as is" basis, with no warranties or
              conditions of any kind, either express or implied, or under the
              terms and conditions imposed on the Licensee under this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or reproducing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or exemplary damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or all other
              commercial damages or losses), even if such Contributor has been
              advised of the possibility of such damages.
        
           9. Accepting Warranty or Liability. While redistributing the Work or
              Derivative Works thereof, You may choose to offer, and charge a fee
              for, acceptance of support, warranty, indemnity, or other liability
              obligations and/or rights consistent with this License. However, in
              accepting such obligations, You may offer such conditions only on
              Your own behalf and on Your sole responsibility, not on behalf of
              any other Contributor, and only if You agree to indemnify, defend,
              and hold each Contributor harmless for any liability incurred by,
              or claims asserted against, such Contributor by reason of your
              accepting any warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           Copyright 2024 Avery Abbott
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/averyhabbott/netbox-windows-dhcp
Project-URL: Repository, https://github.com/averyhabbott/netbox-windows-dhcp
Project-URL: Bug Tracker, https://github.com/averyhabbott/netbox-windows-dhcp/issues
Keywords: netbox,dhcp,windows,plugin,powershell,ipam,network
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Plugins
Classifier: Framework :: Django
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Dynamic: license-file

# netbox-windows-dhcp

A NetBox v4.5.0+ plugin for full integration with Windows DHCP Server via [PowerShell Universal](https://ironmansoftware.com/powershell-universal) (PSU v5).

## Features

- Define Windows DHCP Servers (hostname, port, HTTP/HTTPS, App Token auth, optional SSL verification)
- Define DHCP Failover relationships (Load Balance or Hot Standby)
- Correlate DHCP Scopes with NetBox Prefixes (many scopes → one prefix)
- Lease lifetime stored in seconds, displayed in the most readable unit (e.g. `3 Days`, `73 Hours`, `30 Minutes`)
- Global library of reusable DHCP Option Values with Option Code Definitions (pre-populated with all standard Windows DHCP built-in codes)
- One-time **Import from Server** — pulls failovers, scopes, scope-level option values, and exclusion ranges from a live DHCP server into NetBox
- Active sync mode: pull leases and reservations → create/update NetBox IP Addresses with status, DNS name, and client MAC
- Stale record cleanup: expired leases and removed reservations are deleted or downgraded automatically
- Push reservations, scope config, and exclusion ranges from NetBox → DHCP server (optional, settings-controlled)
- **DHCP Scopes** panel injected into the NetBox Prefix detail view
- All sync and import operations run as background jobs — no HTTP timeouts on large servers
- All background job changes appear in the NetBox changelog (attributed to the user who queued the job)
- Scheduled background sync (hourly by default, configurable) + manual **Sync Now** per server or for all servers
- Full REST API for all plugin objects
- Plugin-wide settings managed via the NetBox UI (no `PLUGINS_CONFIG` entry required)

## Requirements

### NetBox host

- NetBox >= 4.5.0
- Python >= 3.10
- `requests` >= 2.28
- NetBox RQ workers running (required for background sync and import jobs)

### Each Windows DHCP server

- Windows Server 2016 or later with the **DHCP Server** role installed
- PowerShell Universal **v5.x** (tested on 5.6.11+) — see [PSU Setup](#psu-setup)
- `DhcpServer` PowerShell module (included with the DHCP Server role)

## Installation

### 1. Install the package

```bash
pip install netbox-windows-dhcp
```

Or from source (editable install recommended for development):

```bash
pip install -e /path/to/netbox-windows-dhcp
```

### 2. Add to NetBox configuration (`configuration.py`)

```python
PLUGINS = [
    'netbox_windows_dhcp',
]
```

No `PLUGINS_CONFIG` entry is required. All settings are managed through the plugin's **Admin → Settings** page in the NetBox UI.

### 3. Run migrations

```bash
python manage.py migrate
```

Running migrations also triggers the `post_migrate` signal which auto-registers the `dhcp_client_id` custom field on IP Address objects.

### 4. Restart NetBox

Restart gunicorn/uwsgi and the RQ workers.

## Getting Started

### Add a DHCP Server

1. Go to **Windows DHCP → Infrastructure → Servers → Add**
2. Enter the hostname/IP, port, and PSU App Token
3. Toggle **Use HTTPS** as appropriate (default: on)
4. Disable **Verify SSL Certificate** if the server uses a self-signed certificate

### Import from a Server

Once a server is configured, click **Import from Server** on the server detail page to run a one-time background import of:

- Failover relationships (matched to existing DHCP Server objects by hostname)
- Scopes (NetBox Prefixes are created automatically if they don't exist)
- Scope-level option values (unknown option codes are created automatically)
  - Option 3 (Router) and Option 51 (Lease Time) are skipped — they are stored directly on the Scope object

You will be redirected to the job status page where you can monitor progress and view the full results log. Existing records are skipped; the import never overwrites data already in NetBox.

### Configure Sync Settings

Go to **Windows DHCP → Admin → Settings** to configure:

| Setting | Description |
| --- | --- |
| Sync IP Addresses from Leases & Reservations | When checked, pull leases and reservations and create/update/delete NetBox IP Address records. When unchecked, sync scope config only. |
| Push Reservations to DHCP Server | Push NetBox `reserved` IPs to the DHCP server as reservations |
| Push Scope Info to DHCP Server | Push scope config changes from NetBox to the DHCP server |
| Sync Interval (minutes) | How often the background sync runs (5–1440) |
| Sync Job Queue | Worker queue priority (`High` / `Default` / `Low`) used for all sync and import background jobs. Default: `Default`. |
| Sync-Protected Tag | A NetBox tag. Any IP Address carrying this tag is fully shielded from sync — its status, DNS name, and record itself are never modified or removed. Leave blank to disable. |
| Update Client ID for Protected IPs | When enabled, the sync updates the `dhcp_client_id` custom field on protected IPs to match the DHCP server's active lease. All other sync writes remain blocked. Useful after a server replacement when the client MAC changes. |

## Editing Rules

Not all objects in the plugin support full CRUD. The table below summarises what operations are allowed and under what conditions.

### Failover Relationships

| Operation | Allowed |
| --- | --- |
| View | ✅ Always |
| Delete | ✅ Always |
| Create | ❌ Never — import from the DHCP server |
| Edit | ✅ Via direct URL only (not exposed in the UI) |

Failover relationships are created automatically during an **Import from Server** run. The **Add** button and **Edit** button are intentionally hidden from the list and detail views — relationships should be managed on the DHCP server and imported into NetBox. The **Sync Enabled** toggle on the list view is the primary way to manage a failover relationship after import.

### DHCP Scopes

| Operation | Push Scope Info **off** | Push Scope Info **on** |
| --- | --- | --- |
| View | ✅ | ✅ |
| Create | ❌ | ✅ |
| Edit | ❌ | ✅ |
| Delete | ❌ | ✅ |

When **Push Scope Info to DHCP Server** is disabled, the DHCP server is the source of truth for scope configuration. Scopes reach NetBox via **Import from Server** and are kept up to date by periodic sync. Direct edits are blocked to prevent NetBox from drifting out of sync with the server.

When **Push Scope Info to DHCP Server** is enabled, NetBox becomes the source of truth. Scope changes saved in NetBox are pushed to the DHCP server on the next sync. Full CRUD is permitted.

> **Note:** Exclusion Ranges follow scope info — create, edit, and delete are permitted whenever **Push Scope Info** is enabled, and blocked when it is disabled.

### IP Address Status Validation

Any IP Address with status `dhcp` must satisfy both of the following conditions when saved through the UI or REST API:

1. The IP address must fall within the prefix of at least one configured DHCP Scope.
2. The IP address must **not** fall within any exclusion range of that scope.

This validation runs during form submission and API writes. It does **not** run during background sync — the sync sets statuses based on authoritative data from the DHCP server and bypasses this check by design.

The `reserved` status is not validated against DHCP scope membership — it is a general-purpose NetBox status used for both DHCP reservations and non-DHCP purposes.

There are no UI-level restrictions on editing IP addresses with `dhcp` or `reserved` status beyond the above. Changes made manually to DHCP-managed IPs will be overwritten on the next sync if **Sync IP Addresses from Leases & Reservations** is enabled.

## Scope Source

Every DHCP Scope must be associated with exactly one of:

- **Server** — for standalone scopes that are not part of a failover relationship. Set automatically during **Import from Server** when the scope has no failover name.
- **Failover Relationship** — for scopes managed under a Windows DHCP failover pair.

This association determines which server is responsible for syncing the scope. Standalone scopes are only synced against their assigned server; failover scopes are synced via the primary server of their failover relationship.

## Sync Behavior

### Scope eligibility

Not every scope is synced on every server. Before processing a scope, the sync checks eligibility:

| Scope type | Synced when |
| --- | --- |
| Standalone (has Server) | Server's **Sync Standalone Scopes** is enabled, and the scope's assigned server matches the server being synced |
| Failover-linked | The failover relationship's **Sync Enabled** is on, and the server being synced is the **primary** of that failover |
| Neither assigned | Never synced |

**Server pre-flight:** If a server has **Sync Standalone Scopes** disabled and is not the primary server for any active failover relationship, the sync skips it entirely — no network connection is made.

### Per-failover sync control

Each failover relationship has a **Sync Enabled** toggle (visible on the failover list and toggleable per-row). When disabled, all scopes using that failover are excluded from sync. This allows pausing sync for a specific failover pair without affecting others.

### IP Address sync

When **Sync IP Addresses from Leases & Reservations** is unchecked (default), the sync pulls and stores scope config only — no IP Address objects are created or modified.

When checked, the sync pulls leases and reservations from each DHCP server and creates/updates/deletes NetBox IP Address records.

### IP Address lifecycle (active sync)

**Creating and updating:**

| Source | `IPAddress.status` | `dns_name` | `dhcp_client_id` |
| --- | --- | --- | --- |
| Active DHCP lease | `dhcp` | Hostname from DHCP (lowercased) | Client MAC address |
| DHCP reservation | `reserved` | Name from reservation (lowercased) | Client MAC address |

Reservations take precedence — a `reserved` IP is not overwritten by a lease record for the same address.

**Special case — `reserved` IP with no `dhcp_client_id`:** If a `reserved` IP address has no `dhcp_client_id` set (e.g. it was manually created before the client MAC was known), and a lease is discovered on the DHCP server for that address, the sync will populate `dhcp_client_id` from the lease but will not change the status or `dns_name`. This allows the IP to be pre-registered before provisioning.

New IP Addresses are created using the prefix length of the associated scope's NetBox Prefix (not `/32`).

The `dhcp_client_id` custom field (auto-registered on IP Address) stores the client MAC address in Windows DHCP hyphen-separated format (`00-11-22-33-44-55`).

All IP Address creates and updates are recorded in the NetBox changelog, attributed to the user who queued the sync job. DHCP lease metadata (lease hostname, active status, expiration) is stored in a separate non-changelog side-table (`DHCPLeaseInfo`) and displayed on the IP Address detail page — these updates do not generate changelog entries.

**Cleanup (stale record removal):**

After syncing leases and reservations for a scope, the plugin removes records that no longer exist on the server:

| NetBox status | `dhcp_client_id` | DHCP-managed? | Server state | Action |
| --- | --- | --- | --- | --- |
| `dhcp` | — | — | Lease still active | No change |
| `dhcp` | — | — | Lease expired or gone | Deleted |
| `reserved` | — | — | Any | Never auto-deleted (pre-staged or manual) |
| `reserved` | set | No (manually created) | Any | Never auto-deleted |
| `reserved` | set | Yes (sync-created) | Reservation still exists | No change |
| `reserved` | set | Yes (sync-created) | No reservation, but lease exists | Downgraded to `dhcp` |
| `reserved` | set | Yes (sync-created) | Neither reservation nor lease | Deleted |

"DHCP-managed" means the record was created or previously updated by the sync (indicated by a `DHCPLeaseInfo` side-record). Manually-created `reserved` IPs are never auto-deleted even if they have a `dhcp_client_id`.

> **Note:** When **Push Reservations to DHCP Server** is enabled, NetBox is the source of truth for reservations. `reserved` IP Addresses with a `dhcp_client_id` are never deleted or downgraded based on server state — they will be pushed to the server on the next sync instead.

**Scope cleanup:**

When a scope exists in NetBox but is no longer reported by the DHCP server, and the server was successfully reached, and **Push Scope Info to DHCP Server** is disabled, the scope is deleted from NetBox. Only scopes whose Scope Source links them to the server being synced (either directly as a standalone scope, or via a failover relationship where this server is primary) are considered.

> When **Push Scope Info to DHCP Server** is enabled, a scope missing from the server will instead be created on the server.

**Safety:** If the API call to fetch leases/reservations fails for a scope, cleanup is skipped for that scope. If `list_scopes()` fails entirely, the server is unreachable and no cleanup runs at all.

### Pre-Staging IPs

To register a device in NetBox before its client MAC is known, create the IP Address with:

- Status `reserved`
- `dns_name` set to the planned canonical hostname
- Leave `dhcp_client_id` blank

The sync will never delete or overwrite the status or `dns_name` of a `reserved` IP with no `dhcp_client_id`. If a lease appears on the DHCP server for that address, the sync populates `dhcp_client_id` from the lease (so the reservation can be pushed once the MAC is known) but leaves everything else unchanged.

**Typical lifecycle:**

1. Create the IP in NetBox with status `reserved`, `dns_name` set to the planned hostname, and no `dhcp_client_id`.
2. Device is provisioned; it receives a DHCP lease. The sync populates `dhcp_client_id` from the lease.
3. Once `dhcp_client_id` is set, the reservation is pushed to the DHCP server on the next sync (if **Push Reservations** is enabled). The `dns_name` is used as the reservation name on the server.

### Sync-Protected IPs

Any IP Address tagged with the configured **Sync-Protected Tag** is fully shielded from sync writes. The sync will never change its status, DNS name, or `dhcp_client_id`, and will never delete the record during cleanup.

DHCP lease metadata (`DHCPLeaseInfo`) is always updated for protected IPs regardless of protection status — the lease hostname, active state, and expiration are still recorded and visible on the IP Address detail page.

#### Update Client ID for Protected IPs

Enable this checkbox to allow one narrow exception: the sync may update the `dhcp_client_id` custom field on a protected IP when the server's active lease carries a different client MAC. All other writes (status, DNS name, record deletion) remain blocked. This is useful after a DHCP server replacement where the client MAC for the same device changes.

**Typical use:** Tag an IP as protected when it has been manually configured and should not be overwritten by automated sync, even if the DHCP server has a conflicting record.

### Sync Now

The **Sync Now** button on a server detail page enqueues a background sync job and redirects to the job status page. The full sync log is visible there. A **Sync All Servers** action is also available from the server list page.

## Lease Lifetime Display

Lease lifetimes are stored in seconds and displayed in the most readable exact unit:

- `86400` → **1 Day**
- `259200` → **3 Days**
- `262800` → **73 Hours** (not an exact number of days)
- `3600` → **1 Hour**
- `60` → **1 Minute**
- `45` → **45 Seconds**

When configuring a scope, enter the value and select the unit (Seconds / Minutes / Hours / Days). The form defaults to **1 Day** for new scopes. Values learned from the DHCP server are automatically decomposed to the largest clean unit.

## Navigation

The plugin adds a **Windows DHCP** menu to the NetBox left sidebar:

- **Infrastructure** → Servers, Failover
- **Scopes** → Scopes
- **Options** → Option Values, Option Code Definitions
- **Admin** → Settings

## PSU Setup

See [psu/README.md](psu/README.md) for full deployment instructions.

The plugin expects PowerShell Universal **v5.x** (tested on 5.6.11+) on each DHCP server, exposing endpoints under `/api/dhcp/`. The PSU script is at `psu/dhcp_api_endpoints.ps1`.

### Endpoint reference

| Method | Path | Description |
| --- | --- | --- |
| GET | `/api/dhcp/scopes` | List all scopes (includes router and failover name) |
| GET | `/api/dhcp/scopes/:scope_id` | Get a single scope |
| POST | `/api/dhcp/scopes` | Create a scope |
| PUT | `/api/dhcp/scopes/:scope_id` | Update a scope |
| GET | `/api/dhcp/leases[?scope_id=]` | List active leases |
| GET | `/api/dhcp/reservations[?scope_id=]` | List reservations |
| POST | `/api/dhcp/reservations` | Create a reservation |
| PUT | `/api/dhcp/reservations/:client_id` | Update a reservation |
| DELETE | `/api/dhcp/reservations/:client_id` | Delete a reservation |
| GET | `/api/dhcp/failover` | List failover relationships |
| POST | `/api/dhcp/failover` | Create a failover relationship |
| GET | `/api/dhcp/options/server` | Server-level option values |
| GET | `/api/dhcp/options/scope/:scope_id` | Scope-level option values |
| GET | `/api/dhcp/exclusions?scope_id=` | List exclusion ranges for a scope |
| POST | `/api/dhcp/exclusions` | Create an exclusion range |
| DELETE | `/api/dhcp/exclusions` | Delete an exclusion range (body: scope_id, start_ip, end_ip) |

Authentication: PSU v5 App Tokens are sent as `Authorization: Bearer <token>`. Generate a token in the PSU admin console under **Security → App Tokens** and paste it into the **App Token** field on the DHCP Server object in NetBox.

## REST API

The plugin exposes a REST API under `/api/plugins/netbox-windows-dhcp/`:

| Endpoint | Model |
| --- | --- |
| `/servers/` | DHCP Servers |
| `/failover/` | Failover relationships |
| `/option-codes/` | Option Code Definitions |
| `/option-values/` | Option Values |
| `/scopes/` | DHCP Scopes (includes nested `exclusion_ranges`) |
| `/exclusion-ranges/` | DHCP Exclusion Ranges |
