agentsclimarketplace

Netbox data modeling

Skill netboxlabs/skills/skills/netbox-data-modeling

Design and manage NetBox data models effectively. Covers site/location hierarchy, IPAM organization, device modeling, tenant assignment, custom fields vs tags vs config contexts, dependency ordering, and relationship patterns. Use when planning NetBox data structure, importing bulk data, or choosing between extensibility mechanisms.From its SKILL.md

Install
npx -y skills add netboxlabs/skills --skill netbox-data-modeling

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as Apache-2.0. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

13.6 KB, as published. Nobody here has run it

NetBox Data Modeling

Your knowledge of NetBox data models may be outdated. Available model types, field options, and relationship patterns evolve between releases. Prefer retrieval over pre-trained knowledge.

Retrieval Sources

SourceURL / MethodUse for
Data model docshttps://netboxlabs.com/docs/netbox/models/All model types and fields
Custom fields docshttps://netboxlabs.com/docs/netbox/customization/custom-fields/Field types, validation, filtering
NetBox repohttps://github.com/netbox-community/netboxModel source code, migrations
NetBox MCP serverIf configured — explore existing data model, inspect object schemasDiscover current structure

When to Use This Skill

Load this skill when you need to:

  • Design a NetBox data model from scratch or extend an existing one
  • Choose between custom fields, tags, and config contexts
  • Plan bulk data imports (dependency ordering)
  • Understand object relationships and hierarchy patterns
  • Model sites, IPAM, devices, or tenancy

For API mechanics (authentication, pagination, error handling), see netbox-api-integration.

NetBox Model Architecture

Base Model Classes

Every NetBox object inherits from one of three base classes:

Base ClassPurposeExamplesKey Traits
PrimaryModelReal infrastructure objectsDevice, Site, Prefix, RackHas description, comments, owner
OrganizationalModelCategorization/taxonomyRIR, IPAM Role, ClusterTypeUnique name + slug
NestedGroupModelRecursive hierarchiesRegion, Location, DeviceRoleParent FK to self (MPTT tree)

All three inherit from NetBoxModel, which provides: custom fields, tags, export templates, custom links, bookmarks, journaling, change logging, notifications, event rules. Every model you interact with has these features.

NetBox 4.5: DeviceRole and Platform changed from OrganizationalModel to NestedGroupModel — they now support parent-child hierarchies.

App Structure

AppScopeKey Models
dcimPhysical infrastructureRegion, Site, Location, Rack, Device, DeviceType, Manufacturer, DeviceRole, Platform, Interface, MACAddress
ipamIP addressingRIR, Aggregate, Prefix, IPAddress, IPRange, VRF, VLAN, VLANGroup, ASN
circuitsConnectivityProvider, Circuit, CircuitGroup, VirtualCircuit
tenancyOwnershipTenantGroup, Tenant, Contact, ContactAssignment
virtualizationVMsClusterType, Cluster, VirtualMachine, VMInterface, VirtualDisk
vpnTunnels/VPNsTunnel, TunnelGroup, L2VPN, IKE/IPSec policies
wirelessWirelessWirelessLAN, WirelessLANGroup, WirelessLink

See references/model-map.md for the complete relationship map.

Core Design Patterns

1. Site & Location Hierarchy

Region (geographic, recursive)    SiteGroup (functional, recursive)
         \                              /
          └──────── Site ──────────────┘
                      │
                  Location (recursive, within site)
                      │
                    Rack → Device
  • Regions = geography: continent → country → metro
  • SiteGroups = function: production, staging, lab, edge
  • Site = a physical facility; optionally assigned to one Region AND/OR one SiteGroup
  • Locations = subdivisions within a site: building → floor → room → row
  • Use Regions when you need geographic filtering/reporting
  • Use SiteGroups when you need functional grouping across geographies
  • Both are optional — start simple, add hierarchy when filtering demands it

See references/model-map.md for the complete relationship map and hierarchy design guidance.

2. IPAM Organization

RIR → Aggregate (top-level allocation, e.g., 10.0.0.0/8)
         └── Prefix (auto-nests by CIDR containment)
               ├── child Prefixes
               ├── IPRange
               └── IPAddress

VRF ──── scopes Prefixes, IPAddresses, IPRanges
VLAN ←── linked to Prefix (optional)

