Skip to content

marcinpsk/Device-Type-Library-Import

 
 

Repository files navigation

NetBox Device Type Import

Tests NetBox main NetBox Python

This library is intended to be your friend and help you import all the device-types defined within the NetBox Device Type Library Repository.

Tested working with NetBox 3.2+ through 4.5+ (weekly CI run against NetBox main)


⚠️ direnv users — This repo ships a .envrc.example file. If you use direnv, review the file before enabling it:

cp .envrc.example .envrc
cat .envrc          # confirm it only loads .env vars and syncs uv
direnv allow

The file exclusively loads variables from .env into your shell and runs uv sync to keep dependencies up to date. Your .envrc is git-ignored.

Description

This script will clone a copy of the netbox-community/devicetype-library repository to your machine to allow it to import the device types you would like without copy and pasting them into the NetBox UI.

Getting Started

  1. Install dependencies with uv:

    uv sync
  2. Copy .env.example to .env and fill in your NetBox URL and API token (the token needs write rights):

    cp .env.example .env
    vim .env
  3. Run the script:

    uv run nb-dt-import.py

Usage

Running the script clones (or updates) the netbox-community/devicetype-library repository into the repo subdirectory (configurable via REPO_PATH), then loops over every manufacturer and device, creating anything that is missing from NetBox while skipping entries that already exist.

Environment Variables

Variable Required Default Description
NETBOX_URL URL of your NetBox instance
NETBOX_TOKEN API token with write access
REPO_URL community library Git URL of the device-type library to clone
REPO_BRANCH master Branch to check out
REPO_PATH ./repo Local path where the library is cloned. Accepts absolute or relative paths.
IGNORE_SSL_ERRORS False Set True to skip TLS verification (dev only)
GRAPHQL_PAGE_SIZE 5000 Items per GraphQL page
PRELOAD_THREADS 8 Threads for concurrent component preloading

⚠️ Tokens: Please note there is a difference in setting the token based on whether you are using v1 or v2 tokens

For v1, your token will simply be the secret part generated when you create the api token in netbox:

NETBOX_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

For v2 tokens, you need to include prefix "nbt_", the bearer key (represented here by capital X-es), a dot, and finally the secret token (represented by lowercase x-es):

NETBOX_TOKEN=nbt_XXXXXXXXXXXX.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Arguments

This script provides ways to selectively import devices via --vendors and --slugs arguments.

To import only devices from one vendor, or multiple vendors:

uv run nb-dt-import.py --vendors apc
uv run nb-dt-import.py --vendors apc,juniper

--slugs does partial matching on each device type's slug and supports multiple values:

uv run nb-dt-import.py --slugs x440-g2            # Imports 11 network switch device type variations
uv run nb-dt-import.py --slugs ap4433a,ap7526     # Imports two specific PDUs

--vendors and --slugs can be combined:

uv run nb-dt-import.py --vendors "Palo Alto" --slugs 440

Update Mode

By default, the script only creates new device types and skips existing ones. To update existing device types:

uv run nb-dt-import.py --update

This will:

  • Add new components (interfaces, power ports, etc.) that are in YAML but missing from NetBox
  • Update properties of existing components if they've changed
  • Update device type properties (u_height, part_number, etc.) if they've changed
  • Report components that exist in NetBox but are missing from YAML (won't delete by default)

Component Removal (Use with Caution)

WARNING: Removing components can affect existing device instances in NetBox.

If you've changed a device type definition (for example, converting interfaces to module-bays to support SFP modules), you can remove obsolete components with:

uv run nb-dt-import.py --update --remove-components

This will delete any components (interfaces, ports, bays, etc.) that exist in NetBox but are no longer present in the YAML definition.

Use cases:

  • Converting fixed interfaces to module-bays for modular devices
  • Removing incorrectly defined components from device templates
  • Cleaning up after major device type definition changes

Important considerations:

  • Components attached to actual device instances may prevent deletion
  • Review the change detection report before enabling component removal
  • Test on a staging NetBox instance first if possible

Contributing

We're happy about any pull requests!

License

MIT

About

This library is intended to assist with importing device and module types into NetBox from the NetBox Community DeviceType-Library

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

No contributors

Languages

  • Python 99.5%
  • Other 0.5%