Netbox Update Interfaces Description Task¤
task api name:
update_interfaces_description
Updates the description field of interfaces, console ports, and console server ports for one or more devices in NetBox. Supports two mutually usable modes: template mode (description_template) renders descriptions dynamically using Jinja2 with live connection context, and static mode (descriptions) applies a fixed mapping of interface names to description strings.
How it Works¤
- Client submits
update_interfaces_descriptionrequest to NetBox worker - Worker resolves the target NetBox instance and optionally the branch
- If
description_templateis provided, the worker fetches all interface connections for the given devices viaget_connections - For each interface, the Jinja2 template is rendered with the connection context (device, interface, remote device, cable attributes, etc.)
- If
descriptionsdict is provided, the worker iterates over the given device list and applies the fixed description values directly - In dry-run mode — the before (
-) / after (+) diff is returned without writing to NetBox - Otherwise, the new description is saved to NetBox
Prerequisites¤
- The devices must already exist in NetBox.
- Only interfaces, console ports, console server ports and power outlet ports are supported as port types.
Branching Support¤
update_interfaces_description is branch-aware. Pass branch=<name> to write all changes into a NetBox Branching Plugin branch instead of main.
Dry Run Mode¤
dry_run=True returns the before/after description diff without any NetBox writes:
{
"<device>": {
"<interface>": {
"-": "<current description>",
"+": "<new description>",
},
...
},
...
}
Template Mode¤
When description_template is provided, the Jinja2 template is rendered once per interface using the full connection context. The template can be an inline string or a remote NorFab file reference (nf://path/to/template.txt).
Jinja2 context variables available in the template:
device— pynetboxdcim.deviceobjectinterface— pynetbox interface/console port/console server port objectremote_device— stringremote_interface— stringtermination_type— stringcable— dictionary of directly attached cable attributes:typestatustenant— dictionary{name: tenant_name}labeltags— list of{name: tag_name}dictionariescustom_fields— dictionary with custom fields datapeer_termination_typepeer_devicepeer_interface
Example template:
{{ remote_device }}:{{ remote_interface }}
Static Mode¤
When descriptions dict is provided, the same mapping is applied to all devices in the devices list. Only interfaces that exist in NetBox are updated — missing interfaces are silently skipped.
descriptions = {
"Ethernet1": "uplink to spine-1",
"Ethernet2": "uplink to spine-2",
}
Examples¤
Update interface descriptions using a Jinja2 template:
nf#netbox update interfaces description devices ceos-leaf-1 description-template "{{ remote_device }}:{{ remote_interface }}"
Filter interfaces by regex pattern:
nf#netbox update interfaces description devices ceos-leaf-1 description-template "{{ remote_device }}:{{ remote_interface }}" interface-regex "Ethernet.*"
Dry run — preview changes without writing:
nf#netbox update interfaces description devices ceos-leaf-1 description-template "{{ remote_device }}:{{ remote_interface }}" dry-run
Update descriptions in a NetBox branch:
nf#netbox update interfaces description devices ceos-leaf-1 description-template "{{ remote_device }}:{{ remote_interface }}" branch my-branch
from norfab.core.nfapi import NorFab
nf = NorFab(inventory="./inventory.yaml")
nf.start()
client = nf.make_client()
# update descriptions using a Jinja2 template
result = client.run_job(
"netbox",
"update_interfaces_description",
workers="any",
kwargs={
"devices": ["ceos-leaf-1", "ceos-leaf-2"],
"description_template": "{{ remote_device }}:{{ remote_interface }}",
},
)
# filter interfaces by regex and use a remote template
result = client.run_job(
"netbox",
"update_interfaces_description",
workers="any",
kwargs={
"devices": ["ceos-leaf-1"],
"description_template": "nf://templates/intf_desc.j2",
"interface_regex": "Ethernet.*",
},
)
# dry run — preview diff without writing
result = client.run_job(
"netbox",
"update_interfaces_description",
workers="any",
kwargs={
"devices": ["ceos-leaf-1"],
"description_template": "{{ remote_device }}:{{ remote_interface }}",
"dry_run": True,
},
)
# static descriptions dict applied to multiple devices
result = client.run_job(
"netbox",
"update_interfaces_description",
workers="any",
kwargs={
"devices": ["ceos-leaf-1", "ceos-leaf-2"],
"descriptions": {
"Ethernet1": "uplink to spine-1",
"Ethernet2": "uplink to spine-2",
},
},
)
# update into a NetBox branch
result = client.run_job(
"netbox",
"update_interfaces_description",
workers="any",
kwargs={
"devices": ["ceos-leaf-1"],
"description_template": "{{ remote_device }}:{{ remote_interface }}",
"branch": "my-branch",
},
)
nf.destroy()
NORFAB Netbox Update Interfaces Description Command Shell Reference¤
NorFab shell supports these command options for the Netbox update_interfaces_description task:
nf# man tree netbox.update.interfaces.description
root
└── netbox: Netbox service
└── update: Update Netbox objects
└── interfaces: Update interfaces
└── description: Updates the description of interfaces for specified devices in NetBox
├── timeout: Job timeout
├── workers: Filter worker to target, default 'any'
├── verbose-result: Control output details, default 'False'
├── progress: Display progress events, default 'True'
├── instance: Netbox instance name to target
├── branch: Branching plugin branch name to use
├── dry-run: Return diff without writing to NetBox
├── devices: Device names to update interfaces for
├── description-template: Jinja2 template to render descriptions
└── interface-regex: Regex pattern to match interfaces and ports
nf#
Python API Reference¤
Updates the description of interfaces for specified devices in NetBox.
This method retrieves interface connections for the given devices, renders new descriptions using a Jinja2 template, and updates the interface descriptions in NetBox accordingly.
Only interfaces, console ports and console server ports supported.
Jinja2 environment receives these context variables for description template rendering:
- device - pynetbox
dcim.deviceobject - interface - pynetbox object -
dcim/interface,dcip.consoleport,dcim.consoleserverport- depending on what kind of interface is that. - remote_device - string
- remote_interface - string
- termination_type - string
- cable - dictionary of directly attached cable attributes:
- type
- status
- tenant - dictionary of
{name: tenant_name} - label
- tags - list of
{name: tag_name}dictionaries - custom_fields - dictionary with custom fields data
- peer_termination_type
- peer_device
- peer_interface
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job
|
Job
|
The job context for logging and event handling. |
required |
devices
|
list
|
List of device names to update interfaces for. |
required |
description_template
|
str
|
Jinja2 template string for the interface description.
Can reference remote template using |
None
|
descriptions
|
dict
|
Dictionary keyed by interface names with values being interface description strings |
None
|
interfaces
|
Union[None, list]
|
Specific interfaces to update. |
None
|
interface_regex
|
Union[None, str]
|
Regex pattern to filter interfaces. |
None
|
instance
|
Union[None, str]
|
NetBox instance identifier. |
None
|
dry_run
|
bool
|
If True, performs a dry run without saving changes. |
False
|
timeout
|
int
|
Timeout for NetBox API requests. |
60
|
branch
|
str
|
Branch name for NetBox instance. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Result |
Result
|
An object containing the outcome of the update operation, including before and after descriptions. |
Source code in norfab\workers\netbox_worker\interfaces_tasks.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 | |