Key rules:

  • Use status=container for summary/aggregate prefixes, status=active for allocated
  • VRF=null means global routing table. Use VRFs for overlapping address spaces
  • Set enforce_unique=True on VRFs to prevent duplicate prefixes
  • Prefixes auto-nest: creating 10.0.1.0/24 inside existing 10.0.0.0/16 builds the tree automatically

Scope pattern (4.x): Prefixes and VLANGroups use CachedScopeMixin — a generic FK (scope_type + scope_id) rather than a direct site FK. VLANGroup scope accepts Region, SiteGroup, Site, Location, Rack, ClusterGroup, Cluster (this full set since 4.5), plus RackGroup as of 4.6.

# Setting scope via API
{"prefix": "10.0.1.0/24", "scope_type": "dcim.site", "scope_id": 42}

3. Device Modeling

Manufacturer → DeviceType (template with component templates)
                              ↓ (instantiation)
DeviceRole + Site + DeviceType → Device (with auto-created components)
  • DeviceType defines the hardware template: interface templates, power ports, module bays
  • Creating a Device auto-creates components from its DeviceType's templates
  • Modules extend devices: module types define additional component templates inserted into module bays
  • DeviceRole (4.5: hierarchical) — use for config context matching and classification
  • Platform (4.5: hierarchical) — OS/firmware family; optionally tied to a Manufacturer

NetBox 4.5: MACAddress is now a standalone model, not just a field on Interface.

4. Tenant Assignment

Tenant is an optional FK on nearly every PrimaryModel: Site, Device, Rack, Prefix, VLAN, VRF, Circuit, VM, Cluster, IPAddress, etc.

Pattern: TenantGroup (hierarchy) → Tenant → assign to objects

Use cases:

  • MSP customer segregation
  • Internal department ownership
  • Cost center tracking

Anti-pattern: Don't overload Tenant for two dimensions (e.g., both "customer" and "department"). Use Tenant for the primary ownership dimension; use custom fields or tags for secondary dimensions.

5. Contact Assignment

Contacts use a generic relation pattern: ContactAssignment links any object to a Contact with a ContactRole.

Contact + ContactRole + any object → ContactAssignment

ContactGroups organize contacts hierarchically. Multiple contacts with different roles can be assigned to the same object.

Extending the Data Model

Decision: Custom Field vs Tag vs Config Context

Question→ Custom Field→ Tag→ Config Context
Does it have a value beyond yes/no?✅❌✅
Applied across many object types?❌ (scoped)✅❌ (devices/VMs only)
Need to filter/search by it?✅✅❌ (not directly)
Used by automation/config rendering?❌❌✅
Inherited/computed from hierarchy?❌❌✅
Per-object unique value?✅❌❌ (matched by criteria)

Examples:

  • Warranty expiry date → custom field (per-device, typed, filterable)
  • PCI-compliant → tag (boolean-like, cross-object)
  • NTP servers for a site's devices → config context (inherited, used in config rendering)

See references/custom-field-types.md for all field types and decision guidance.

Custom Fields — Key Points

  • Types: text, longtext, integer, decimal, boolean, date, datetime, URL, JSON, selection, multi-selection, object, multi-object (13 types — unchanged in 4.6; there is no standalone "color" type)
  • JSON fields accept an optional validation_schema (4.6+) to enforce a JSON Schema on values
  • Selection/multi-selection choice sets support per-choice colors (choice_colors, 4.6+) — this is what release notes call the "color custom field", not a new field type
  • Object/multi-object fields create relationships to other NetBox objects — prefer these over storing names in text fields
  • Scope to specific object types at creation time
  • Group fields with group_name for UI organization
  • Visibility: always / if-set / hidden
  • Filter via API: ?cf_<field_name>=<value>

