ADR - NetBox sync_bgp_community Task Plan¤
Status¤
Accepted on 31 August 2026.
Goal¤
Add a small standalone NetBox task named sync_bgp_community. It collects live
BGP communities with the TTP Templates bgp_communities getter, groups records
by community value, and reconciles:
rtvalues with NetBox IPAM route targets;- every non-
rtvalue with NetBox BGP plugin communities.
Different community-set names observed for the same value are stored in the
community_name custom field as a comma-separated string.
Design¤
- Add
bgp_community_tasks.pywith aNetboxBgpCommunityTasksmixin and a decoratedsync_bgp_communitytask. - Reuse the common NetBox and Nornir arguments:
instance,branch,devices, host filters,timeout,dry_run, andwith_approval. - Run Nornir
parse_ttponce withget="bgp_communities"and the selected devices. - Normalize live data into two dictionaries keyed by
value. Deduplicate and sort each value's getternameentries before joining them with", ". - Check for the NetBox BGP plugin, then fetch IPAM route targets and, when the
plugin is installed, BGP plugin communities. Without the plugin, skip all
non-
rtrecords and synchronize route targets only. - Compare live and NetBox state through the existing
self.make_diff()helper, which uses DeepDiff. Return separateroute_targetsandcommunitiesactions. - On write runs, bulk-create missing objects and append missing live names to
the
community_namecustom field. Existing custom-field values are preserved. Do not rename route targets or modify other fields. - Report malformed records without making writes for them.
The first implementation will not delete NetBox objects. A missing live record does not prove that a globally shared community is stale.
Models and Interfaces¤
- Add
SyncBgpCommunityInputandSyncBgpCommunityResulttonetbox_models.py. - Register the mixin in
netbox_worker.py. - Add the NFCLI command
netbox sync bgp-communitiesusing the same thin shell pattern assync_vrfs. - Do not add the task to
sync_allorcheck_syncin this change.
Documentation and Tests¤
- Add a task page with inputs, output, CLI and Python examples, then register it
in
mkdocs.yml. - Update
docs/norfab_features.md, its Last updated date, and the 0.22.0 changelog entry. - Add a focused
tests/services/netbox/test_sync_bgp_community.pysuite covering dry-run, create, alias aggregation across devices, update, idempotency, branch forwarding, malformed results, and no deletions. - Add minimal FakeNOS command output to two existing simulated devices so the same value is returned under different community-set names.
- Add one pytest marker and run the focused tests, Ruff, and relevant docs checks.
Planned Files¤
norfab/workers/netbox_worker/bgp_community_tasks.pynorfab/workers/netbox_worker/netbox_models.pynorfab/workers/netbox_worker/netbox_worker.pynorfab/clients/nfcli_shell/netbox/netbox_picle_shell_sync_bgp_community.pynorfab/clients/nfcli_shell/netbox/netbox_picle_shell.pytests/services/netbox/test_sync_bgp_community.py- two existing FakeNOS device YAML files
pyproject.toml,mkdocs.yml, the task documentation, feature catalogue, and changelog
Decisions¤
- Store the getter's live community-set
namevalues, not device names. - Store
rtin IPAM and all other getter types in the BGP plugin. - Never delete objects.
- Use optional argument
community_name_field, defaulting tocommunity_name. If the configured field does not exist, continue without synchronizing community names. - When an object already exists, split the current custom-field value by comma, strip spaces, append missing live names, and skip updates when all live names are already present.