Repository navigation
Conversation
Send the 'X-NetBox-Branch: <schema_id>' header on every NetBox API request when 'branch_schema_id' is set in the [netbox] section, so all reads and writes target the given branch. The header is set once on the shared requests.Session in NetBoxHandler.create_session(). Also available via the NBS_NETBOX_BRANCH_SCHEMA_ID environment variable. Co-authored-by: bragenr <bragenr@users.noreply.github.com>
The X-NetBox-Branch header only accepts the branch schema ID, so branch_name and branch_id are resolved to the schema ID via the branching plugin API (/api/plugins/branching/branches/) at startup, before the header is set. The three options are mutually exclusive and validated in the config. Caching is disabled automatically when a branch is used, since main-schema cache data must not be mixed with branch data. Co-authored-by: bragenr <bragenr@users.noreply.github.com>
bragenr
force-pushed
the
feature/netbox-branch-header
branch
from
November 20, 2026 11:27
9902e62 to
21f6604
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for the NetBox Branching plugin. When a branch is configured in the
[netbox]section, every NetBox API request carries theX-NetBox-Branch: <schema_id>header, so all reads and writes are performed inside that branch. Branch selection via the REST API is stateless, which is why the header must be sent on every request.Related feature request: #508
Changes
module/netbox/config.py: new optional[netbox]settingsbranch_schema_id,branch_nameandbranch_id. Mutually exclusive, rejected by config validation if more than one is set. Also available as env vars (NBS_NETBOX_BRANCH_SCHEMA_ID,NBS_NETBOX_BRANCH_NAME,NBS_NETBOX_BRANCH_ID).module/netbox/connection.py: newNetBoxHandler.setup_branch_header()called right after the sharedrequests.Sessionis created. TheX-NetBox-Branchheader only accepts the branch's 8-char schema ID (verified against the plugin source), sobranch_name/branch_idare first resolved to the schema ID via/api/plugins/branching/branches/on the main schema, before any branch header is set. Clear fatal errors for 404 (plugin not installed), 403 (token permission), unknown branch names. The header is set once on the shared session, so it covers all queries, creates, updates and prune/delete. When a branch is active, caching is auto-disabled with a warning (main-schema cache must not mix with branch data).settings-example.ini: regenerated withpython3 netbox-sync.py -g(only the new documented options added).tests/test_netbox_branch_header.py: 10 new tests — header behavior, name/ID resolution, error paths, caching switch-off, config validation.Configuration
Verification
python -m pytest: 247 passed, 46 skipped (skips are vcsim integration tests; vcsim not installed here)-n -l DEBUG2) shows theNetBox Branching enabled...log line, then a real sync into a disposable branchNotes for reviewers
prune_enabled = falserecommended for initial branch tests.branch_name/branch_idrequire the netbox-branching plugin and a token with read permission on branching branches.