Tags — Key Points

  • Properties: name, slug, color, description
  • Restrict object_types to relevant models (don't let every tag appear everywhere)
  • Filter via API: ?tag=<slug>
  • No value — presence/absence only. If you need a value, use a custom field

Config Contexts — Key Points

  • JSON data matched to devices/VMs via: regions, site_groups, sites, locations, device_types, roles, platforms, cluster_types, cluster_groups, clusters, tenant_groups, tenants, tags
  • Weight-based merging: lower weight merges first, higher weight overwrites conflicts
  • Deep merge for dicts; replace for lists
  • Local context data (on device/VM directly) always wins
  • ConfigContextProfile enforces JSON Schema validation
  • Performance: exclude with ?exclude=config_context when listing devices/VMs

Dependency Order

When bulk-importing data, create objects in dependency order. Required FKs must exist before the dependent object.

High-level order:

  1. Organizational models (RIR, Manufacturer, ClusterType, DeviceRole, Platform, IPAM Role, RackRole)
  2. Taxonomy hierarchies (Region, SiteGroup, TenantGroup, Tenant)
  3. Sites → Locations → Racks
  4. DeviceTypes (needs Manufacturer)
  5. Devices (needs DeviceType, DeviceRole, Site)
  6. IPAM: VRFs → Aggregates → Prefixes → IP Addresses
  7. VLANGroups → VLANs
  8. Clusters → VMs
  9. Circuits (needs Provider, CircuitType)
  10. Custom fields, tags, config contexts (can be created at any point but best early)

See references/dependency-order.md for the complete ordered list.

Anti-Patterns

  1. Flat site structure — Not using Regions/SiteGroups with 50+ sites. Kills filtering and reporting.
  2. Text custom fields as relationships — Use object/multi-object custom field types instead of storing names as text.
  3. Duplicate dimensions — Having both cf_environment=production AND tag production. Pick one.
  4. Ignoring dependency order — Creating devices before sites/device types. Scripts fail on missing FKs.
  5. Everything in global VRF — Model overlapping address spaces properly with VRFs.
  6. Overloading tenant — Using tenant for two things. One dimension only; use custom fields for the rest.
  7. Giant config contexts — Store variables, not entire configs. Use config templates for rendering.
  8. Unused roles — DeviceRole drives config context matching. Design roles deliberately, use 4.5 hierarchy.
  9. Prefix without status — Always set container/active/reserved. Container = organizational, active = allocated.
  10. Hardcoded PKs — Use name/slug for lookups. PKs differ across environments.

Version Notes

NetBox 4.5

ChangeImpact
DeviceRole → NestedGroupModelDesign role hierarchies (e.g., network → network/router, network/switch)
Platform → NestedGroupModelDesign platform hierarchies (e.g., cisco-ios → cisco-ios/xe, cisco-ios/xr)
MACAddress standalone modelMAC addresses are first-class objects, not just interface fields
VirtualDeviceContextModel VDCs on multi-tenant devices
CachedScopeMixin on Prefix/VLANGroupUse scope_type/scope_id instead of direct site FK
v2 API tokensUse Bearer nbt_<key>.<secret> format
ConfigContextProfileValidate config context data against JSON Schema
VirtualCircuit, CircuitGroupNew circuit modeling options
VirtualDiskDisk modeling for VMs

NetBox 4.6 (all 4.6+ only — don't assume on a 4.5.x instance)

ChangeImpact
VirtualMachineTypeReusable VM classification (like DeviceType) supplying default platform/vCPUs/memory; endpoint virtualization/virtual-machine-types/. VM gains optional virtual_machine_type FK
VM cluster now optionalA VM must be tied to at least one of site, cluster, or device — clusterless VMs attached directly to a Device are now first-class
CableBundleLogical grouping of cables (conduit/trunk/harness); Cable.bundle FK, optional, does not affect tracing; endpoint dcim/cable-bundles/
RackGroup (flat)Secondary, non-hierarchical rack categorization (row/aisle/cage) orthogonal to Location; Rack.group FK; endpoint dcim/rack-groups/. Can scope VLANGroups
VLANGroup scope += rackgrouprackgroup added to the VLANGroup scope types (full set: region/sitegroup/site/location/rackgroup/rack/clustergroup/cluster)
ASN roleASNs can now carry an ipam Role (Roles classify prefixes, VLANs, and ASNs)
JSON CF validation_schemaJSON custom fields can enforce a JSON Schema
Choice colorsPer-choice colors on selection/multiselect choice sets (choice_colors) — not a new field type
v1 API tokensDeprecated in 4.6, removed in 5.0; v2 nbt_ tokens return plaintext once at creation (4.6.1)

Keep looking

Skills are one crate of 628,853. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.