Description
NetBox version
v4.2.6
Feature type
Data model extension
Proposed functionality
ModuleTypeProfile
Introduce a new ModuleTypeProfile model to represent a meta class of module types (e.g. power supply, NIC, or GPU). Each instance of this model will define a user-configurable schema of attributes to be assigned on module types having this profile.
class ModuleTypeProfile(NetBoxModel):
name = models.CharField()
schema = models.JSONField()
The schema
field will hold a user-defined JSON schema which defines the scalar attributes that can be defined on module types with this profile. For example, a CPU profile might have a profile specify the following:
{
"properties": {
"architecture": {
"type": "string"
},
"speed": {
"type": "number",
"minimum": "0.01",
"multipleOf": "0.01"
},
"cores": {
"type": "number",
"minimum": 1,
"multipleOf": 1
}
}
}
Note that these attributes are intentionally limited to storing the basic types supported by JSON schema (strings, numbers, booleans, and null). Any more advanced needs will require the use of a custom field on the ModuleType model.
ModuleType
Two new fields will be added to the ModuleType model:
profile
: An optional ForeignKey to ModuleTypeProfileattributes
: A JSONField which stores the assigned key-value pairs for a module type as defined by the assigned profile
When editing a module type, the UI form will be extended to render all profile attributes as discrete form fields, with simple validation applied automatically.
Use case
The introduction of module type profiles with configurable attributes will improve the ability to accurately model field-replaceable units (FRU) as modules in NetBox. Today, this is typically done using inventory items, however that model is considerably limited in several ways:
- Inventory items have no ability to track unoccupied bays/sockets
- Inventory items (like other device components) must be named
- Inventory items cannot contain components (interfaces, power ports, etc.)
- There is no mechanism available for storing profile-specific attributes on inventory items
Modules are better suited for this task, as only the last constraint listed above affects modules as well, and is overcome by the changes proposed in this FR. (Ultimately, we'll likely deprecate inventory items in favor of this and related improvements to modules.)
Database changes
- Introduce the ModuleTypeProfile model
- Add a
profile
ForeignKey on ModuleType - Add an
attributes
JSONField on ModuleType
External dependencies
This will introduce a dependency in the jsonschema
Python library.