Skip to content

Commit 6850c1a

Browse files
committed
Clean up model & registry documentation
1 parent 76b584e commit 6850c1a

File tree

6 files changed

+134
-43
lines changed

6 files changed

+134
-43
lines changed

docs/development/application-registry.md

+18-25
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ The registry can be inspected by importing `registry` from `extras.registry`.
88

99
## Stores
1010

11+
### `data_backends`
12+
13+
A dictionary mapping data backend types to their respective classes. These are used to interact with [remote data sources](../models/core/datasource.md).
14+
15+
### `denormalized_fields`
16+
17+
Stores registration made using `netbox.denormalized.register()`. For each model, a list of related models and their field mappings is maintained to facilitate automatic updates.
18+
1119
### `model_features`
1220

1321
A dictionary of particular features (e.g. custom fields) mapped to the NetBox models which support them, arranged by app. For example:
@@ -20,38 +28,23 @@ A dictionary of particular features (e.g. custom fields) mapped to the NetBox mo
2028
...
2129
},
2230
'webhooks': {
23-
...
31+
'extras': ['configcontext', 'tag', ...],
32+
'dcim': ['site', 'rack', 'devicetype', ...],
2433
},
2534
...
2635
}
2736
```
2837

29-
### `plugin_menu_items`
38+
Supported model features are listed in the [features matrix](./models.md#features-matrix).
3039

31-
Navigation menu items provided by NetBox plugins. Each plugin is registered as a key with the list of menu items it provides. An example:
40+
### `plugins`
3241

33-
```python
34-
{
35-
'Plugin A': (
36-
<MenuItem>, <MenuItem>, <MenuItem>,
37-
),
38-
'Plugin B': (
39-
<MenuItem>, <MenuItem>, <MenuItem>,
40-
),
41-
}
42-
```
42+
This store maintains all registered items for plugins, such as navigation menus, template extensions, etc.
4343

44-
### `plugin_template_extensions`
44+
### `search`
4545

46-
Plugin content that gets embedded into core NetBox templates. The store comprises NetBox models registered as dictionary keys, each pointing to a list of applicable template extension classes that exist. An example:
46+
A dictionary mapping each model (identified by its app and label) to its search index class, if one has been registered for it.
4747

48-
```python
49-
{
50-
'dcim.site': [
51-
<TemplateExtension>, <TemplateExtension>, <TemplateExtension>,
52-
],
53-
'dcim.rack': [
54-
<TemplateExtension>, <TemplateExtension>,
55-
],
56-
}
57-
```
48+
### `views`
49+
50+
A hierarchical mapping of registered views for each model. Mappings are added using the `register_model_view()` decorator, and URLs paths can be generated from these using `get_model_urls()`.

docs/development/models.md

+34-18
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,43 @@
22

33
## Model Types
44

5-
A NetBox model represents a discrete object type such as a device or IP address. Per [Django convention](https://docs.djangoproject.com/en/stable/topics/db/models/), each model is defined as a Python class and has its own SQL table. All NetBox data models can be categorized by type.
5+
A NetBox model represents a discrete object type such as a device or IP address. Per [Django convention](https://docs.djangoproject.com/en/stable/topics/db/models/), each model is defined as a Python class and has its own table in the PostgreSQL database. All NetBox data models can be categorized by type.
66

7-
The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/contenttypes/) framework can be used to reference models within the database. A ContentType instance references a model by its `app_label` and `name`: For example, the Site model is referred to as `dcim.site`. The content type combined with an object's primary key form a globally unique identifier for the object (e.g. `dcim.site:123`).
7+
The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/contenttypes/) framework is used to map Django models to database tables. A ContentType instance references a model by its `app_label` and `name`: For example, the Site model within the DCIM app is referred to as `dcim.site`. The content type combined with an object's primary key form a globally unique identifier for the object (e.g. `dcim.site:123`).
88

99
### Features Matrix
1010

11-
* [Change logging](../features/change-logging.md) - Changes to these objects are automatically recorded in the change log
12-
* [Webhooks](../integrations/webhooks.md) - NetBox is capable of generating outgoing webhooks for these objects
13-
* [Custom fields](../customization/custom-fields.md) - These models support the addition of user-defined fields
14-
* [Export templates](../customization/export-templates.md) - Users can create custom export templates for these models
15-
* [Tagging](../models/extras/tag.md) - The models can be tagged with user-defined tags
16-
* [Journaling](../features/journaling.md) - These models support persistent historical commentary
17-
* Nesting - These models can be nested recursively to create a hierarchy
18-
19-
| Type | Change Logging | Webhooks | Custom Fields | Export Templates | Tags | Journaling | Nesting |
20-
| ------------------ | ---------------- | ---------------- |------------------| ---------------- | ---------------- | ---------------- | ---------------- |
21-
| Primary | :material-check: | :material-check: | :material-check: | :material-check: | :material-check: | :material-check: | |
22-
| Organizational | :material-check: | :material-check: | :material-check: | :material-check: | :material-check: | | |
23-
| Nested Group | :material-check: | :material-check: | :material-check: | :material-check: | :material-check: | | :material-check: |
24-
| Component | :material-check: | :material-check: | :material-check: | :material-check: | :material-check: | | |
25-
| Component Template | :material-check: | :material-check: | | | | | |
11+
Depending on its classification, each NetBox model may support various features which enhance its operation. Each feature is enabled by inheriting from its designated mixin class, and some features also make use of the [application registry](./application-registry.md#model_features).
12+
13+
| Feature | Feature Mixin | Registry Key | Description |
14+
|------------------------------------------------------------|-------------------------|--------------------|--------------------------------------------------------------------------------|
15+
| [Change logging](../features/change-logging.md) | `ChangeLoggingMixin` | - | Changes to these objects are automatically recorded in the change log |
16+
| Cloning | `CloningMixin` | - | Provides the `clone()` method to prepare a copy |
17+
| [Custom fields](../customization/custom-fields.md) | `CustomFieldsMixin` | `custom_fields` | These models support the addition of user-defined fields |
18+
| [Custom links](../customization/custom-links.md) | `CustomLinksMixin` | `custom_links` | These models support the assignment of custom links |
19+
| [Custom validation](../customization/custom-validation.md) | `CustomValidationMixin` | - | Supports the enforcement of custom validation rules |
20+
| [Export templates](../customization/export-templates.md) | `ExportTemplatesMixin` | `export_templates` | Users can create custom export templates for these models |
21+
| [Job results](../features/background-jobs.md) | `JobResultsMixin` | `job_results` | Users can create custom export templates for these models |
22+
| [Journaling](../features/journaling.md) | `JournalingMixin` | `journaling` | These models support persistent historical commentary |
23+
| [Synchronized data](../integrations/synchronized-data.md) | `SyncedDataMixin` | `synced_data` | Certain model data can be automatically synchronized from a remote data source |
24+
| [Tagging](../models/extras/tag.md) | `TagsMixin` | `tags` | The models can be tagged with user-defined tags |
25+
| [Webhooks](../integrations/webhooks.md) | `WebhooksMixin` | `webhooks` | NetBox is capable of generating outgoing webhooks for these objects |
2626

2727
## Models Index
2828

2929
### Primary Models
3030

31+
These are considered the "core" application models which are used to model network infrastructure.
32+
3133
* [circuits.Circuit](../models/circuits/circuit.md)
3234
* [circuits.Provider](../models/circuits/provider.md)
3335
* [circuits.ProviderNetwork](../models/circuits/providernetwork.md)
36+
* [core.DataSource](../models/core/datasource.md)
3437
* [dcim.Cable](../models/dcim/cable.md)
3538
* [dcim.Device](../models/dcim/device.md)
3639
* [dcim.DeviceType](../models/dcim/devicetype.md)
40+
* [dcim.Module](../models/dcim/module.md)
41+
* [dcim.ModuleType](../models/dcim/moduletype.md)
3742
* [dcim.PowerFeed](../models/dcim/powerfeed.md)
3843
* [dcim.PowerPanel](../models/dcim/powerpanel.md)
3944
* [dcim.Rack](../models/dcim/rack.md)
@@ -47,10 +52,10 @@ The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/
4752
* [ipam.IPAddress](../models/ipam/ipaddress.md)
4853
* [ipam.IPRange](../models/ipam/iprange.md)
4954
* [ipam.L2VPN](../models/ipam/l2vpn.md)
50-
* [ipam.L2VPNTermination](../models/ipam/l2vpntermination.md)
5155
* [ipam.Prefix](../models/ipam/prefix.md)
5256
* [ipam.RouteTarget](../models/ipam/routetarget.md)
5357
* [ipam.Service](../models/ipam/service.md)
58+
* [ipam.ServiceTemplate](../models/ipam/servicetemplate.md)
5459
* [ipam.VLAN](../models/ipam/vlan.md)
5560
* [ipam.VRF](../models/ipam/vrf.md)
5661
* [tenancy.Contact](../models/tenancy/contact.md)
@@ -62,6 +67,8 @@ The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/
6267

6368
### Organizational Models
6469

70+
Organization models are used to organize and classify primary models.
71+
6572
* [circuits.CircuitType](../models/circuits/circuittype.md)
6673
* [dcim.DeviceRole](../models/dcim/devicerole.md)
6774
* [dcim.Manufacturer](../models/dcim/manufacturer.md)
@@ -76,6 +83,8 @@ The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/
7683

7784
### Nested Group Models
7885

86+
Nested group models behave like organizational model, but self-nest within a recursive hierarchy. For example, the Region model can be used to represent a hierarchy of countries, states, and cities.
87+
7988
* [dcim.Location](../models/dcim/location.md) (formerly RackGroup)
8089
* [dcim.Region](../models/dcim/region.md)
8190
* [dcim.SiteGroup](../models/dcim/sitegroup.md)
@@ -85,24 +94,31 @@ The Django [content types](https://docs.djangoproject.com/en/stable/ref/contrib/
8594

8695
### Component Models
8796

97+
Component models represent individual physical or virtual components belonging to a device or virtual machine.
98+
8899
* [dcim.ConsolePort](../models/dcim/consoleport.md)
89100
* [dcim.ConsoleServerPort](../models/dcim/consoleserverport.md)
90101
* [dcim.DeviceBay](../models/dcim/devicebay.md)
91102
* [dcim.FrontPort](../models/dcim/frontport.md)
92103
* [dcim.Interface](../models/dcim/interface.md)
93104
* [dcim.InventoryItem](../models/dcim/inventoryitem.md)
105+
* [dcim.ModuleBay](../models/dcim/modulebay.md)
94106
* [dcim.PowerOutlet](../models/dcim/poweroutlet.md)
95107
* [dcim.PowerPort](../models/dcim/powerport.md)
96108
* [dcim.RearPort](../models/dcim/rearport.md)
97109
* [virtualization.VMInterface](../models/virtualization/vminterface.md)
98110

99111
### Component Template Models
100112

113+
These function as templates to effect the replication of device and virtual machine components. Component template models support a limited feature set, including change logging, custom validation, and webhooks.
114+
101115
* [dcim.ConsolePortTemplate](../models/dcim/consoleporttemplate.md)
102116
* [dcim.ConsoleServerPortTemplate](../models/dcim/consoleserverporttemplate.md)
103117
* [dcim.DeviceBayTemplate](../models/dcim/devicebaytemplate.md)
104118
* [dcim.FrontPortTemplate](../models/dcim/frontporttemplate.md)
105119
* [dcim.InterfaceTemplate](../models/dcim/interfacetemplate.md)
120+
* [dcim.InventoryItemTemplate](../models/dcim/inventoryitemtemplate.md)
121+
* [dcim.ModuleBayTemplate](../models/dcim/modulebaytemplate.md)
106122
* [dcim.PowerOutletTemplate](../models/dcim/poweroutlettemplate.md)
107123
* [dcim.PowerPortTemplate](../models/dcim/powerporttemplate.md)
108124
* [dcim.RearPortTemplate](../models/dcim/rearporttemplate.md)

docs/features/background-jobs.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Background Jobs
2+
3+
NetBox includes the ability to execute certain functions as background tasks. These include:
4+
5+
* [Report](../customization/reports.md) execution
6+
* [Custom script](../customization/custom-scripts.md) execution
7+
* Synchronization of [remote data sources](../integrations/synchronized-data.md)
8+
9+
Additionally, NetBox plugins can enqueue their own background tasks. This is accomplished using the [JobResult model](../models/extras/jobresult.md). Background tasks are executed by the `rqworker` process(es).
10+
11+
## Scheduled Jobs
12+
13+
Background jobs can be configured to run immediately, or at a set time in the future. Scheduled jobs can also be configured to repeat at a set interval.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Synchronized Data
2+
3+
Some NetBox models support automatic synchronization of certain attributes from remote [data sources](../models/core/datasource.md), such as a git repository hosted on GitHub or GitLab. Data from the authoritative remote source is synchronized locally in NetBox as [data files](../models/core/datafile.md).
4+
5+
The following features support the use of synchronized data:
6+
7+
* [Configuration templates](../features/configuration-rendering.md)
8+
* [Configuration context data](../features/context-data.md)
9+
* [Export templates](../customization/export-templates.md)

docs/models/extras/jobresult.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Job Results
2+
3+
The JobResult model is used to schedule and record the execution of [background tasks](../../features/background-jobs.md).
4+
5+
## Fields
6+
7+
### Name
8+
9+
The name or other identifier of the NetBox object with which the job is associated.
10+
11+
## Object Type
12+
13+
The type of object (model) associated with this job.
14+
15+
### Created
16+
17+
The date and time at which the job itself was created.
18+
19+
### Scheduled
20+
21+
The date and time at which the job is/was scheduled to execute (if not submitted for immediate execution at the time of creation).
22+
23+
### Interval
24+
25+
The interval (in minutes) at which a scheduled job should re-execute.
26+
27+
### Completed
28+
29+
The date and time at which the job completed (if complete).
30+
31+
### User
32+
33+
The user who created the job.
34+
35+
### Status
36+
37+
The job's current status. Potential values include:
38+
39+
| Value | Description |
40+
|-------|-------------|
41+
| Pending | Awaiting execution by an RQ worker process |
42+
| Scheduled | Scheduled for a future date/time |
43+
| Running | Currently executing |
44+
| Completed | Successfully completed |
45+
| Failed | The job did not complete successfully |
46+
| Errored | An unexpected error was encountered during execution |
47+
48+
### Data
49+
50+
Any data associated with the execution of the job, such as log output.
51+
52+
### Job ID
53+
54+
The job's UUID, used for unique identification within a queue.

mkdocs.yml

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ nav:
7777
- Configuration Rendering: 'features/configuration-rendering.md'
7878
- Change Logging: 'features/change-logging.md'
7979
- Journaling: 'features/journaling.md'
80+
- Background Jobs: 'features/background-jobs.md'
8081
- Auth & Permissions: 'features/authentication-permissions.md'
8182
- API & Integration: 'features/api-integration.md'
8283
- Customization: 'features/customization.md'
@@ -117,6 +118,7 @@ nav:
117118
- REST API: 'integrations/rest-api.md'
118119
- GraphQL API: 'integrations/graphql-api.md'
119120
- Webhooks: 'integrations/webhooks.md'
121+
- Synchronized Data: 'integrations/synchronized-data.md'
120122
- NAPALM: 'integrations/napalm.md'
121123
- Prometheus Metrics: 'integrations/prometheus-metrics.md'
122124
- Plugins:
@@ -153,6 +155,9 @@ nav:
153155
- Circuit Type: 'models/circuits/circuittype.md'
154156
- Provider: 'models/circuits/provider.md'
155157
- Provider Network: 'models/circuits/providernetwork.md'
158+
- Core:
159+
- DataFile: 'models/core/datafile.md'
160+
- DataSource: 'models/core/datasource.md'
156161
- DCIM:
157162
- Cable: 'models/dcim/cable.md'
158163
- ConsolePort: 'models/dcim/consoleport.md'
@@ -202,6 +207,7 @@ nav:
202207
- CustomLink: 'models/extras/customlink.md'
203208
- ExportTemplate: 'models/extras/exporttemplate.md'
204209
- ImageAttachment: 'models/extras/imageattachment.md'
210+
- JobResult: 'models/extras/jobresult.md'
205211
- JournalEntry: 'models/extras/journalentry.md'
206212
- SavedFilter: 'models/extras/savedfilter.md'
207213
- StagedChange: 'models/extras/stagedchange.md'

0 commit comments

Comments
 (0)