mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-09 05:12:18 -06:00
Compare commits
313 Commits
02496-max-
...
35de0c59cd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35de0c59cd | ||
|
|
44362dc191 | ||
|
|
d9e4c78dcc | ||
|
|
f84ccb6e85 | ||
|
|
e18a0f4dde | ||
|
|
1923d889f5 | ||
|
|
197f94a6ef | ||
|
|
575dcea478 | ||
|
|
42df6be604 | ||
|
|
9d60342ec7 | ||
|
|
edbcea817c | ||
|
|
860bdae1e9 | ||
|
|
d4f0eeb0a7 | ||
|
|
39e1eefe36 | ||
|
|
078231a46b | ||
|
|
fba56d3704 | ||
|
|
9de61fe1a8 | ||
|
|
c2bd57eecf | ||
|
|
ab5005ec09 | ||
|
|
84ba09bf02 | ||
|
|
ee6a3a495b | ||
|
|
5664684530 | ||
|
|
562334eac8 | ||
|
|
560dcb6af1 | ||
|
|
ac74d9f9be | ||
|
|
05e1317f5e | ||
|
|
c8af43f3f2 | ||
|
|
b410b4e107 | ||
|
|
4ca4983204 | ||
|
|
fd9a6b958b | ||
|
|
99781888d3 | ||
|
|
b6fe79e647 | ||
|
|
44a1e45fe0 | ||
|
|
93b934701d | ||
|
|
c0de8748a2 | ||
|
|
e7ad66f2ef | ||
|
|
067c670243 | ||
|
|
9cb7f4b9ad | ||
|
|
8d191b5d5b | ||
|
|
aeb6024502 | ||
|
|
5458873cdc | ||
|
|
ad96fb3ab4 | ||
|
|
fd67acc3ab | ||
|
|
20c260b126 | ||
|
|
7bca9f5d6d | ||
|
|
502b33b144 | ||
|
|
10e69c8b30 | ||
|
|
513b11450d | ||
|
|
b5edfa5d53 | ||
|
|
afba5b2791 | ||
|
|
8b3f7ce507 | ||
|
|
adad3745ae | ||
|
|
8055fae253 | ||
|
|
1505285aff | ||
|
|
7cc7c7ab81 | ||
|
|
ae21a6a684 | ||
|
|
aac3a51431 | ||
|
|
3e0ad2176f | ||
|
|
4e8edfb3d6 | ||
|
|
651557a82b | ||
|
|
c3d66dc42e | ||
|
|
a50e570f22 | ||
|
|
a44a79ec79 | ||
|
|
b919868521 | ||
|
|
d9aab6bbe2 | ||
|
|
82171fce7a | ||
|
|
1dcfc05c32 | ||
|
|
5143003c68 | ||
|
|
020eb64eab | ||
|
|
ec7afccd55 | ||
|
|
76fd63823c | ||
|
|
6c373decd6 | ||
|
|
222b26e060 | ||
|
|
066b787777 | ||
|
|
90b2732068 | ||
|
|
bfba0ccaae | ||
|
|
d5718357f1 | ||
|
|
d61737396b | ||
|
|
c6248f1142 | ||
|
|
05f254a768 | ||
|
|
0cb10f806a | ||
|
|
8ac7f6f8de | ||
|
|
45fc354d45 | ||
|
|
cd8087ab43 | ||
|
|
da5ae21150 | ||
|
|
38b2839a1e | ||
|
|
5585b410f8 | ||
|
|
47ac506d5c | ||
|
|
db3a4bc731 | ||
|
|
ebeceaaa21 | ||
|
|
3e1ccc80e9 | ||
|
|
d192c1e352 | ||
|
|
c7d94bd529 | ||
|
|
a718cb1173 | ||
|
|
867a01fae5 | ||
|
|
fbb948d30e | ||
|
|
975e0ff398 | ||
|
|
d7877b7627 | ||
|
|
b685df7c9c | ||
|
|
9dcf9475cc | ||
|
|
cee2a5e0ed | ||
|
|
e1bf27e4db | ||
|
|
9b89af75e4 | ||
|
|
9e13d89baa | ||
|
|
01cbdbb968 | ||
|
|
a4365be0a3 | ||
|
|
4961b0d334 | ||
|
|
ab06edd9f5 | ||
|
|
e787a71c1d | ||
|
|
cd8878df30 | ||
|
|
b5a9cb1762 | ||
|
|
1d2f6a82cb | ||
|
|
6e7bbfc3e2 | ||
|
|
9723a2f0ad | ||
|
|
327d08f4c2 | ||
|
|
3e43226901 | ||
|
|
7b0e8c1a0d | ||
|
|
917280d1d3 | ||
|
|
4be476eb49 | ||
|
|
8005b56ab4 | ||
|
|
3f1654c9ba | ||
|
|
95f8fe788d | ||
|
|
588c069ff1 | ||
|
|
5b3ff3c0e9 | ||
|
|
a024012abd | ||
|
|
730d73042d | ||
|
|
6c2a6d0e90 | ||
|
|
6fc04bd1fe | ||
|
|
e55a4ae603 | ||
|
|
60cc009d6b | ||
|
|
e9777d3193 | ||
|
|
1d2aef71b2 | ||
|
|
4edaa48aa7 | ||
|
|
dfb08ff521 | ||
|
|
9d6522c11e | ||
|
|
281cb4f586 | ||
|
|
838794a5cf | ||
|
|
e6a6ff7aec | ||
|
|
1de41b4964 | ||
|
|
d5cec3723e | ||
|
|
87ff83ef1f | ||
|
|
59899d0d9a | ||
|
|
bcffc383bf | ||
|
|
3cdc6251be | ||
|
|
0e1705b870 | ||
|
|
8522c03b71 | ||
|
|
20af97ce24 | ||
|
|
c05106f9b2 | ||
|
|
264b40a269 | ||
|
|
17429c4257 | ||
|
|
40b114c0bb | ||
|
|
1cffbb21bb | ||
|
|
ed3dd019a7 | ||
|
|
17cffd7860 | ||
|
|
21bb734dcb | ||
|
|
c392988212 | ||
|
|
37bea1e98e | ||
|
|
cbf9b62f12 | ||
|
|
c429cc3638 | ||
|
|
da68503a19 | ||
|
|
e9b15436c4 | ||
|
|
4d5f8e9460 | ||
|
|
77613b37b2 | ||
|
|
3fd4664a76 | ||
|
|
032ed4f11c | ||
|
|
7ca4342c15 | ||
|
|
70bc1c226a | ||
|
|
eef9db5e5a | ||
|
|
6a21459ccc | ||
|
|
635de4af2e | ||
|
|
df96f7dd0f | ||
|
|
90712fa865 | ||
|
|
90874adf14 | ||
|
|
2a629d6f74 | ||
|
|
83de784196 | ||
|
|
1acd567706 | ||
|
|
7d993cc141 | ||
|
|
d4783b7fbd | ||
|
|
3890043b06 | ||
|
|
fbe76ac98a | ||
|
|
0b61d69e05 | ||
|
|
1245a9f99d | ||
|
|
78223cea03 | ||
|
|
8452222761 | ||
|
|
8a59fc733c | ||
|
|
df688ce064 | ||
|
|
fd3a9a0c37 | ||
|
|
1a1ab2a19d | ||
|
|
068d493cc6 | ||
|
|
80f03daad6 | ||
|
|
d04c41d0f6 | ||
|
|
1fc849eb40 | ||
|
|
bbf1f6181d | ||
|
|
729b0365e0 | ||
|
|
43cb476223 | ||
|
|
d6f756d315 | ||
|
|
afc62b6ffd | ||
|
|
3d4841f17f | ||
|
|
2aefb3af73 | ||
|
|
4eff4d6a4a | ||
|
|
9381564cab | ||
|
|
3d143d635b | ||
|
|
77307b3c91 | ||
|
|
bf83299a93 | ||
|
|
aa4571b61f | ||
|
|
56d9146323 | ||
|
|
e192f64dd2 | ||
|
|
d433a28524 | ||
|
|
dbfdf318ad | ||
|
|
9b064e678d | ||
|
|
be74436884 | ||
|
|
639bc4462b | ||
|
|
52d4498caf | ||
|
|
1c59d411f7 | ||
|
|
ac7a4ec4a3 | ||
|
|
0cf58e62b2 | ||
|
|
fb8d41b527 | ||
|
|
ae5d7911f9 | ||
|
|
3bd0186870 | ||
|
|
09ce8a808d | ||
|
|
8eaff9dce7 | ||
|
|
cb3308a166 | ||
|
|
5fbae8407e | ||
|
|
2fdd46f64c | ||
|
|
5bbab7eb47 | ||
|
|
c5124cb2e4 | ||
|
|
d01d7b4156 | ||
|
|
4db6123fb2 | ||
|
|
43648d629b | ||
|
|
0b97df0984 | ||
|
|
5334c8143c | ||
|
|
bbb330becf | ||
|
|
87505e0bb9 | ||
|
|
e4c74ce6a3 | ||
|
|
7d82493052 | ||
|
|
a4868f894d | ||
|
|
77c08b7bf9 | ||
|
|
531ea34207 | ||
|
|
6747c82a1a | ||
|
|
e251ea10b5 | ||
|
|
a1aaf465ac | ||
|
|
2a1d315d85 | ||
|
|
adad7c2209 | ||
|
|
8cc6589a35 | ||
|
|
bee0080917 | ||
|
|
389c44e5d6 | ||
|
|
9cb2c78e34 | ||
|
|
2ae98f0353 | ||
|
|
addda0538f | ||
|
|
c902a1c510 | ||
|
|
f23ee0a46f | ||
|
|
b4acc3fb36 | ||
|
|
5ad6bd88f6 | ||
|
|
2bebfccf9b | ||
|
|
b7cc4c418b | ||
|
|
37a9d03348 | ||
|
|
a69bbcf651 | ||
|
|
2edfde5753 | ||
|
|
cfbd9632ac | ||
|
|
c9386bc9c3 | ||
|
|
c826c5cdb0 | ||
|
|
a4ab4f885d | ||
|
|
61d77dff14 | ||
|
|
24a83acc34 | ||
|
|
dbc71158ec | ||
|
|
a91af996d5 | ||
|
|
f0523611d1 | ||
|
|
7719b98697 | ||
|
|
f383067ecb | ||
|
|
20de263565 | ||
|
|
bb290dc792 | ||
|
|
fcdb7ff6c8 | ||
|
|
5ceb6a60da | ||
|
|
33d4759871 | ||
|
|
2abc5ac69a | ||
|
|
f8c074045f | ||
|
|
18a308ae3a | ||
|
|
d8e4c95bcc | ||
|
|
c63e60a62b | ||
|
|
82db8a9c02 | ||
|
|
bb75bceec5 | ||
|
|
9a68cde95f | ||
|
|
6c723dfb1a | ||
|
|
9b85d92ad0 | ||
|
|
917a2c2618 | ||
|
|
6388705e57 | ||
|
|
ac335c3d87 | ||
|
|
a54c508da2 | ||
|
|
d69042f26e | ||
|
|
f6290dd7af | ||
|
|
adce67a7cf | ||
|
|
f82f084c02 | ||
|
|
43fc7fb58a | ||
|
|
11099b01bb | ||
|
|
5dc48f3a88 | ||
|
|
1ee23ba6fa | ||
|
|
23d7515b41 | ||
|
|
12818f1786 | ||
|
|
f0ae0da1c7 | ||
|
|
c30e4813b7 | ||
|
|
57a7afd548 | ||
|
|
b4eaeead13 | ||
|
|
24fff6bd74 | ||
|
|
b9567208d4 | ||
|
|
cfcea7c941 | ||
|
|
21ba27fb39 | ||
|
|
c0e4d1c1e3 | ||
|
|
d95eaa7ba2 | ||
|
|
5506901867 | ||
|
|
ec9da88134 | ||
|
|
e221f1fffa | ||
|
|
530dad279a | ||
|
|
b1439dc298 |
@@ -2,7 +2,7 @@
|
|||||||
name: ✨ Feature Request
|
name: ✨ Feature Request
|
||||||
type: Feature
|
type: Feature
|
||||||
description: Propose a new NetBox feature or enhancement
|
description: Propose a new NetBox feature or enhancement
|
||||||
labels: ["type: feature", "status: needs triage"]
|
labels: ["netbox", "type: feature", "status: needs triage"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
@@ -15,7 +15,7 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: NetBox version
|
label: NetBox version
|
||||||
description: What version of NetBox are you currently running?
|
description: What version of NetBox are you currently running?
|
||||||
placeholder: v4.4.2
|
placeholder: v4.4.7
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
|
|||||||
8
.github/ISSUE_TEMPLATE/02-bug_report.yaml
vendored
8
.github/ISSUE_TEMPLATE/02-bug_report.yaml
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: 🐛 Bug Report
|
name: 🐛 Bug Report
|
||||||
type: Bug
|
type: Bug
|
||||||
description: Report a reproducible bug in the current release of NetBox
|
description: Report a reproducible bug in the current release of NetBox
|
||||||
labels: ["type: bug", "status: needs triage"]
|
labels: ["netbox", "type: bug", "status: needs triage"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
@@ -27,7 +27,7 @@ body:
|
|||||||
attributes:
|
attributes:
|
||||||
label: NetBox Version
|
label: NetBox Version
|
||||||
description: What version of NetBox are you currently running?
|
description: What version of NetBox are you currently running?
|
||||||
placeholder: v4.4.2
|
placeholder: v4.4.7
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
@@ -35,9 +35,9 @@ body:
|
|||||||
label: Python Version
|
label: Python Version
|
||||||
description: What version of Python are you currently running?
|
description: What version of Python are you currently running?
|
||||||
options:
|
options:
|
||||||
- "3.10"
|
|
||||||
- "3.11"
|
|
||||||
- "3.12"
|
- "3.12"
|
||||||
|
- "3.13"
|
||||||
|
- "3.14"
|
||||||
validations:
|
validations:
|
||||||
required: true
|
required: true
|
||||||
- type: textarea
|
- type: textarea
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
name: 📖 Documentation Change
|
name: 📖 Documentation Change
|
||||||
type: Documentation
|
type: Documentation
|
||||||
description: Suggest an addition or modification to the NetBox documentation
|
description: Suggest an addition or modification to the NetBox documentation
|
||||||
labels: ["type: documentation", "status: needs triage"]
|
labels: ["netbox", "type: documentation", "status: needs triage"]
|
||||||
body:
|
body:
|
||||||
- type: dropdown
|
- type: dropdown
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/04-translation.yaml
vendored
2
.github/ISSUE_TEMPLATE/04-translation.yaml
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: 🌍 Translation
|
name: 🌍 Translation
|
||||||
type: Translation
|
type: Translation
|
||||||
description: Request support for a new language in the user interface
|
description: Request support for a new language in the user interface
|
||||||
labels: ["type: translation"]
|
labels: ["netbox", "type: translation"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/05-housekeeping.yaml
vendored
2
.github/ISSUE_TEMPLATE/05-housekeeping.yaml
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: 🏡 Housekeeping
|
name: 🏡 Housekeeping
|
||||||
type: Housekeeping
|
type: Housekeeping
|
||||||
description: A change pertaining to the codebase itself (developers only)
|
description: A change pertaining to the codebase itself (developers only)
|
||||||
labels: ["type: housekeeping"]
|
labels: ["netbox", "type: housekeeping"]
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE/06-deprecation.yaml
vendored
2
.github/ISSUE_TEMPLATE/06-deprecation.yaml
vendored
@@ -2,7 +2,7 @@
|
|||||||
name: 🗑️ Deprecation
|
name: 🗑️ Deprecation
|
||||||
type: Deprecation
|
type: Deprecation
|
||||||
description: The removal of an existing feature or resource
|
description: The removal of an existing feature or resource
|
||||||
labels: ["type: deprecation"]
|
labels: ["netbox", "type: deprecation"]
|
||||||
body:
|
body:
|
||||||
- type: textarea
|
- type: textarea
|
||||||
attributes:
|
attributes:
|
||||||
|
|||||||
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -31,7 +31,7 @@ jobs:
|
|||||||
NETBOX_CONFIGURATION: netbox.configuration_testing
|
NETBOX_CONFIGURATION: netbox.configuration_testing
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version: ['3.10', '3.11', '3.12']
|
python-version: ['3.12', '3.13']
|
||||||
node-version: ['20.x']
|
node-version: ['20.x']
|
||||||
services:
|
services:
|
||||||
redis:
|
redis:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v0.6.9
|
rev: v0.14.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
name: "Ruff linter"
|
name: "Ruff linter"
|
||||||
@@ -21,14 +21,6 @@ repos:
|
|||||||
language: system
|
language: system
|
||||||
pass_filenames: false
|
pass_filenames: false
|
||||||
types: [python]
|
types: [python]
|
||||||
- id: openapi-check
|
|
||||||
name: "Validate OpenAPI schema"
|
|
||||||
description: "Check for any unexpected changes to the OpenAPI schema"
|
|
||||||
files: api/.*\.py$
|
|
||||||
entry: scripts/verify-openapi.sh
|
|
||||||
language: system
|
|
||||||
pass_filenames: false
|
|
||||||
types: [python]
|
|
||||||
- id: mkdocs-build
|
- id: mkdocs-build
|
||||||
name: "Build documentation"
|
name: "Build documentation"
|
||||||
description: "Build the documentation with mkdocs"
|
description: "Build the documentation with mkdocs"
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ django-cors-headers
|
|||||||
|
|
||||||
# Runtime UI tool for debugging Django
|
# Runtime UI tool for debugging Django
|
||||||
# https://github.com/jazzband/django-debug-toolbar/blob/main/docs/changes.rst
|
# https://github.com/jazzband/django-debug-toolbar/blob/main/docs/changes.rst
|
||||||
# django-debug-toolbar v6.0.0 raises "Attribute Error at /: 'function' object has no attribute 'set'"
|
django-debug-toolbar
|
||||||
# see https://github.com/netbox-community/netbox/issues/19974
|
|
||||||
django-debug-toolbar==5.2.0
|
|
||||||
|
|
||||||
# Library for writing reusable URL query filters
|
# Library for writing reusable URL query filters
|
||||||
# https://github.com/carltongibson/django-filter/blob/main/CHANGES.rst
|
# https://github.com/carltongibson/django-filter/blob/main/CHANGES.rst
|
||||||
@@ -71,7 +69,8 @@ django-timezone-field
|
|||||||
|
|
||||||
# A REST API framework for Django projects
|
# A REST API framework for Django projects
|
||||||
# https://www.django-rest-framework.org/community/release-notes/
|
# https://www.django-rest-framework.org/community/release-notes/
|
||||||
djangorestframework
|
# TODO: Re-evaluate the monkey-patch of get_unique_validators() before upgrading
|
||||||
|
djangorestframework==3.16.1
|
||||||
|
|
||||||
# Sane and flexible OpenAPI 3 schema generation for Django REST framework.
|
# Sane and flexible OpenAPI 3 schema generation for Django REST framework.
|
||||||
# https://github.com/tfranzel/drf-spectacular/blob/master/CHANGELOG.rst
|
# https://github.com/tfranzel/drf-spectacular/blob/master/CHANGELOG.rst
|
||||||
@@ -167,7 +166,8 @@ strawberry-graphql-django
|
|||||||
svgwrite
|
svgwrite
|
||||||
|
|
||||||
# Tabular dataset library (for table-based exports)
|
# Tabular dataset library (for table-based exports)
|
||||||
# https://github.com/jazzband/tablib/blob/master/HISTORY.md
|
# Current: https://github.com/jazzband/tablib/releases
|
||||||
|
# Previous: https://github.com/jazzband/tablib/blob/master/HISTORY.md
|
||||||
tablib
|
tablib
|
||||||
|
|
||||||
# Timezone data (required by django-timezone-field on Python 3.9+)
|
# Timezone data (required by django-timezone-field on Python 3.9+)
|
||||||
|
|||||||
@@ -186,6 +186,7 @@
|
|||||||
"usb-3-micro-b",
|
"usb-3-micro-b",
|
||||||
"molex-micro-fit-1x2",
|
"molex-micro-fit-1x2",
|
||||||
"molex-micro-fit-2x2",
|
"molex-micro-fit-2x2",
|
||||||
|
"molex-micro-fit-2x3",
|
||||||
"molex-micro-fit-2x4",
|
"molex-micro-fit-2x4",
|
||||||
"dc-terminal",
|
"dc-terminal",
|
||||||
"saf-d-grid",
|
"saf-d-grid",
|
||||||
@@ -293,6 +294,7 @@
|
|||||||
"usb-c",
|
"usb-c",
|
||||||
"molex-micro-fit-1x2",
|
"molex-micro-fit-1x2",
|
||||||
"molex-micro-fit-2x2",
|
"molex-micro-fit-2x2",
|
||||||
|
"molex-micro-fit-2x3",
|
||||||
"molex-micro-fit-2x4",
|
"molex-micro-fit-2x4",
|
||||||
"dc-terminal",
|
"dc-terminal",
|
||||||
"eaton-c39",
|
"eaton-c39",
|
||||||
|
|||||||
21356
contrib/openapi.json
21356
contrib/openapi.json
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
## Local Authentication
|
## Local Authentication
|
||||||
|
|
||||||
Local user accounts and groups can be created in NetBox under the "Authentication" section in the "Admin" menu. This section is available only to users with the "staff" permission enabled.
|
Local user accounts and groups can be created in NetBox under the "Authentication" section in the "Admin" menu.
|
||||||
|
|
||||||
At a minimum, each user account must have a username and password set. User accounts may also denote a first name, last name, and email address. [Permissions](../permissions.md) may also be assigned to individual users and/or groups as needed.
|
At a minimum, each user account must have a username and password set. User accounts may also denote a first name, last name, and email address. [Permissions](../permissions.md) may also be assigned to individual users and/or groups as needed.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
# GraphQL API Parameters
|
# GraphQL API Parameters
|
||||||
|
|
||||||
|
## GRAPHQL_DEFAULT_VERSION
|
||||||
|
|
||||||
|
!!! note "This parameter was introduced in NetBox v4.5."
|
||||||
|
|
||||||
|
Default: `1`
|
||||||
|
|
||||||
|
Designates the default version of the GraphQL API served by `/graphql/`. To access a specific version, append the version number to the URL, e.g. `/graphql/v2/`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## GRAPHQL_ENABLED
|
## GRAPHQL_ENABLED
|
||||||
|
|
||||||
!!! tip "Dynamic Configuration Parameter"
|
!!! tip "Dynamic Configuration Parameter"
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ Some configuration parameters are primarily controlled via NetBox's admin interf
|
|||||||
* [`POWERFEED_DEFAULT_MAX_UTILIZATION`](./default-values.md#powerfeed_default_max_utilization)
|
* [`POWERFEED_DEFAULT_MAX_UTILIZATION`](./default-values.md#powerfeed_default_max_utilization)
|
||||||
* [`POWERFEED_DEFAULT_VOLTAGE`](./default-values.md#powerfeed_default_voltage)
|
* [`POWERFEED_DEFAULT_VOLTAGE`](./default-values.md#powerfeed_default_voltage)
|
||||||
* [`PREFER_IPV4`](./miscellaneous.md#prefer_ipv4)
|
* [`PREFER_IPV4`](./miscellaneous.md#prefer_ipv4)
|
||||||
|
* [`PROTECTION_RULES`](./data-validation.md#protection_rules)
|
||||||
* [`RACK_ELEVATION_DEFAULT_UNIT_HEIGHT`](./default-values.md#rack_elevation_default_unit_height)
|
* [`RACK_ELEVATION_DEFAULT_UNIT_HEIGHT`](./default-values.md#rack_elevation_default_unit_height)
|
||||||
* [`RACK_ELEVATION_DEFAULT_UNIT_WIDTH`](./default-values.md#rack_elevation_default_unit_width)
|
* [`RACK_ELEVATION_DEFAULT_UNIT_WIDTH`](./default-values.md#rack_elevation_default_unit_width)
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ Sets content for the top banner in the user interface.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## COPILOT_ENABLED
|
||||||
|
|
||||||
|
!!! tip "Dynamic Configuration Parameter"
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
Enables or disables the [NetBox Copilot](https://netboxlabs.com/docs/copilot/) agent globally. When enabled, users can opt to toggle the agent individually.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## CENSUS_REPORTING_ENABLED
|
## CENSUS_REPORTING_ENABLED
|
||||||
|
|
||||||
Default: `True`
|
Default: `True`
|
||||||
|
|||||||
@@ -127,19 +127,3 @@ The list of groups that promote an remote User to Superuser on Login. If group i
|
|||||||
Default: `[]` (Empty list)
|
Default: `[]` (Empty list)
|
||||||
|
|
||||||
The list of users that get promoted to Superuser on Login. If user isn't present in list on next Login, the Role gets revoked. (Requires `REMOTE_AUTH_ENABLED` and `REMOTE_AUTH_GROUP_SYNC_ENABLED` )
|
The list of users that get promoted to Superuser on Login. If user isn't present in list on next Login, the Role gets revoked. (Requires `REMOTE_AUTH_ENABLED` and `REMOTE_AUTH_GROUP_SYNC_ENABLED` )
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## REMOTE_AUTH_STAFF_GROUPS
|
|
||||||
|
|
||||||
Default: `[]` (Empty list)
|
|
||||||
|
|
||||||
The list of groups that promote an remote User to Staff on Login. If group isn't present on next Login, the Role gets revoked. (Requires `REMOTE_AUTH_ENABLED` and `REMOTE_AUTH_GROUP_SYNC_ENABLED` )
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## REMOTE_AUTH_STAFF_USERS
|
|
||||||
|
|
||||||
Default: `[]` (Empty list)
|
|
||||||
|
|
||||||
The list of users that get promoted to Staff on Login. If user isn't present in list on next Login, the Role gets revoked. (Requires `REMOTE_AUTH_ENABLED` and `REMOTE_AUTH_GROUP_SYNC_ENABLED` )
|
|
||||||
|
|||||||
@@ -23,6 +23,31 @@ ALLOWED_HOSTS = ['*']
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## API_TOKEN_PEPPERS
|
||||||
|
|
||||||
|
!!! info "This parameter was introduced in NetBox v4.5."
|
||||||
|
|
||||||
|
[Cryptographic peppers](https://en.wikipedia.org/wiki/Pepper_(cryptography)) are employed to generate hashes of sensitive values on the server. This parameter defines the peppers used to hash v2 API tokens in NetBox. You must define at least one pepper before creating a v2 API token. See the [API documentation](../integrations/rest-api.md#authentication) for further information about how peppers are used.
|
||||||
|
|
||||||
|
```python
|
||||||
|
API_TOKEN_PEPPERS = {
|
||||||
|
# DO NOT USE THIS EXAMPLE PEPPER IN PRODUCTION
|
||||||
|
1: 'kp7ht*76fiQAhUi5dHfASLlYUE_S^gI^(7J^K5M!LfoH@vl&b_',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! warning "Peppers are sensitive"
|
||||||
|
Treat pepper values as extremely sensitive. Consider populating peppers from environment variables at initialization time rather than defining them in the configuration file, if feasible.
|
||||||
|
|
||||||
|
Peppers must be at least 50 characters in length and should comprise a random string with a diverse character set. Consider using the Python script at `$INSTALL_ROOT/netbox/generate_secret_key.py` to generate a pepper value.
|
||||||
|
|
||||||
|
It is recommended to start with a pepper ID of `1`. Additional peppers can be introduced later as needed to begin rotating token hashes.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
Although NetBox will run without `API_TOKEN_PEPPERS` defined, the use of v2 API tokens will be unavailable.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## DATABASE
|
## DATABASE
|
||||||
|
|
||||||
!!! warning "Legacy Configuration Parameter"
|
!!! warning "Legacy Configuration Parameter"
|
||||||
|
|||||||
@@ -1,16 +1,5 @@
|
|||||||
# Security & Authentication Parameters
|
# Security & Authentication Parameters
|
||||||
|
|
||||||
## ALLOW_TOKEN_RETRIEVAL
|
|
||||||
|
|
||||||
Default: `False`
|
|
||||||
|
|
||||||
!!! note
|
|
||||||
The default value of this parameter changed from `True` to `False` in NetBox v4.3.0.
|
|
||||||
|
|
||||||
If disabled, the values of API tokens will not be displayed after each token's initial creation. A user **must** record the value of a token prior to its creation, or it will be lost. Note that this affects _all_ users, regardless of assigned permissions.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ALLOWED_URL_SCHEMES
|
## ALLOWED_URL_SCHEMES
|
||||||
|
|
||||||
!!! tip "Dynamic Configuration Parameter"
|
!!! tip "Dynamic Configuration Parameter"
|
||||||
@@ -92,7 +81,7 @@ If `True`, the cookie employed for cross-site request forgery (CSRF) protection
|
|||||||
|
|
||||||
Default: `[]`
|
Default: `[]`
|
||||||
|
|
||||||
Defines a list of trusted origins for unsafe (e.g. `POST`) requests. This is a pass-through to Django's [`CSRF_TRUSTED_ORIGINS`](https://docs.djangoproject.com/en/stable/ref/settings/#csrf-trusted-origins) setting. Note that each host listed must specify a scheme (e.g. `http://` or `https://).
|
Defines a list of trusted origins for unsafe (e.g. `POST`) requests. This is a pass-through to Django's [`CSRF_TRUSTED_ORIGINS`](https://docs.djangoproject.com/en/stable/ref/settings/#csrf-trusted-origins) setting. Note that each host listed must specify a scheme (e.g. `http://` or `https://`).
|
||||||
|
|
||||||
```python
|
```python
|
||||||
CSRF_TRUSTED_ORIGINS = (
|
CSRF_TRUSTED_ORIGINS = (
|
||||||
|
|||||||
@@ -232,6 +232,9 @@ STORAGES = {
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"BACKEND": "extras.storage.ScriptFileSystemStorage",
|
"BACKEND": "extras.storage.ScriptFileSystemStorage",
|
||||||
|
"OPTIONS": {
|
||||||
|
"allow_overwrite": True,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -247,6 +250,7 @@ STORAGES = {
|
|||||||
"OPTIONS": {
|
"OPTIONS": {
|
||||||
'access_key': 'access key',
|
'access_key': 'access key',
|
||||||
'secret_key': 'secret key',
|
'secret_key': 'secret key',
|
||||||
|
"allow_overwrite": True,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ An example fieldset definition is provided below:
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
class MyScript(Script):
|
class MyScript(Script):
|
||||||
class Meta:
|
class Meta(Script.Meta):
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('First group', ('field1', 'field2', 'field3')),
|
('First group', ('field1', 'field2', 'field3')),
|
||||||
('Second group', ('field4', 'field5')),
|
('Second group', ('field4', 'field5')),
|
||||||
@@ -131,17 +131,6 @@ self.log_info(f"Running as user {username} (IP: {ip_address})...")
|
|||||||
|
|
||||||
For a complete list of available request parameters, please see the [Django documentation](https://docs.djangoproject.com/en/stable/ref/request-response/).
|
For a complete list of available request parameters, please see the [Django documentation](https://docs.djangoproject.com/en/stable/ref/request-response/).
|
||||||
|
|
||||||
## Reading Data from Files
|
|
||||||
|
|
||||||
The Script class provides two convenience methods for reading data from files:
|
|
||||||
|
|
||||||
* `load_yaml`
|
|
||||||
* `load_json`
|
|
||||||
|
|
||||||
These two methods will load data in YAML or JSON format, respectively, from files within the local path (i.e. `SCRIPTS_ROOT`).
|
|
||||||
|
|
||||||
**Note:** These convenience methods are deprecated and will be removed in NetBox v4.4. These only work if running scripts within the local path, they will not work if using a storage other than ScriptFileSystemStorage.
|
|
||||||
|
|
||||||
## Logging
|
## Logging
|
||||||
|
|
||||||
The Script object provides a set of convenient functions for recording messages at different severity levels:
|
The Script object provides a set of convenient functions for recording messages at different severity levels:
|
||||||
@@ -404,6 +393,61 @@ A complete date & time. Returns a `datetime.datetime` object.
|
|||||||
|
|
||||||
Custom scripts can be run via the web UI by navigating to the script, completing any required form data, and clicking the "run script" button. It is possible to schedule a script to be executed at specified time in the future. A scheduled script can be canceled by deleting the associated job result object.
|
Custom scripts can be run via the web UI by navigating to the script, completing any required form data, and clicking the "run script" button. It is possible to schedule a script to be executed at specified time in the future. A scheduled script can be canceled by deleting the associated job result object.
|
||||||
|
|
||||||
|
#### Prefilling variables via URL parameters
|
||||||
|
|
||||||
|
Script form fields can be prefilled by appending query parameters to the script URL. Each parameter name must match the variable name defined on the script class. Prefilled values are treated as initial values and can be edited before execution. Multiple values can be supplied by repeating the same parameter. Query values must be percent‑encoded where required (for example, spaces as `%20`).
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
For string and integer variables, when a script defines:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from extras.scripts import Script, StringVar, IntegerVar
|
||||||
|
|
||||||
|
class MyScript(Script):
|
||||||
|
name = StringVar()
|
||||||
|
count = IntegerVar()
|
||||||
|
```
|
||||||
|
|
||||||
|
the following URL prefills the `name` and `count` fields:
|
||||||
|
|
||||||
|
```
|
||||||
|
https://<netbox>/extras/scripts/<script_id>/?name=Branch42&count=3
|
||||||
|
```
|
||||||
|
|
||||||
|
For object variables (`ObjectVar`), supply the object’s primary key (PK):
|
||||||
|
|
||||||
|
```
|
||||||
|
https://<netbox>/extras/scripts/<script_id>/?device=1
|
||||||
|
```
|
||||||
|
|
||||||
|
If an object ID cannot be resolved or the object is not visible to the requesting user, the field remains unpopulated.
|
||||||
|
|
||||||
|
Supported variable types:
|
||||||
|
|
||||||
|
| Variable class | Expected input | Example query string |
|
||||||
|
|--------------------------|---------------------------------|---------------------------------------------|
|
||||||
|
| `StringVar` | string (percent‑encoded) | `?name=Branch42` |
|
||||||
|
| `TextVar` | string (percent‑encoded) | `?notes=Initial%20value` |
|
||||||
|
| `IntegerVar` | integer | `?count=3` |
|
||||||
|
| `DecimalVar` | decimal number | `?ratio=0.75` |
|
||||||
|
| `BooleanVar` | value → `True`; empty → `False` | `?enabled=true` (True), `?enabled=` (False) |
|
||||||
|
| `ChoiceVar` | choice value (not label) | `?role=edge` |
|
||||||
|
| `MultiChoiceVar` | choice values (repeat) | `?roles=edge&roles=core` |
|
||||||
|
| `ObjectVar(Device)` | PK (integer) | `?device=1` |
|
||||||
|
| `MultiObjectVar(Device)` | PKs (repeat) | `?devices=1&devices=2` |
|
||||||
|
| `IPAddressVar` | IP address | `?ip=198.51.100.10` |
|
||||||
|
| `IPAddressWithMaskVar` | IP address with mask | `?addr=192.0.2.1/24` |
|
||||||
|
| `IPNetworkVar` | IP network prefix | `?network=2001:db8::/64` |
|
||||||
|
| `DateVar` | date `YYYY-MM-DD` | `?date=2025-01-05` |
|
||||||
|
| `DateTimeVar` | ISO datetime | `?when=2025-01-05T14:30:00` |
|
||||||
|
| `FileVar` | — (not supported) | — |
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
- The parameter names above are examples; use the actual variable attribute names defined by the script.
|
||||||
|
- For `BooleanVar`, only an empty value (`?enabled=`) unchecks the box; any other value including `false` or `0` checks it.
|
||||||
|
- File uploads (`FileVar`) cannot be prefilled via URL parameters.
|
||||||
|
|
||||||
### Via the API
|
### Via the API
|
||||||
|
|
||||||
To run a script via the REST API, issue a POST request to the script's endpoint specifying the form data and commitment. For example, to run a script named `example.MyReport`, we would make a request such as the following:
|
To run a script via the REST API, issue a POST request to the script's endpoint specifying the form data and commitment. For example, to run a script named `example.MyReport`, we would make a request such as the following:
|
||||||
@@ -455,7 +499,7 @@ from extras.scripts import *
|
|||||||
|
|
||||||
class NewBranchScript(Script):
|
class NewBranchScript(Script):
|
||||||
|
|
||||||
class Meta:
|
class Meta(Script.Meta):
|
||||||
name = "New Branch"
|
name = "New Branch"
|
||||||
description = "Provision a new branch site"
|
description = "Provision a new branch site"
|
||||||
field_order = ['site_name', 'switch_count', 'switch_model']
|
field_order = ['site_name', 'switch_count', 'switch_model']
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ A dictionary mapping data backend types to their respective classes. These are u
|
|||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
### `filtersets`
|
||||||
|
|
||||||
|
A dictionary mapping each model (identified by its app and label) to its filterset class, if one has been registered for it. Filtersets are registered using the `@register_filterset` decorator.
|
||||||
|
|
||||||
### `model_features`
|
### `model_features`
|
||||||
|
|
||||||
A dictionary of model features (e.g. custom fields, tags, etc.) mapped to the functions used to qualify a model as supporting each feature. Model features are registered using the `register_model_feature()` function in `netbox.utils`.
|
A dictionary of model features (e.g. custom fields, tags, etc.) mapped to the functions used to qualify a model as supporting each feature. Model features are registered using the `register_model_feature()` function in `netbox.utils`.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Getting started with NetBox development is pretty straightforward, and should fe
|
|||||||
* A Linux system or compatible environment
|
* A Linux system or compatible environment
|
||||||
* A PostgreSQL server, which can be installed locally [per the documentation](../installation/1-postgresql.md)
|
* A PostgreSQL server, which can be installed locally [per the documentation](../installation/1-postgresql.md)
|
||||||
* A Redis server, which can also be [installed locally](../installation/2-redis.md)
|
* A Redis server, which can also be [installed locally](../installation/2-redis.md)
|
||||||
* Python 3.10 or later
|
* Python 3.12 or later
|
||||||
|
|
||||||
### 1. Fork the Repo
|
### 1. Fork the Repo
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ For end‑user guidance on resetting saved table layouts, see [Features > User P
|
|||||||
|
|
||||||
## Available Preferences
|
## Available Preferences
|
||||||
|
|
||||||
| Name | Description |
|
| Name | Description |
|
||||||
|--------------------------|---------------------------------------------------------------|
|
|----------------------------|---------------------------------------------------------------|
|
||||||
| data_format | Preferred format when rendering raw data (JSON or YAML) |
|
| `csv_delimiter` | The delimiting character used when exporting CSV data |
|
||||||
| pagination.per_page | The number of items to display per page of a paginated table |
|
| `data_format` | Preferred format when rendering raw data (JSON or YAML) |
|
||||||
| pagination.placement | Where to display the paginator controls relative to the table |
|
| `locale.language` | The language selected for UI translation |
|
||||||
| tables.${table}.columns | The ordered list of columns to display when viewing the table |
|
| `pagination.per_page` | The number of items to display per page of a paginated table |
|
||||||
| tables.${table}.ordering | A list of column names by which the table should be ordered |
|
| `pagination.placement` | Where to display the paginator controls relative to the table |
|
||||||
|
| `tables.${table}.columns` | The ordered list of columns to display when viewing the table |
|
||||||
|
| `tables.${table}.ordering` | A list of column names by which the table should be ordered |
|
||||||
|
| `ui.copilot_enabled` | Toggles the NetBox Copilot AI agent |
|
||||||
|
| `ui.tables.striping` | Toggles visual striping of tables in the UI |
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ NetBox's REST API, powered by the [Django REST Framework](https://www.django-res
|
|||||||
|
|
||||||
```no-highlight
|
```no-highlight
|
||||||
curl -s -X POST \
|
curl -s -X POST \
|
||||||
-H "Authorization: Token $TOKEN" \
|
-H "Authorization: Bearer $TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
http://netbox/api/ipam/prefixes/ \
|
http://netbox/api/ipam/prefixes/ \
|
||||||
--data '{"prefix": "192.0.2.0/24", "site": {"name": "Branch 12"}}'
|
--data '{"prefix": "192.0.2.0/24", "site": {"name": "Branch 12"}}'
|
||||||
|
|||||||
@@ -90,3 +90,10 @@ http://netbox:8000/api/extras/config-templates/123/render/ \
|
|||||||
"bar": 123
|
"bar": 123
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
!!! note "Permissions"
|
||||||
|
Rendering configuration templates via the REST API requires appropriate permissions for the relevant object type:
|
||||||
|
|
||||||
|
* To render a device's configuration via `/api/dcim/devices/{id}/render-config/`, assign a permission for "DCIM > Device" with the `render_config` action.
|
||||||
|
* To render a virtual machine's configuration via `/api/virtualization/virtual-machines/{id}/render-config/`, assign a permission for "Virtualization > Virtual Machine" with the `render_config` action.
|
||||||
|
* To render a config template directly via `/api/extras/config-templates/{id}/render/`, assign a permission for "Extras > Config Template" with the `render` action.
|
||||||
|
|||||||
10
docs/features/resource-ownership.md
Normal file
10
docs/features/resource-ownership.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# Resource Ownership
|
||||||
|
|
||||||
|
!!! info "This feature was introduced in NetBox v4.5."
|
||||||
|
|
||||||
|
Most objects in NetBox can be assigned an owner. An owner is a set of users and/or groups who are responsible for the administration of associated objects. For example, you might designate the operations team at a site as the owner for all prefixes and VLANs deployed at that site. The users and groups assigned to an owner are referred to as its members.
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Ownership of an object should not be confused with the concept of [tenancy](./tenancy.md), which indicates the dedication of an object to a specific tenant. For instance, a tenant might represent a customer served by the object, whereas an owner typically represents a set of internal users responsible for the management of the object.
|
||||||
|
|
||||||
|
Owners can be organized into groups for easier management.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
# Tenancy
|
# Tenancy
|
||||||
|
|
||||||
Most core objects within NetBox's data model support _tenancy_. This is the association of an object with a particular tenant to convey ownership or dependency. For example, an enterprise might represent its internal business units as tenants, whereas a managed services provider might create a tenant in NetBox to represent each of its customers.
|
Most core objects within NetBox's data model support _tenancy_. This is the association of an object with a particular tenant to convey assignment or dependency. For example, an enterprise might represent its internal business units as tenants, whereas a managed services provider might create a tenant in NetBox to represent each of its customers.
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
flowchart TD
|
flowchart TD
|
||||||
@@ -19,20 +19,36 @@ Tenants can be grouped by any logic that your use case demands, and groups can b
|
|||||||
|
|
||||||
Typically, the tenant model is used to represent a customer or internal organization, however it can be used for whatever purpose meets your needs.
|
Typically, the tenant model is used to represent a customer or internal organization, however it can be used for whatever purpose meets your needs.
|
||||||
|
|
||||||
Most core objects within NetBox can be assigned to particular tenant, so this model provides a very convenient way to correlate ownership across object types. For example, each of your customers might have its own racks, devices, IP addresses, circuits and so on: These can all be easily tracked via tenant assignment.
|
Most core objects within NetBox can be assigned to a particular tenant, so this model provides a very convenient way to correlate resource allocation across object types. For example, each of your customers might have its own racks, devices, IP addresses, circuits and so on: These can all be easily tracked via tenant assignment.
|
||||||
|
|
||||||
The following objects can be assigned to tenants:
|
The following objects can be assigned to tenants:
|
||||||
|
|
||||||
* Sites
|
* Circuits
|
||||||
|
* Circuit groups
|
||||||
|
* Virtual circuits
|
||||||
|
* Cables
|
||||||
|
* Devices
|
||||||
|
* Virtual device contexts
|
||||||
|
* Power feeds
|
||||||
* Racks
|
* Racks
|
||||||
* Rack reservations
|
* Rack reservations
|
||||||
* Devices
|
* Sites
|
||||||
* VRFs
|
* Locations
|
||||||
|
* ASNs
|
||||||
|
* ASN ranges
|
||||||
|
* Aggregates
|
||||||
* Prefixes
|
* Prefixes
|
||||||
|
* IP ranges
|
||||||
* IP addresses
|
* IP addresses
|
||||||
* VLANs
|
* VLANs
|
||||||
* Circuits
|
* VLAN groups
|
||||||
|
* VRFs
|
||||||
|
* Route targets
|
||||||
* Clusters
|
* Clusters
|
||||||
* Virtual machines
|
* Virtual machines
|
||||||
|
* L2VPNs
|
||||||
|
* Tunnels
|
||||||
|
* Wireless LANs
|
||||||
|
* Wireless links
|
||||||
|
|
||||||
Tenant assignment is used to signify the ownership of an object in NetBox. As such, each object may only be owned by a single tenant. For example, if you have a firewall dedicated to a particular customer, you would assign it to the tenant which represents that customer. However, if the firewall serves multiple customers, it doesn't *belong* to any particular customer, so tenant assignment would not be appropriate.
|
Tenancy represents the dedication of an object to a specific tenant. As such, each object may only be assigned to a single tenant. For example, if you have a firewall dedicated to a particular customer, you would assign it to the tenant which represents that customer. However, if the firewall serves multiple customers, it doesn't *belong* to any particular customer, so the assignment of a tenant would not be appropriate.
|
||||||
|
|||||||
@@ -34,9 +34,6 @@ Sets the default number of rows displayed on paginated tables.
|
|||||||
### Paginator placement
|
### Paginator placement
|
||||||
Controls where pagination controls are rendered relative to a table.
|
Controls where pagination controls are rendered relative to a table.
|
||||||
|
|
||||||
### HTMX navigation (experimental)
|
|
||||||
Enables partial‑page navigation for supported views. Disable this preference if unexpected behavior is observed.
|
|
||||||
|
|
||||||
### Striped table rows
|
### Striped table rows
|
||||||
Toggles alternating row backgrounds on tables.
|
Toggles alternating row backgrounds on tables.
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ This section of the documentation discusses installing and configuring the NetBo
|
|||||||
|
|
||||||
Begin by installing all system packages required by NetBox and its dependencies.
|
Begin by installing all system packages required by NetBox and its dependencies.
|
||||||
|
|
||||||
!!! warning "Python 3.10 or later required"
|
!!! warning "Python 3.12 or later required"
|
||||||
NetBox supports Python 3.10, 3.11, and 3.12.
|
NetBox supports only Python 3.12 or later.
|
||||||
|
|
||||||
```no-highlight
|
```no-highlight
|
||||||
sudo apt install -y python3 python3-pip python3-venv python3-dev \
|
sudo apt install -y python3 python3-pip python3-venv python3-dev \
|
||||||
@@ -15,7 +15,7 @@ build-essential libxml2-dev libxslt1-dev libffi-dev libpq-dev \
|
|||||||
libssl-dev zlib1g-dev
|
libssl-dev zlib1g-dev
|
||||||
```
|
```
|
||||||
|
|
||||||
Before continuing, check that your installed Python version is at least 3.10:
|
Before continuing, check that your installed Python version is at least 3.12:
|
||||||
|
|
||||||
```no-highlight
|
```no-highlight
|
||||||
python3 -V
|
python3 -V
|
||||||
@@ -120,6 +120,23 @@ If you are not yet sure what the domain name and/or IP address of the NetBox ins
|
|||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### API_TOKEN_PEPPERS
|
||||||
|
|
||||||
|
Define at least one random cryptographic pepper, identified by a numeric ID starting at 1. This will be used to generate SHA256 checksums for API tokens.
|
||||||
|
|
||||||
|
```python
|
||||||
|
API_TOKEN_PEPPERS = {
|
||||||
|
# DO NOT USE THIS EXAMPLE PEPPER IN PRODUCTION
|
||||||
|
1: 'kp7ht*76fiQAhUi5dHfASLlYUE_S^gI^(7J^K5M!LfoH@vl&b_',
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
As with [`SECRET_KEY`](#secret_key) below, you can use the `generate_secret_key.py` script to generate a random pepper:
|
||||||
|
```no-highlight
|
||||||
|
python3 ../generate_secret_key.py
|
||||||
|
```
|
||||||
|
|
||||||
### DATABASES
|
### DATABASES
|
||||||
|
|
||||||
This parameter holds the PostgreSQL database configuration details. The default database must be defined; additional databases may be defined as needed e.g. by plugins.
|
This parameter holds the PostgreSQL database configuration details. The default database must be defined; additional databases may be defined as needed e.g. by plugins.
|
||||||
@@ -235,10 +252,10 @@ Once NetBox has been configured, we're ready to proceed with the actual installa
|
|||||||
sudo /opt/netbox/upgrade.sh
|
sudo /opt/netbox/upgrade.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that **Python 3.10 or later is required** for NetBox v4.0 and later releases. If the default Python installation on your server is set to a lesser version, pass the path to the supported installation as an environment variable named `PYTHON`. (Note that the environment variable must be passed _after_ the `sudo` command.)
|
Note that **Python 3.12 or later is required** for NetBox v4.5 and later releases. If the default Python installation on your server is set to a lesser version, pass the path to the supported installation as an environment variable named `PYTHON`. (Note that the environment variable must be passed _after_ the `sudo` command.)
|
||||||
|
|
||||||
```no-highlight
|
```no-highlight
|
||||||
sudo PYTHON=/usr/bin/python3.10 /opt/netbox/upgrade.sh
|
sudo PYTHON=/usr/bin/python3.12 /opt/netbox/upgrade.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
|
|||||||
@@ -60,6 +60,3 @@ You should see output similar to the following:
|
|||||||
If the NetBox service fails to start, issue the command `journalctl -eu netbox` to check for log messages that may indicate the problem.
|
If the NetBox service fails to start, issue the command `journalctl -eu netbox` to check for log messages that may indicate the problem.
|
||||||
|
|
||||||
Once you've verified that the WSGI workers are up and running, move on to HTTP server setup.
|
Once you've verified that the WSGI workers are up and running, move on to HTTP server setup.
|
||||||
|
|
||||||
!!! note
|
|
||||||
There is a bug in the current stable release of gunicorn (v21.2.0) where automatic restarts of the worker processes can result in 502 errors under heavy load. (See [gunicorn bug #3038](https://github.com/benoitc/gunicorn/issues/3038) for more detail.) Users who encounter this issue may opt to downgrade to an earlier, unaffected release of gunicorn (`pip install gunicorn==20.1.0`). Note, however, that this earlier release does not officially support Python 3.11.
|
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ AUTH_LDAP_MIRROR_GROUPS = True
|
|||||||
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
||||||
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
||||||
"is_active": "cn=active,ou=groups,dc=example,dc=com",
|
"is_active": "cn=active,ou=groups,dc=example,dc=com",
|
||||||
"is_staff": "cn=staff,ou=groups,dc=example,dc=com",
|
|
||||||
"is_superuser": "cn=superuser,ou=groups,dc=example,dc=com"
|
"is_superuser": "cn=superuser,ou=groups,dc=example,dc=com"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +133,6 @@ AUTH_LDAP_CACHE_TIMEOUT = 3600
|
|||||||
```
|
```
|
||||||
|
|
||||||
* `is_active` - All users must be mapped to at least this group to enable authentication. Without this, users cannot log in.
|
* `is_active` - All users must be mapped to at least this group to enable authentication. Without this, users cannot log in.
|
||||||
* `is_staff` - Users mapped to this group are enabled for access to the administration tools; this is the equivalent of checking the "staff status" box on a manually created user. This doesn't grant any specific permissions.
|
|
||||||
* `is_superuser` - Users mapped to this group will be granted superuser status. Superusers are implicitly granted all permissions.
|
* `is_superuser` - Users mapped to this group will be granted superuser status. Superusers are implicitly granted all permissions.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
@@ -248,7 +246,6 @@ AUTH_LDAP_MIRROR_GROUPS = True
|
|||||||
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
||||||
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
||||||
"is_active": "cn=active,ou=groups,dc=example,dc=com",
|
"is_active": "cn=active,ou=groups,dc=example,dc=com",
|
||||||
"is_staff": "cn=staff,ou=groups,dc=example,dc=com",
|
|
||||||
"is_superuser": "cn=superuser,ou=groups,dc=example,dc=com"
|
"is_superuser": "cn=superuser,ou=groups,dc=example,dc=com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ The following sections detail how to set up a new instance of NetBox:
|
|||||||
|
|
||||||
| Dependency | Supported Versions |
|
| Dependency | Supported Versions |
|
||||||
|------------|--------------------|
|
|------------|--------------------|
|
||||||
| Python | 3.10, 3.11, 3.12 |
|
| Python | 3.12, 3.13, 3.14 |
|
||||||
| PostgreSQL | 14+ |
|
| PostgreSQL | 14+ |
|
||||||
| Redis | 4.0+ |
|
| Redis | 4.0+ |
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ NetBox requires the following dependencies:
|
|||||||
|
|
||||||
| Dependency | Supported Versions |
|
| Dependency | Supported Versions |
|
||||||
|------------|--------------------|
|
|------------|--------------------|
|
||||||
| Python | 3.10, 3.11, 3.12 |
|
| Python | 3.12, 3.13, 3.14 |
|
||||||
| PostgreSQL | 14+ |
|
| PostgreSQL | 14+ |
|
||||||
| Redis | 4.0+ |
|
| Redis | 4.0+ |
|
||||||
|
|
||||||
@@ -27,6 +27,7 @@ NetBox requires the following dependencies:
|
|||||||
|
|
||||||
| NetBox Version | Python min | Python max | PostgreSQL min | Redis min | Documentation |
|
| NetBox Version | Python min | Python max | PostgreSQL min | Redis min | Documentation |
|
||||||
|:--------------:|:----------:|:----------:|:--------------:|:---------:|:-----------------------------------------------------------------------------------------:|
|
|:--------------:|:----------:|:----------:|:--------------:|:---------:|:-----------------------------------------------------------------------------------------:|
|
||||||
|
| 4.5 | 3.12 | 3.14 | 14 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.5.0/docs/installation/index.md) |
|
||||||
| 4.4 | 3.10 | 3.12 | 14 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.4.0/docs/installation/index.md) |
|
| 4.4 | 3.10 | 3.12 | 14 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.4.0/docs/installation/index.md) |
|
||||||
| 4.3 | 3.10 | 3.12 | 14 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.3.0/docs/installation/index.md) |
|
| 4.3 | 3.10 | 3.12 | 14 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.3.0/docs/installation/index.md) |
|
||||||
| 4.2 | 3.10 | 3.12 | 13 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.2.0/docs/installation/index.md) |
|
| 4.2 | 3.10 | 3.12 | 13 | 4.0 | [Link](https://github.com/netbox-community/netbox/blob/v4.2.0/docs/installation/index.md) |
|
||||||
@@ -130,7 +131,7 @@ sudo ./upgrade.sh
|
|||||||
If the default version of Python is not at least 3.10, you'll need to pass the path to a supported Python version as an environment variable when calling the upgrade script. For example:
|
If the default version of Python is not at least 3.10, you'll need to pass the path to a supported Python version as an environment variable when calling the upgrade script. For example:
|
||||||
|
|
||||||
```no-highlight
|
```no-highlight
|
||||||
sudo PYTHON=/usr/bin/python3.10 ./upgrade.sh
|
sudo PYTHON=/usr/bin/python3.12 ./upgrade.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! note
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ Likewise, the site, rack, and device objects are located under the "DCIM" applic
|
|||||||
|
|
||||||
The full hierarchy of available endpoints can be viewed by navigating to the API root in a web browser.
|
The full hierarchy of available endpoints can be viewed by navigating to the API root in a web browser.
|
||||||
|
|
||||||
Each model generally has two views associated with it: a list view and a detail view. The list view is used to retrieve a list of multiple objects and to create new objects. The detail view is used to retrieve, update, or delete an single existing object. All objects are referenced by their numeric primary key (`id`).
|
Each model generally has two views associated with it: a list view and a detail view. The list view is used to retrieve a list of multiple objects and to create new objects. The detail view is used to retrieve, update, or delete a single existing object. All objects are referenced by their numeric primary key (`id`).
|
||||||
|
|
||||||
* `/api/dcim/devices/` - List existing devices or create a new device
|
* `/api/dcim/devices/` - List existing devices or create a new device
|
||||||
* `/api/dcim/devices/123/` - Retrieve, update, or delete the device with ID 123
|
* `/api/dcim/devices/123/` - Retrieve, update, or delete the device with ID 123
|
||||||
@@ -653,18 +653,22 @@ The NetBox REST API primarily employs token-based authentication. For convenienc
|
|||||||
|
|
||||||
### Tokens
|
### Tokens
|
||||||
|
|
||||||
A token is a unique identifier mapped to a NetBox user account. Each user may have one or more tokens which he or she can use for authentication when making REST API requests. To create a token, navigate to the API tokens page under your user profile.
|
A token is a secret, unique identifier mapped to a NetBox user account. Each user may have one or more tokens which he or she can use for authentication when making REST API requests. To create a token, navigate to the API tokens page under your user profile. When creating a token, NetBox will automatically populate a randomly-generated token value.
|
||||||
|
|
||||||
|
!!! note "Tokens cannot be retrieved once created"
|
||||||
|
Once a token has been created, its plaintext value cannot be retrieved. For this reason, you must take care to securely record the token locally immediately upon its creation. If a token plaintext is lost, it cannot be recovered: A new token must be created.
|
||||||
|
|
||||||
By default, all users can create and manage their own REST API tokens under the user control panel in the UI or via the REST API. This ability can be disabled by overriding the [`DEFAULT_PERMISSIONS`](../configuration/security.md#default_permissions) configuration parameter.
|
By default, all users can create and manage their own REST API tokens under the user control panel in the UI or via the REST API. This ability can be disabled by overriding the [`DEFAULT_PERMISSIONS`](../configuration/security.md#default_permissions) configuration parameter.
|
||||||
|
|
||||||
Each token contains a 160-bit key represented as 40 hexadecimal characters. When creating a token, you'll typically leave the key field blank so that a random key will be automatically generated. However, NetBox allows you to specify a key in case you need to restore a previously deleted token to operation.
|
|
||||||
|
|
||||||
Additionally, a token can be set to expire at a specific time. This can be useful if an external client needs to be granted temporary access to NetBox.
|
Additionally, a token can be set to expire at a specific time. This can be useful if an external client needs to be granted temporary access to NetBox.
|
||||||
|
|
||||||
!!! info "Restricting Token Retrieval"
|
#### v1 and v2 Tokens
|
||||||
The ability to retrieve the key value of a previously-created API token can be restricted by disabling the [`ALLOW_TOKEN_RETRIEVAL`](../configuration/security.md#allow_token_retrieval) configuration parameter.
|
|
||||||
|
|
||||||
### Restricting Write Operations
|
Beginning with NetBox v4.5, two versions of API token are supported, denoted as v1 and v2. Users are strongly encouraged to create only v2 tokens and to discontinue the use of v1 tokens. Support for v1 tokens will be removed in a future NetBox release.
|
||||||
|
|
||||||
|
v2 API tokens offer much stronger security. The token plaintext given at creation time is hashed together with a configured [cryptographic pepper](../configuration/required-parameters.md#api_token_peppers) to generate a unique checksum. This checksum is irreversible; the token plaintext is never stored on the server and thus cannot be retrieved even with database-level access.
|
||||||
|
|
||||||
|
#### Restricting Write Operations
|
||||||
|
|
||||||
By default, a token can be used to perform all actions via the API that a user would be permitted to do via the web UI. Deselecting the "write enabled" option will restrict API requests made with the token to read operations (e.g. GET) only.
|
By default, a token can be used to perform all actions via the API that a user would be permitted to do via the web UI. Deselecting the "write enabled" option will restrict API requests made with the token to read operations (e.g. GET) only.
|
||||||
|
|
||||||
@@ -681,10 +685,22 @@ It is possible to provision authentication tokens for other users via the REST A
|
|||||||
|
|
||||||
### Authenticating to the API
|
### Authenticating to the API
|
||||||
|
|
||||||
An authentication token is attached to a request by setting the `Authorization` header to the string `Token` followed by a space and the user's token:
|
An authentication token is included with a request in its `Authorization` header. The format of the header value depends on the version of token in use. v2 tokens use the following form, concatenating the token's prefix (`nbt_`) and key with its plaintext value, separated by a period:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -H "Authorization: Token $TOKEN" \
|
Authorization: Bearer nbt_<key>.<token>
|
||||||
|
```
|
||||||
|
|
||||||
|
Legacy v1 tokens use the prefix `Token` rather than `Bearer`, and include only the token plaintext. (v1 tokens do not have a key.)
|
||||||
|
|
||||||
|
```
|
||||||
|
Authorization: Token <token>
|
||||||
|
```
|
||||||
|
|
||||||
|
Below is an example REST API request utilizing a v2 token.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ curl -H "Authorization: Bearer nbt_4F9DAouzURLb.zjebxBPzICiPbWz0Wtx0fTL7bCKXKGTYhNzkgC2S" \
|
||||||
-H "Accept: application/json; indent=4" \
|
-H "Accept: application/json; indent=4" \
|
||||||
https://netbox/api/dcim/sites/
|
https://netbox/api/dcim/sites/
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,6 +21,21 @@ The cable's operational status. Choices include:
|
|||||||
* Planned
|
* Planned
|
||||||
* Decommissioning
|
* Decommissioning
|
||||||
|
|
||||||
|
### Profile
|
||||||
|
|
||||||
|
!!! note "This field was introduced in NetBox v4.5."
|
||||||
|
|
||||||
|
The profile to which the cable conforms. The profile determines the mapping of termination between the two ends and enables logical tracing across complex connections, such as breakout cables. Supported profiles are listed below.
|
||||||
|
|
||||||
|
* Straight (single position)
|
||||||
|
* Straight (multi-position)
|
||||||
|
* Shuffle (2x2 MPO8)
|
||||||
|
* Shuffle (4x4 MPO8)
|
||||||
|
|
||||||
|
A single-position cable is allowed only one termination point at each end. There is no limit to the number of terminations a multi-position cable may have. Each end of a cable must have the same number of terminations, unless connected to a pass-through port or to a circuit termination.
|
||||||
|
|
||||||
|
The assignment of a cable profile is optional. If no profile is assigned, legacy tracing behavior will be preserved.
|
||||||
|
|
||||||
### Type
|
### Type
|
||||||
|
|
||||||
The cable's physical medium or classification.
|
The cable's physical medium or classification.
|
||||||
|
|||||||
23
docs/models/users/owner.md
Normal file
23
docs/models/users/owner.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Owner
|
||||||
|
|
||||||
|
An owner is a set of users and/or groups who are responsible for the administration of certain resources within NetBox. The users and groups assigned to an owner are referred to as its members. Owner assignments are useful for indicating which parties are responsible for the administration of a particular object.
|
||||||
|
|
||||||
|
Most objects within NetBox can be assigned an owner, although this is not required.
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
### Name
|
||||||
|
|
||||||
|
The owner's name.
|
||||||
|
|
||||||
|
### Group
|
||||||
|
|
||||||
|
The [group](./ownergroup.md) to which the owner is assigned. The assignment of an owner to a group is optional.
|
||||||
|
|
||||||
|
### User Groups
|
||||||
|
|
||||||
|
Groups of users that are members of the owner.
|
||||||
|
|
||||||
|
### Users
|
||||||
|
|
||||||
|
Individual users that are members of the owner.
|
||||||
9
docs/models/users/ownergroup.md
Normal file
9
docs/models/users/ownergroup.md
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Owner Groups
|
||||||
|
|
||||||
|
Groups are used to correlate and organize [owners](./owner.md). The assignment of an owner to a group has no bearing on the relationship of owned objects to their owners.
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
### Name
|
||||||
|
|
||||||
|
The name of the group.
|
||||||
@@ -21,6 +21,13 @@ The VM's operational status.
|
|||||||
!!! tip
|
!!! tip
|
||||||
Additional statuses may be defined by setting `VirtualMachine.status` under the [`FIELD_CHOICES`](../../configuration/data-validation.md#field_choices) configuration parameter.
|
Additional statuses may be defined by setting `VirtualMachine.status` under the [`FIELD_CHOICES`](../../configuration/data-validation.md#field_choices) configuration parameter.
|
||||||
|
|
||||||
|
### Start on boot
|
||||||
|
|
||||||
|
The start on boot setting from the hypervisor.
|
||||||
|
|
||||||
|
!!! tip
|
||||||
|
Additional statuses may be defined by setting `VirtualMachine.start_on_boot` under the [`FIELD_CHOICES`](../../configuration/data-validation.md#field_choices) configuration parameter.
|
||||||
|
|
||||||
### Site & Cluster
|
### Site & Cluster
|
||||||
|
|
||||||
The [site](../dcim/site.md) and/or [cluster](./cluster.md) to which the VM is assigned.
|
The [site](../dcim/site.md) and/or [cluster](./cluster.md) to which the VM is assigned.
|
||||||
|
|||||||
@@ -60,6 +60,13 @@ Four of the standard Python logging levels are supported:
|
|||||||
|
|
||||||
Log entries recorded using the runner's logger will be saved in the job's log in the database in addition to being processed by other [system logging handlers](../../configuration/system.md#logging).
|
Log entries recorded using the runner's logger will be saved in the job's log in the database in addition to being processed by other [system logging handlers](../../configuration/system.md#logging).
|
||||||
|
|
||||||
|
### Jobs running for Model instances
|
||||||
|
|
||||||
|
A Job can be executed for a specific instance of a Model.
|
||||||
|
To enable this functionality, the model must include the `JobsMixin`.
|
||||||
|
|
||||||
|
When enqueuing a Job, you can associate it with a particular instance by passing that instance to the `instance` parameter.
|
||||||
|
|
||||||
### Scheduled Jobs
|
### Scheduled Jobs
|
||||||
|
|
||||||
As described above, jobs can be scheduled for immediate execution or at any later time using the `enqueue()` method. However, for management purposes, the `enqueue_once()` method allows a job to be scheduled exactly once avoiding duplicates. If a job is already scheduled for a particular instance, a second one won't be scheduled, respecting thread safety. An example use case would be to schedule a periodic task that is bound to an instance in general, but not to any event of that instance (such as updates). The parameters of the `enqueue_once()` method are identical to those of `enqueue()`.
|
As described above, jobs can be scheduled for immediate execution or at any later time using the `enqueue()` method. However, for management purposes, the `enqueue_once()` method allows a job to be scheduled exactly once avoiding duplicates. If a job is already scheduled for a particular instance, a second one won't be scheduled, respecting thread safety. An example use case would be to schedule a periodic task that is bound to an instance in general, but not to any event of that instance (such as updates). The parameters of the `enqueue_once()` method are identical to those of `enqueue()`.
|
||||||
@@ -73,9 +80,10 @@ As described above, jobs can be scheduled for immediate execution or at any late
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from core.choices import JobIntervalChoices
|
from core.choices import JobIntervalChoices
|
||||||
from netbox.models import NetBoxModel
|
from netbox.models import NetBoxModel
|
||||||
|
from netbox.models.features import JobsMixin
|
||||||
from .jobs import MyTestJob
|
from .jobs import MyTestJob
|
||||||
|
|
||||||
class MyModel(NetBoxModel):
|
class MyModel(JobsMixin, NetBoxModel):
|
||||||
foo = models.CharField()
|
foo = models.CharField()
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|||||||
@@ -55,6 +55,27 @@ class MyModelViewSet(...):
|
|||||||
filterset_class = filtersets.MyModelFilterSet
|
filterset_class = filtersets.MyModelFilterSet
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Implementing Quick Search
|
||||||
|
|
||||||
|
The `ObjectListView` has a field called Quick Search. For Quick Search to work the corresponding FilterSet has to override the `search` method that is implemented in `NetBoxModelFilterSet`. This function takes a queryset and can perform arbitrary operations on it and return it. A common use-case is to search for the given search value in multiple fields:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from django.db.models import Q
|
||||||
|
from netbox.filtersets import NetBoxModelFilterSet
|
||||||
|
|
||||||
|
class MyFilterSet(NetBoxModelFilterSet):
|
||||||
|
...
|
||||||
|
def search(self, queryset, name, value):
|
||||||
|
if not value.strip():
|
||||||
|
return queryset
|
||||||
|
return queryset.filter(
|
||||||
|
Q(name__icontains=value) |
|
||||||
|
Q(description__icontains=value)
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
The `search` method is also used by the `q` filter in `NetBoxModelFilterSet` which in turn is used by the Search field in the filters tab.
|
||||||
|
|
||||||
## Filter Classes
|
## Filter Classes
|
||||||
|
|
||||||
### TagFilter
|
### TagFilter
|
||||||
|
|||||||
@@ -173,12 +173,12 @@ classifiers=[
|
|||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
'Natural Language :: English',
|
'Natural Language :: English',
|
||||||
"Programming Language :: Python :: 3 :: Only",
|
"Programming Language :: Python :: 3 :: Only",
|
||||||
'Programming Language :: Python :: 3.10',
|
|
||||||
'Programming Language :: Python :: 3.11',
|
|
||||||
'Programming Language :: Python :: 3.12',
|
'Programming Language :: Python :: 3.12',
|
||||||
|
'Programming Language :: Python :: 3.13',
|
||||||
|
'Programming Language :: Python :: 3.14',
|
||||||
]
|
]
|
||||||
|
|
||||||
requires-python = ">=3.10.0"
|
requires-python = ">=3.12.0"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ python3 -m venv ~/.virtualenvs/my_plugin
|
|||||||
You can make NetBox available within this environment by creating a path file pointing to its location. This will add NetBox to the Python path upon activation. (Be sure to adjust the command below to specify your actual virtual environment path, Python version, and NetBox installation.)
|
You can make NetBox available within this environment by creating a path file pointing to its location. This will add NetBox to the Python path upon activation. (Be sure to adjust the command below to specify your actual virtual environment path, Python version, and NetBox installation.)
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
echo /opt/netbox/netbox > $VENV/lib/python3.10/site-packages/netbox.pth
|
echo /opt/netbox/netbox > $VENV/lib/python3.12/site-packages/netbox.pth
|
||||||
```
|
```
|
||||||
|
|
||||||
## Development Installation
|
## Development Installation
|
||||||
|
|||||||
@@ -64,14 +64,17 @@ item1 = PluginMenuItem(
|
|||||||
|
|
||||||
A `PluginMenuItem` has the following attributes:
|
A `PluginMenuItem` has the following attributes:
|
||||||
|
|
||||||
| Attribute | Required | Description |
|
| Attribute | Required | Description |
|
||||||
|-----------------|----------|----------------------------------------------------------------------------------------------------------|
|
|-----------------|----------|------------------------------------------------------|
|
||||||
| `link` | Yes | Name of the URL path to which this menu item links |
|
| `link` | Yes | Name of the URL path to which this menu item links |
|
||||||
| `link_text` | Yes | The text presented to the user |
|
| `link_text` | Yes | The text presented to the user |
|
||||||
| `permissions` | - | A list of permissions required to display this link |
|
| `permissions` | - | A list of permissions required to display this link |
|
||||||
| `auth_required` | - | Display only for authenticated users |
|
| `auth_required` | - | Display only for authenticated users |
|
||||||
| `staff_only` | - | Display only for users who have `is_staff` set to true (any specified permissions will also be required) |
|
| `staff_only` | - | Display only for superusers |
|
||||||
| `buttons` | - | An iterable of PluginMenuButton instances to include |
|
| `buttons` | - | An iterable of PluginMenuButton instances to include |
|
||||||
|
|
||||||
|
!!! note "Changed in NetBox v4.5"
|
||||||
|
In releases prior to NetBox v4.5, `staff_only` restricted display of a menu item to only users with `is_staff` set to True. In NetBox v4.5, the `is_staff` flag was removed from the user model. Menu items with `staff_only` set to True are now displayed only for superusers.
|
||||||
|
|
||||||
## Menu Buttons
|
## Menu Buttons
|
||||||
|
|
||||||
|
|||||||
148
docs/plugins/development/ui-components.md
Normal file
148
docs/plugins/development/ui-components.md
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
# UI Components
|
||||||
|
|
||||||
|
!!! note "New in NetBox v4.5"
|
||||||
|
All UI components described here were introduced in NetBox v4.5. Be sure to set the minimum NetBox version to 4.5.0 for your plugin before incorporating any of these resources.
|
||||||
|
|
||||||
|
!!! danger "Beta Feature"
|
||||||
|
UI components are considered a beta feature, and are still under active development. Please be aware that the API for resources on this page is subject to change in future releases.
|
||||||
|
|
||||||
|
To simply the process of designing your plugin's user interface, and to encourage a consistent look and feel throughout the entire application, NetBox provides a set of components that enable programmatic UI design. These make it possible to declare complex page layouts with little or no custom HTML.
|
||||||
|
|
||||||
|
## Page Layout
|
||||||
|
|
||||||
|
A layout defines the general arrangement of content on a page into rows and columns. The layout is defined under the [view](./views.md) and declares a set of rows, each of which may have one or more columns. Below is an example layout.
|
||||||
|
|
||||||
|
```
|
||||||
|
+-------+-------+-------+
|
||||||
|
| Col 1 | Col 2 | Col 3 |
|
||||||
|
+-------+-------+-------+
|
||||||
|
| Col 4 |
|
||||||
|
+-----------+-----------+
|
||||||
|
| Col 5 | Col 6 |
|
||||||
|
+-----------+-----------+
|
||||||
|
```
|
||||||
|
|
||||||
|
The above layout can be achieved with the following declaration under a view:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from netbox.ui import layout
|
||||||
|
from netbox.views import generic
|
||||||
|
|
||||||
|
class MyView(generic.ObjectView):
|
||||||
|
layout = layout.Layout(
|
||||||
|
layout.Row(
|
||||||
|
layout.Column(),
|
||||||
|
layout.Column(),
|
||||||
|
layout.Column(),
|
||||||
|
),
|
||||||
|
layout.Row(
|
||||||
|
layout.Column(),
|
||||||
|
),
|
||||||
|
layout.Row(
|
||||||
|
layout.Column(),
|
||||||
|
layout.Column(),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! note
|
||||||
|
Currently, layouts are supported only for subclasses of [`generic.ObjectView`](./views.md#netbox.views.generic.ObjectView).
|
||||||
|
|
||||||
|
::: netbox.ui.layout.Layout
|
||||||
|
|
||||||
|
::: netbox.ui.layout.SimpleLayout
|
||||||
|
|
||||||
|
::: netbox.ui.layout.Row
|
||||||
|
|
||||||
|
::: netbox.ui.layout.Column
|
||||||
|
|
||||||
|
## Panels
|
||||||
|
|
||||||
|
Within each column, related blocks of content are arranged into panels. Each panel has a title and may have a set of associated actions, but the content within is otherwise arbitrary.
|
||||||
|
|
||||||
|
Plugins can define their own panels by inheriting from the base class `netbox.ui.panels.Panel`. Override the `get_context()` method to pass additional context to your custom panel template. An example is provided below.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from netbox.ui.panels import Panel
|
||||||
|
|
||||||
|
class RecentChangesPanel(Panel):
|
||||||
|
template_name = 'my_plugin/panels/recent_changes.html'
|
||||||
|
title = _('Recent Changes')
|
||||||
|
|
||||||
|
def get_context(self, context):
|
||||||
|
return {
|
||||||
|
**super().get_context(context),
|
||||||
|
'changes': get_changes()[:10],
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
NetBox also includes a set of panels suite for specific uses, such as display object details or embedding a table of related objects. These are listed below.
|
||||||
|
|
||||||
|
::: netbox.ui.panels.Panel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.ObjectPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.ObjectAttributesPanel
|
||||||
|
|
||||||
|
#### Object Attributes
|
||||||
|
|
||||||
|
The following classes are available to represent object attributes within an ObjectAttributesPanel. Additionally, plugins can subclass `netbox.ui.attrs.ObjectAttribute` to create custom classes.
|
||||||
|
|
||||||
|
| Class | Description |
|
||||||
|
|--------------------------------------|--------------------------------------------------|
|
||||||
|
| `netbox.ui.attrs.AddressAttr` | A physical or mailing address. |
|
||||||
|
| `netbox.ui.attrs.BooleanAttr` | A boolean value |
|
||||||
|
| `netbox.ui.attrs.ColorAttr` | A color expressed in RGB |
|
||||||
|
| `netbox.ui.attrs.ChoiceAttr` | A selection from a set of choices |
|
||||||
|
| `netbox.ui.attrs.GPSCoordinatesAttr` | GPS coordinates (latitude and longitude) |
|
||||||
|
| `netbox.ui.attrs.ImageAttr` | An attached image (displays the image) |
|
||||||
|
| `netbox.ui.attrs.NestedObjectAttr` | A related nested object |
|
||||||
|
| `netbox.ui.attrs.NumericAttr` | An integer or float value |
|
||||||
|
| `netbox.ui.attrs.RelatedObjectAttr` | A related object |
|
||||||
|
| `netbox.ui.attrs.TemplatedAttr` | Renders an attribute using a custom template |
|
||||||
|
| `netbox.ui.attrs.TextAttr` | A string (text) value |
|
||||||
|
| `netbox.ui.attrs.TimezoneAttr` | A timezone with annotated offset |
|
||||||
|
| `netbox.ui.attrs.UtilizationAttr` | A numeric value expressed as a utilization graph |
|
||||||
|
|
||||||
|
::: netbox.ui.panels.OrganizationalObjectPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.NestedGroupObjectPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.CommentsPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.JSONPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.RelatedObjectsPanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.ObjectsTablePanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.TemplatePanel
|
||||||
|
|
||||||
|
::: netbox.ui.panels.PluginContentPanel
|
||||||
|
|
||||||
|
## Panel Actions
|
||||||
|
|
||||||
|
Each panel may have actions associated with it. These render as links or buttons within the panel header, opposite the panel's title. For example, a common use case is to include an "Add" action on a panel which displays a list of objects. Below is an example of this.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from netbox.ui import actions, panels
|
||||||
|
|
||||||
|
panels.ObjectsTablePanel(
|
||||||
|
model='dcim.Region',
|
||||||
|
title=_('Child Regions'),
|
||||||
|
filters={'parent_id': lambda ctx: ctx['object'].pk},
|
||||||
|
actions=[
|
||||||
|
actions.AddObject('dcim.Region', url_params={'parent': lambda ctx: ctx['object'].pk}),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
```
|
||||||
|
|
||||||
|
::: netbox.ui.actions.PanelAction
|
||||||
|
|
||||||
|
::: netbox.ui.actions.LinkAction
|
||||||
|
|
||||||
|
::: netbox.ui.actions.AddObject
|
||||||
|
|
||||||
|
::: netbox.ui.actions.CopyContent
|
||||||
@@ -1,5 +1,133 @@
|
|||||||
# NetBox v4.4
|
# NetBox v4.4
|
||||||
|
|
||||||
|
## v4.4.7 (2025-11-25)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#20371](https://github.com/netbox-community/netbox/issues/20371) - Add Molex Micro-Fit 2x3 for power ports & power outlets
|
||||||
|
* [#20731](https://github.com/netbox-community/netbox/issues/20731) - Enable specifying `data_source` & `data_file` when bulk import config templates
|
||||||
|
* [#20820](https://github.com/netbox-community/netbox/issues/20820) - Enable filtering of custom fields by object type
|
||||||
|
* [#20823](https://github.com/netbox-community/netbox/issues/20823) - Disallow creation of API tokens with an expiration date in the past
|
||||||
|
* [#20841](https://github.com/netbox-community/netbox/issues/20841) - Support advanced filtering for available rack types when creating/editing a rack
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#20134](https://github.com/netbox-community/netbox/issues/20134) - Prevent out-of-band HTMX content swaps in embedded tables
|
||||||
|
* [#20432](https://github.com/netbox-community/netbox/issues/20432) - Fix tracing of cables across multiple circuits in parallel
|
||||||
|
* [#20465](https://github.com/netbox-community/netbox/issues/20465) - Ensure that scripts are updated immediately when a new file is uploaded
|
||||||
|
* [#20638](https://github.com/netbox-community/netbox/issues/20638) - Correct OpenAPI schema for bulk create operations
|
||||||
|
* [#20649](https://github.com/netbox-community/netbox/issues/20649) - Enforce view permissions on REST API endpoint for custom scripts
|
||||||
|
* [#20740](https://github.com/netbox-community/netbox/issues/20740) - Ensure permissions constraints are enforced when executing custom scripts via the REST API
|
||||||
|
* [#20743](https://github.com/netbox-community/netbox/issues/20743) - Pass request context to custom script when triggered by an event rule
|
||||||
|
* [#20766](https://github.com/netbox-community/netbox/issues/20766) - Fix inadvertent translations on server error page
|
||||||
|
* [#20775](https://github.com/netbox-community/netbox/issues/20775) - Fix `TypeError` exception when bulk renaming unnamed devices
|
||||||
|
* [#20822](https://github.com/netbox-community/netbox/issues/20822) - Add missing `auto_sync_enabled` field in bulk edit forms
|
||||||
|
* [#20827](https://github.com/netbox-community/netbox/issues/20827) - Fix UI styling issue when toggling between light and dark mode
|
||||||
|
* [#20839](https://github.com/netbox-community/netbox/issues/20839) - Fix filtering by object type in UI for custom links and saved filters
|
||||||
|
* [#20840](https://github.com/netbox-community/netbox/issues/20840) - Remove extraneous references to airflow for RackType model
|
||||||
|
* [#20844](https://github.com/netbox-community/netbox/issues/20844) - Fix object type filter for L2VPN terminations
|
||||||
|
* [#20859](https://github.com/netbox-community/netbox/issues/20859) - Prevent dashboard crash due to exception raised by a widget
|
||||||
|
* [#20865](https://github.com/netbox-community/netbox/issues/20865) - Enforce proper min/max values for latitude & longitude fields
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v4.4.6 (2025-11-11)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#14171](https://github.com/netbox-community/netbox/issues/14171) - Support VLAN assignment for device & VM interfaces being bulk imported
|
||||||
|
* [#20297](https://github.com/netbox-community/netbox/issues/20297) - Introduce additional coaxial cable types
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#20378](https://github.com/netbox-community/netbox/issues/20378) - Prevent exception when attempting to delete a data source utilized by a custom script
|
||||||
|
* [#20645](https://github.com/netbox-community/netbox/issues/20645) - CSVChoiceField should defer to model field's default value when CSV field is empty
|
||||||
|
* [#20647](https://github.com/netbox-community/netbox/issues/20647) - Improve handling of empty strings during bulk imports
|
||||||
|
* [#20653](https://github.com/netbox-community/netbox/issues/20653) - Fix filtering of jobs by object type ID
|
||||||
|
* [#20660](https://github.com/netbox-community/netbox/issues/20660) - Optimize loading of custom script modules from remote storage
|
||||||
|
* [#20670](https://github.com/netbox-community/netbox/issues/20670) - Improve validation of related objects during bulk import
|
||||||
|
* [#20688](https://github.com/netbox-community/netbox/issues/20688) - Suppress non-harmful "No active configuration revision found" warning message
|
||||||
|
* [#20697](https://github.com/netbox-community/netbox/issues/20697) - Prevent duplication of signals which increment/decrement related object counts
|
||||||
|
* [#20699](https://github.com/netbox-community/netbox/issues/20699) - Ensure proper ordering of changelog entries resulting from cascading deletions
|
||||||
|
* [#20713](https://github.com/netbox-community/netbox/issues/20713) - Ensure a pre-change snapshot is recorded on virtual chassis members being added/removed
|
||||||
|
* [#20721](https://github.com/netbox-community/netbox/issues/20721) - Fix breadcrumb navigation links in UI for background tasks
|
||||||
|
* [#20738](https://github.com/netbox-community/netbox/issues/20738) - Deleting a virtual chassis should nullify the `vc_position` of all former members
|
||||||
|
* [#20750](https://github.com/netbox-community/netbox/issues/20750) - Fix cloning of permissions when only one action is enabled
|
||||||
|
* [#20755](https://github.com/netbox-community/netbox/issues/20755) - Prevent duplicate results under certain conditions when filtering providers
|
||||||
|
* [#20771](https://github.com/netbox-community/netbox/issues/20771) - Comments are required when creating a new journal entry
|
||||||
|
* [#20774](https://github.com/netbox-community/netbox/issues/20774) - Bulk action button labels should be translated
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v4.4.5 (2025-10-28)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#19751](https://github.com/netbox-community/netbox/issues/19751) - Disable occupied module bays in form dropdowns when installing a new module
|
||||||
|
* [#20301](https://github.com/netbox-community/netbox/issues/20301) - Add a "dismiss all" option to the notifications dropdown
|
||||||
|
* [#20399](https://github.com/netbox-community/netbox/issues/20399) - Add `assigned` and `primary` boolean filters for MAC addresses
|
||||||
|
* [#20567](https://github.com/netbox-community/netbox/issues/20567) - Add contacts column to services table
|
||||||
|
* [#20675](https://github.com/netbox-community/netbox/issues/20675) - Enable [NetBox Copilot](https://netboxlabs.com/products/netbox-copilot/) integration
|
||||||
|
* [#20692](https://github.com/netbox-community/netbox/issues/20692) - Add contacts column to IP addresses table
|
||||||
|
* [#20700](https://github.com/netbox-community/netbox/issues/20700) - Add contacts table column for various additional models
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#19872](https://github.com/netbox-community/netbox/issues/19872) - Ensure custom script validation failures display error messages
|
||||||
|
* [#20389](https://github.com/netbox-community/netbox/issues/20389) - Fix "select all" behavior for bulk rename views
|
||||||
|
* [#20422](https://github.com/netbox-community/netbox/issues/20422) - Enable filtering of aggregates and prefixes by family in GraphQL API
|
||||||
|
* [#20459](https://github.com/netbox-community/netbox/issues/20459) - Fix validation of `is_oob` & `is_primary` fields under IP address bulk import
|
||||||
|
* [#20466](https://github.com/netbox-community/netbox/issues/20466) - Fix querying of devices with a primary IP assigned in GraphQL API
|
||||||
|
* [#20498](https://github.com/netbox-community/netbox/issues/20498) - Enforce the validation regex (if set) for custom URL fields
|
||||||
|
* [#20524](https://github.com/netbox-community/netbox/issues/20524) - Raise a validation error when attempting to schedule a custom script for a past date/time
|
||||||
|
* [#20541](https://github.com/netbox-community/netbox/issues/20541) - Fix resolution of GraphQL object fields which rely on custom filters
|
||||||
|
* [#20551](https://github.com/netbox-community/netbox/issues/20551) - Fix automatic slug generation in quick-add UI form
|
||||||
|
* [#20606](https://github.com/netbox-community/netbox/issues/20606) - Enable copying of values from table columns rendered as badges
|
||||||
|
* [#20641](https://github.com/netbox-community/netbox/issues/20641) - Fix `AttributeError` exception raised by the object changes REST API endpoint
|
||||||
|
* [#20646](https://github.com/netbox-community/netbox/issues/20646) - Prevent cables from connecting to objects marked as connected
|
||||||
|
* [#20655](https://github.com/netbox-community/netbox/issues/20655) - Fix `FieldError` exception when attempting to sort permissions list by actions
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v4.4.4 (2025-10-15)
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#20554](https://github.com/netbox-community/netbox/issues/20554) - Fix generic relation filters to accept `<app>.<model>` format matching POST requests
|
||||||
|
* [#20574](https://github.com/netbox-community/netbox/issues/20574) - Fix excessive storage initialization overhead when listing scripts with remote backends
|
||||||
|
* [#20584](https://github.com/netbox-community/netbox/issues/20584) - Enforce PoE mode requirement on interface templates when PoE type is set
|
||||||
|
* [#20585](https://github.com/netbox-community/netbox/issues/20585) - Fix API schema generation crash for models with single-field UniqueConstraints
|
||||||
|
* [#20587](https://github.com/netbox-community/netbox/issues/20587) - Fix upgrade.sh failure when removing stale content types
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## v4.4.3 (2025-10-14)
|
||||||
|
|
||||||
|
### Enhancements
|
||||||
|
|
||||||
|
* [#20426](https://github.com/netbox-community/netbox/issues/20426) - Add a copy-to-clipboard button for custom script output
|
||||||
|
* [#20516](https://github.com/netbox-community/netbox/issues/20516) - Improve rendering of VLAN ID ranges in VLAN group tables
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* [#19302](https://github.com/netbox-community/netbox/issues/19302) - Fix uniqueness validation in REST API for nullable fields
|
||||||
|
* [#19615](https://github.com/netbox-community/netbox/issues/19615) - Fix support for static file parameters in templates when external storage is in use
|
||||||
|
* [#19818](https://github.com/netbox-community/netbox/issues/19818) - Hide primary IP assignment fields when creating a new virtual machine in the UI
|
||||||
|
* [#19825](https://github.com/netbox-community/netbox/issues/19825) - Prevent cache for config revisions from being erroneously overwritten when debugging is enabled
|
||||||
|
* [#20140](https://github.com/netbox-community/netbox/issues/20140) - Changing a site's region or group should update any associated circuit terminations
|
||||||
|
* [#20156](https://github.com/netbox-community/netbox/issues/20156) - Fix display of rack elevation labels
|
||||||
|
* [#20290](https://github.com/netbox-community/netbox/issues/20290) - Fix migration error when upgrading to NetBox v4.4 from releases earlier than v4.3
|
||||||
|
* [#20471](https://github.com/netbox-community/netbox/issues/20471) - Saving an unmodified VLAN group should not generate a change record
|
||||||
|
* [#20475](https://github.com/netbox-community/netbox/issues/20475) - Collapse singleton VLAN IDs in VLAN group display
|
||||||
|
* [#20494](https://github.com/netbox-community/netbox/issues/20494) - Correct OpenAPI schema definition for `IntegerRangeSerializer`
|
||||||
|
* [#20496](https://github.com/netbox-community/netbox/issues/20496) - REST API should always honor `MAX_PAGE_SIZE` value
|
||||||
|
* [#20497](https://github.com/netbox-community/netbox/issues/20497) - Fix filtering of VLAN groups by VLAN ID range in GraphQL API
|
||||||
|
* [#20507](https://github.com/netbox-community/netbox/issues/20507) - Fix support for fetching ASN contacts via GraphQL API
|
||||||
|
* [#20523](https://github.com/netbox-community/netbox/issues/20523) - Hide password change form for users authenticated via SSO
|
||||||
|
* [#20542](https://github.com/netbox-community/netbox/issues/20542) - Fix the creation of MAC addresses using the "quick add" form
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## v4.4.2 (2025-09-30)
|
## v4.4.2 (2025-09-30)
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
|||||||
@@ -77,6 +77,7 @@ nav:
|
|||||||
- Wireless: 'features/wireless.md'
|
- Wireless: 'features/wireless.md'
|
||||||
- Virtualization: 'features/virtualization.md'
|
- Virtualization: 'features/virtualization.md'
|
||||||
- VPN Tunnels: 'features/vpn-tunnels.md'
|
- VPN Tunnels: 'features/vpn-tunnels.md'
|
||||||
|
- Resource Ownership: 'features/resource-ownership.md'
|
||||||
- Tenancy: 'features/tenancy.md'
|
- Tenancy: 'features/tenancy.md'
|
||||||
- Contacts: 'features/contacts.md'
|
- Contacts: 'features/contacts.md'
|
||||||
- Search: 'features/search.md'
|
- Search: 'features/search.md'
|
||||||
@@ -142,6 +143,7 @@ nav:
|
|||||||
- Getting Started: 'plugins/development/index.md'
|
- Getting Started: 'plugins/development/index.md'
|
||||||
- Models: 'plugins/development/models.md'
|
- Models: 'plugins/development/models.md'
|
||||||
- Views: 'plugins/development/views.md'
|
- Views: 'plugins/development/views.md'
|
||||||
|
- UI Components: 'plugins/development/ui-components.md'
|
||||||
- Navigation: 'plugins/development/navigation.md'
|
- Navigation: 'plugins/development/navigation.md'
|
||||||
- Templates: 'plugins/development/templates.md'
|
- Templates: 'plugins/development/templates.md'
|
||||||
- Tables: 'plugins/development/tables.md'
|
- Tables: 'plugins/development/tables.md'
|
||||||
@@ -273,6 +275,9 @@ nav:
|
|||||||
- ContactRole: 'models/tenancy/contactrole.md'
|
- ContactRole: 'models/tenancy/contactrole.md'
|
||||||
- Tenant: 'models/tenancy/tenant.md'
|
- Tenant: 'models/tenancy/tenant.md'
|
||||||
- TenantGroup: 'models/tenancy/tenantgroup.md'
|
- TenantGroup: 'models/tenancy/tenantgroup.md'
|
||||||
|
- Users:
|
||||||
|
- Owner: 'models/users/owner.md'
|
||||||
|
- OwnerGroup: 'models/users/ownergroup.md'
|
||||||
- Virtualization:
|
- Virtualization:
|
||||||
- Cluster: 'models/virtualization/cluster.md'
|
- Cluster: 'models/virtualization/cluster.md'
|
||||||
- ClusterGroup: 'models/virtualization/clustergroup.md'
|
- ClusterGroup: 'models/virtualization/clustergroup.md'
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
from django.utils.translation import gettext as _
|
|
||||||
|
|
||||||
from account.models import UserToken
|
|
||||||
from netbox.tables import NetBoxTable, columns
|
|
||||||
|
|
||||||
__all__ = (
|
|
||||||
'UserTokenTable',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
TOKEN = """<samp><span id="token_{{ record.pk }}">{{ record }}</span></samp>"""
|
|
||||||
|
|
||||||
ALLOWED_IPS = """{{ value|join:", " }}"""
|
|
||||||
|
|
||||||
COPY_BUTTON = """
|
|
||||||
{% if settings.ALLOW_TOKEN_RETRIEVAL %}
|
|
||||||
{% copy_content record.pk prefix="token_" color="success" %}
|
|
||||||
{% endif %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class UserTokenTable(NetBoxTable):
|
|
||||||
"""
|
|
||||||
Table for users to manager their own API tokens under account views.
|
|
||||||
"""
|
|
||||||
key = columns.TemplateColumn(
|
|
||||||
verbose_name=_('Key'),
|
|
||||||
template_code=TOKEN,
|
|
||||||
)
|
|
||||||
write_enabled = columns.BooleanColumn(
|
|
||||||
verbose_name=_('Write Enabled')
|
|
||||||
)
|
|
||||||
created = columns.DateTimeColumn(
|
|
||||||
timespec='minutes',
|
|
||||||
verbose_name=_('Created'),
|
|
||||||
)
|
|
||||||
expires = columns.DateTimeColumn(
|
|
||||||
timespec='minutes',
|
|
||||||
verbose_name=_('Expires'),
|
|
||||||
)
|
|
||||||
last_used = columns.DateTimeColumn(
|
|
||||||
verbose_name=_('Last Used'),
|
|
||||||
)
|
|
||||||
allowed_ips = columns.TemplateColumn(
|
|
||||||
verbose_name=_('Allowed IPs'),
|
|
||||||
template_code=ALLOWED_IPS
|
|
||||||
)
|
|
||||||
actions = columns.ActionsColumn(
|
|
||||||
actions=('edit', 'delete'),
|
|
||||||
extra_buttons=COPY_BUTTON
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
|
||||||
model = UserToken
|
|
||||||
fields = (
|
|
||||||
'pk', 'id', 'key', 'description', 'write_enabled', 'created', 'expires', 'last_used', 'allowed_ips',
|
|
||||||
)
|
|
||||||
@@ -25,9 +25,12 @@ from extras.models import Bookmark
|
|||||||
from extras.tables import BookmarkTable, NotificationTable, SubscriptionTable
|
from extras.tables import BookmarkTable, NotificationTable, SubscriptionTable
|
||||||
from netbox.authentication import get_auth_backend_display, get_saml_idps
|
from netbox.authentication import get_auth_backend_display, get_saml_idps
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
|
from netbox.ui import layout
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from users import forms, tables
|
from users import forms
|
||||||
from users.models import UserConfig
|
from users.models import UserConfig
|
||||||
|
from users.tables import TokenTable
|
||||||
|
from users.ui.panels import TokenExamplePanel, TokenPanel
|
||||||
from utilities.request import safe_for_redirect
|
from utilities.request import safe_for_redirect
|
||||||
from utilities.string import remove_linebreaks
|
from utilities.string import remove_linebreaks
|
||||||
from utilities.views import register_model_view
|
from utilities.views import register_model_view
|
||||||
@@ -328,7 +331,8 @@ class UserTokenListView(LoginRequiredMixin, View):
|
|||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
tokens = UserToken.objects.filter(user=request.user)
|
tokens = UserToken.objects.filter(user=request.user)
|
||||||
table = tables.UserTokenTable(tokens)
|
table = TokenTable(tokens)
|
||||||
|
table.columns.hide('user')
|
||||||
table.configure(request)
|
table.configure(request)
|
||||||
|
|
||||||
return render(request, 'account/token_list.html', {
|
return render(request, 'account/token_list.html', {
|
||||||
@@ -340,14 +344,21 @@ class UserTokenListView(LoginRequiredMixin, View):
|
|||||||
|
|
||||||
@register_model_view(UserToken)
|
@register_model_view(UserToken)
|
||||||
class UserTokenView(LoginRequiredMixin, View):
|
class UserTokenView(LoginRequiredMixin, View):
|
||||||
|
layout = layout.SimpleLayout(
|
||||||
|
left_panels=[
|
||||||
|
TokenPanel(),
|
||||||
|
],
|
||||||
|
right_panels=[
|
||||||
|
TokenExamplePanel(),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get(self, request, pk):
|
def get(self, request, pk):
|
||||||
token = get_object_or_404(UserToken.objects.filter(user=request.user), pk=pk)
|
token = get_object_or_404(UserToken.objects.filter(user=request.user), pk=pk)
|
||||||
key = token.key if settings.ALLOW_TOKEN_RETRIEVAL else None
|
|
||||||
|
|
||||||
return render(request, 'account/token.html', {
|
return render(request, 'account/token.html', {
|
||||||
'object': token,
|
'object': token,
|
||||||
'key': key,
|
'layout': self.layout,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from drf_spectacular.utils import extend_schema_field
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from circuits.choices import CircuitPriorityChoices, CircuitStatusChoices, VirtualCircuitTerminationRoleChoices
|
from circuits.choices import CircuitPriorityChoices, CircuitStatusChoices, VirtualCircuitTerminationRoleChoices
|
||||||
@@ -11,10 +10,12 @@ from circuits.models import (
|
|||||||
from dcim.api.serializers_.device_components import InterfaceSerializer
|
from dcim.api.serializers_.device_components import InterfaceSerializer
|
||||||
from dcim.api.serializers_.cables import CabledObjectSerializer
|
from dcim.api.serializers_.cables import CabledObjectSerializer
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
|
from netbox.api.serializers import (
|
||||||
|
NetBoxModelSerializer, OrganizationalModelSerializer, PrimaryModelSerializer, WritableNestedSerializer,
|
||||||
|
)
|
||||||
from netbox.choices import DistanceUnitChoices
|
from netbox.choices import DistanceUnitChoices
|
||||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
|
||||||
from .providers import ProviderAccountSerializer, ProviderNetworkSerializer, ProviderSerializer
|
from .providers import ProviderAccountSerializer, ProviderNetworkSerializer, ProviderSerializer
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -29,7 +30,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeSerializer(NetBoxModelSerializer):
|
class CircuitTypeSerializer(OrganizationalModelSerializer):
|
||||||
|
|
||||||
# Related object counts
|
# Related object counts
|
||||||
circuit_count = RelatedObjectCountField('circuits')
|
circuit_count = RelatedObjectCountField('circuits')
|
||||||
@@ -37,8 +38,8 @@ class CircuitTypeSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitType
|
model = CircuitType
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'color', 'description', 'tags', 'custom_fields',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'color', 'description', 'owner', 'tags',
|
||||||
'created', 'last_updated', 'circuit_count',
|
'custom_fields', 'created', 'last_updated', 'circuit_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'circuit_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'circuit_count')
|
||||||
|
|
||||||
@@ -53,7 +54,7 @@ class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
|
|||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
|
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
|
||||||
termination = serializers.SerializerMethodField(read_only=True)
|
termination = GFKSerializerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitTermination
|
model = CircuitTermination
|
||||||
@@ -62,24 +63,16 @@ class CircuitCircuitTerminationSerializer(WritableNestedSerializer):
|
|||||||
'upstream_speed', 'xconnect_id', 'description',
|
'upstream_speed', 'xconnect_id', 'description',
|
||||||
]
|
]
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_termination(self, obj):
|
|
||||||
if obj.termination_id is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.termination)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.termination, nested=True, context=context).data
|
|
||||||
|
|
||||||
|
class CircuitGroupSerializer(OrganizationalModelSerializer):
|
||||||
class CircuitGroupSerializer(NetBoxModelSerializer):
|
|
||||||
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
|
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
|
||||||
circuit_count = RelatedObjectCountField('assignments')
|
circuit_count = RelatedObjectCountField('assignments')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitGroup
|
model = CircuitGroup
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'tenant',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'tenant', 'owner', 'tags',
|
||||||
'tags', 'custom_fields', 'created', 'last_updated', 'circuit_count'
|
'custom_fields', 'created', 'last_updated', 'circuit_count'
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name')
|
brief_fields = ('id', 'url', 'display', 'name')
|
||||||
|
|
||||||
@@ -99,7 +92,7 @@ class CircuitGroupAssignmentSerializer_(NetBoxModelSerializer):
|
|||||||
brief_fields = ('id', 'url', 'display', 'group', 'priority')
|
brief_fields = ('id', 'url', 'display', 'group', 'priority')
|
||||||
|
|
||||||
|
|
||||||
class CircuitSerializer(NetBoxModelSerializer):
|
class CircuitSerializer(PrimaryModelSerializer):
|
||||||
provider = ProviderSerializer(nested=True)
|
provider = ProviderSerializer(nested=True)
|
||||||
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True, default=None)
|
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True, default=None)
|
||||||
status = ChoiceField(choices=CircuitStatusChoices, required=False)
|
status = ChoiceField(choices=CircuitStatusChoices, required=False)
|
||||||
@@ -115,7 +108,7 @@ class CircuitSerializer(NetBoxModelSerializer):
|
|||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'cid', 'provider', 'provider_account', 'type', 'status', 'tenant',
|
'id', 'url', 'display_url', 'display', 'cid', 'provider', 'provider_account', 'type', 'status', 'tenant',
|
||||||
'install_date', 'termination_date', 'commit_rate', 'description', 'distance', 'distance_unit',
|
'install_date', 'termination_date', 'commit_rate', 'description', 'distance', 'distance_unit',
|
||||||
'termination_a', 'termination_z', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
'termination_a', 'termination_z', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
'assignments',
|
'assignments',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'provider', 'cid', 'description')
|
brief_fields = ('id', 'url', 'display', 'provider', 'cid', 'description')
|
||||||
@@ -132,7 +125,7 @@ class CircuitTerminationSerializer(NetBoxModelSerializer, CabledObjectSerializer
|
|||||||
default=None
|
default=None
|
||||||
)
|
)
|
||||||
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
|
termination_id = serializers.IntegerField(allow_null=True, required=False, default=None)
|
||||||
termination = serializers.SerializerMethodField(read_only=True)
|
termination = GFKSerializerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitTermination
|
model = CircuitTermination
|
||||||
@@ -144,20 +137,12 @@ class CircuitTerminationSerializer(NetBoxModelSerializer, CabledObjectSerializer
|
|||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'circuit', 'term_side', 'description', 'cable', '_occupied')
|
brief_fields = ('id', 'url', 'display', 'circuit', 'term_side', 'description', 'cable', '_occupied')
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_termination(self, obj):
|
|
||||||
if obj.termination_id is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.termination)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.termination, nested=True, context=context).data
|
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupAssignmentSerializer(CircuitGroupAssignmentSerializer_):
|
class CircuitGroupAssignmentSerializer(CircuitGroupAssignmentSerializer_):
|
||||||
member_type = ContentTypeField(
|
member_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.filter(CIRCUIT_GROUP_ASSIGNMENT_MEMBER_MODELS)
|
queryset=ContentType.objects.filter(CIRCUIT_GROUP_ASSIGNMENT_MEMBER_MODELS)
|
||||||
)
|
)
|
||||||
member = serializers.SerializerMethodField(read_only=True)
|
member = GFKSerializerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitGroupAssignment
|
model = CircuitGroupAssignment
|
||||||
@@ -167,16 +152,8 @@ class CircuitGroupAssignmentSerializer(CircuitGroupAssignmentSerializer_):
|
|||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'group', 'member_type', 'member_id', 'member', 'priority')
|
brief_fields = ('id', 'url', 'display', 'group', 'member_type', 'member_id', 'member', 'priority')
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_member(self, obj):
|
|
||||||
if obj.member_id is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.member)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.member, nested=True, context=context).data
|
|
||||||
|
|
||||||
|
class VirtualCircuitTypeSerializer(OrganizationalModelSerializer):
|
||||||
class VirtualCircuitTypeSerializer(NetBoxModelSerializer):
|
|
||||||
|
|
||||||
# Related object counts
|
# Related object counts
|
||||||
virtual_circuit_count = RelatedObjectCountField('virtual_circuits')
|
virtual_circuit_count = RelatedObjectCountField('virtual_circuits')
|
||||||
@@ -184,13 +161,13 @@ class VirtualCircuitTypeSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'color', 'description', 'tags', 'custom_fields',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'color', 'description', 'owner', 'tags',
|
||||||
'created', 'last_updated', 'virtual_circuit_count',
|
'custom_fields', 'created', 'last_updated', 'virtual_circuit_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'virtual_circuit_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'virtual_circuit_count')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitSerializer(NetBoxModelSerializer):
|
class VirtualCircuitSerializer(PrimaryModelSerializer):
|
||||||
provider_network = ProviderNetworkSerializer(nested=True)
|
provider_network = ProviderNetworkSerializer(nested=True)
|
||||||
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True, default=None)
|
provider_account = ProviderAccountSerializer(nested=True, required=False, allow_null=True, default=None)
|
||||||
type = VirtualCircuitTypeSerializer(nested=True)
|
type = VirtualCircuitTypeSerializer(nested=True)
|
||||||
@@ -201,7 +178,7 @@ class VirtualCircuitSerializer(NetBoxModelSerializer):
|
|||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'cid', 'provider_network', 'provider_account', 'type', 'status',
|
'id', 'url', 'display_url', 'display', 'cid', 'provider_network', 'provider_account', 'type', 'status',
|
||||||
'tenant', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
'tenant', 'description', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'provider_network', 'cid', 'description')
|
brief_fields = ('id', 'url', 'display', 'provider_network', 'cid', 'description')
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from circuits.models import Provider, ProviderAccount, ProviderNetwork
|
|||||||
from ipam.api.serializers_.asns import ASNSerializer
|
from ipam.api.serializers_.asns import ASNSerializer
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.api.fields import RelatedObjectCountField, SerializedPKRelatedField
|
from netbox.api.fields import RelatedObjectCountField, SerializedPKRelatedField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import PrimaryModelSerializer
|
||||||
from .nested import NestedProviderAccountSerializer
|
from .nested import NestedProviderAccountSerializer
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -14,7 +14,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderSerializer(NetBoxModelSerializer):
|
class ProviderSerializer(PrimaryModelSerializer):
|
||||||
accounts = SerializedPKRelatedField(
|
accounts = SerializedPKRelatedField(
|
||||||
queryset=ProviderAccount.objects.all(),
|
queryset=ProviderAccount.objects.all(),
|
||||||
serializer=NestedProviderAccountSerializer,
|
serializer=NestedProviderAccountSerializer,
|
||||||
@@ -35,32 +35,32 @@ class ProviderSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Provider
|
model = Provider
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'accounts', 'description', 'comments',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'accounts', 'description', 'owner', 'comments',
|
||||||
'asns', 'tags', 'custom_fields', 'created', 'last_updated', 'circuit_count',
|
'asns', 'tags', 'custom_fields', 'created', 'last_updated', 'circuit_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'circuit_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'circuit_count')
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountSerializer(NetBoxModelSerializer):
|
class ProviderAccountSerializer(PrimaryModelSerializer):
|
||||||
provider = ProviderSerializer(nested=True)
|
provider = ProviderSerializer(nested=True)
|
||||||
name = serializers.CharField(allow_blank=True, max_length=100, required=False, default='')
|
name = serializers.CharField(allow_blank=True, max_length=100, required=False, default='')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'provider', 'name', 'account', 'description', 'comments', 'tags',
|
'id', 'url', 'display_url', 'display', 'provider', 'name', 'account', 'description', 'owner', 'comments',
|
||||||
'custom_fields', 'created', 'last_updated',
|
'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'account', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'account', 'description')
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkSerializer(NetBoxModelSerializer):
|
class ProviderNetworkSerializer(PrimaryModelSerializer):
|
||||||
provider = ProviderSerializer(nested=True)
|
provider = ProviderSerializer(nested=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'provider', 'name', 'service_id', 'description', 'comments', 'tags',
|
'id', 'url', 'display_url', 'display', 'provider', 'name', 'service_id', 'description', 'owner', 'comments',
|
||||||
'custom_fields', 'created', 'last_updated',
|
'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ from django.utils.translation import gettext as _
|
|||||||
from dcim.filtersets import CabledObjectFilterSet
|
from dcim.filtersets import CabledObjectFilterSet
|
||||||
from dcim.models import Interface, Location, Region, Site, SiteGroup
|
from dcim.models import Interface, Location, Region, Site, SiteGroup
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.filtersets import NetBoxModelFilterSet, OrganizationalModelFilterSet
|
from netbox.filtersets import NetBoxModelFilterSet, OrganizationalModelFilterSet, PrimaryModelFilterSet
|
||||||
|
from netbox.plugins.registration import register_filterset
|
||||||
from tenancy.filtersets import ContactModelFilterSet, TenancyFilterSet
|
from tenancy.filtersets import ContactModelFilterSet, TenancyFilterSet
|
||||||
from utilities.filters import (
|
from utilities.filters import (
|
||||||
ContentTypeFilter, MultiValueCharFilter, MultiValueNumberFilter, TreeNodeMultipleChoiceFilter,
|
ContentTypeFilter, MultiValueCharFilter, MultiValueNumberFilter, TreeNodeMultipleChoiceFilter,
|
||||||
@@ -29,7 +30,8 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
@register_filterset
|
||||||
|
class ProviderFilterSet(PrimaryModelFilterSet, ContactModelFilterSet):
|
||||||
region_id = TreeNodeMultipleChoiceFilter(
|
region_id = TreeNodeMultipleChoiceFilter(
|
||||||
queryset=Region.objects.all(),
|
queryset=Region.objects.all(),
|
||||||
field_name='circuits__terminations___region',
|
field_name='circuits__terminations___region',
|
||||||
@@ -89,13 +91,12 @@ class ProviderFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
|||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
Q(name__icontains=value) |
|
Q(name__icontains=value) |
|
||||||
Q(description__icontains=value) |
|
Q(description__icontains=value) |
|
||||||
Q(accounts__account__icontains=value) |
|
|
||||||
Q(accounts__name__icontains=value) |
|
|
||||||
Q(comments__icontains=value)
|
Q(comments__icontains=value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
@register_filterset
|
||||||
|
class ProviderAccountFilterSet(PrimaryModelFilterSet, ContactModelFilterSet):
|
||||||
provider_id = django_filters.ModelMultipleChoiceFilter(
|
provider_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
label=_('Provider (ID)'),
|
label=_('Provider (ID)'),
|
||||||
@@ -122,7 +123,8 @@ class ProviderAccountFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
|||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkFilterSet(NetBoxModelFilterSet):
|
@register_filterset
|
||||||
|
class ProviderNetworkFilterSet(PrimaryModelFilterSet):
|
||||||
provider_id = django_filters.ModelMultipleChoiceFilter(
|
provider_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
label=_('Provider (ID)'),
|
label=_('Provider (ID)'),
|
||||||
@@ -149,6 +151,7 @@ class ProviderNetworkFilterSet(NetBoxModelFilterSet):
|
|||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class CircuitTypeFilterSet(OrganizationalModelFilterSet):
|
class CircuitTypeFilterSet(OrganizationalModelFilterSet):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -156,7 +159,8 @@ class CircuitTypeFilterSet(OrganizationalModelFilterSet):
|
|||||||
fields = ('id', 'name', 'slug', 'color', 'description')
|
fields = ('id', 'name', 'slug', 'color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class CircuitFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilterSet):
|
@register_filterset
|
||||||
|
class CircuitFilterSet(PrimaryModelFilterSet, TenancyFilterSet, ContactModelFilterSet):
|
||||||
provider_id = django_filters.ModelMultipleChoiceFilter(
|
provider_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
label=_('Provider (ID)'),
|
label=_('Provider (ID)'),
|
||||||
@@ -267,6 +271,7 @@ class CircuitFilterSet(NetBoxModelFilterSet, TenancyFilterSet, ContactModelFilte
|
|||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class CircuitTerminationFilterSet(NetBoxModelFilterSet, CabledObjectFilterSet):
|
class CircuitTerminationFilterSet(NetBoxModelFilterSet, CabledObjectFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
@@ -348,7 +353,7 @@ class CircuitTerminationFilterSet(NetBoxModelFilterSet, CabledObjectFilterSet):
|
|||||||
model = CircuitTermination
|
model = CircuitTermination
|
||||||
fields = (
|
fields = (
|
||||||
'id', 'termination_id', 'term_side', 'port_speed', 'upstream_speed', 'xconnect_id', 'description',
|
'id', 'termination_id', 'term_side', 'port_speed', 'upstream_speed', 'xconnect_id', 'description',
|
||||||
'mark_connected', 'pp_info', 'cable_end',
|
'mark_connected', 'pp_info', 'cable_end', 'cable_position',
|
||||||
)
|
)
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
@@ -362,6 +367,7 @@ class CircuitTerminationFilterSet(NetBoxModelFilterSet, CabledObjectFilterSet):
|
|||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class CircuitGroupFilterSet(OrganizationalModelFilterSet, TenancyFilterSet):
|
class CircuitGroupFilterSet(OrganizationalModelFilterSet, TenancyFilterSet):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -369,6 +375,7 @@ class CircuitGroupFilterSet(OrganizationalModelFilterSet, TenancyFilterSet):
|
|||||||
fields = ('id', 'name', 'slug', 'description')
|
fields = ('id', 'name', 'slug', 'description')
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class CircuitGroupAssignmentFilterSet(NetBoxModelFilterSet):
|
class CircuitGroupAssignmentFilterSet(NetBoxModelFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
@@ -468,6 +475,7 @@ class CircuitGroupAssignmentFilterSet(NetBoxModelFilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class VirtualCircuitTypeFilterSet(OrganizationalModelFilterSet):
|
class VirtualCircuitTypeFilterSet(OrganizationalModelFilterSet):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -475,7 +483,8 @@ class VirtualCircuitTypeFilterSet(OrganizationalModelFilterSet):
|
|||||||
fields = ('id', 'name', 'slug', 'color', 'description')
|
fields = ('id', 'name', 'slug', 'color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
@register_filterset
|
||||||
|
class VirtualCircuitFilterSet(PrimaryModelFilterSet, TenancyFilterSet):
|
||||||
provider_id = django_filters.ModelMultipleChoiceFilter(
|
provider_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
field_name='provider_network__provider',
|
field_name='provider_network__provider',
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -531,6 +540,7 @@ class VirtualCircuitFilterSet(NetBoxModelFilterSet, TenancyFilterSet):
|
|||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class VirtualCircuitTerminationFilterSet(NetBoxModelFilterSet):
|
class VirtualCircuitTerminationFilterSet(NetBoxModelFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ from circuits.models import *
|
|||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.choices import DistanceUnitChoices
|
from netbox.choices import DistanceUnitChoices
|
||||||
from netbox.forms import NetBoxModelBulkEditForm
|
from netbox.forms import NetBoxModelBulkEditForm, OrganizationalModelBulkEditForm, PrimaryModelBulkEditForm
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms import add_blank_choice, get_field_value
|
from utilities.forms import add_blank_choice, get_field_value
|
||||||
from utilities.forms.fields import (
|
from utilities.forms.fields import (
|
||||||
ColorField, CommentField, ContentTypeChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField,
|
ColorField, ContentTypeChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField,
|
||||||
)
|
)
|
||||||
from utilities.forms.rendering import FieldSet
|
from utilities.forms.rendering import FieldSet
|
||||||
from utilities.forms.widgets import BulkEditNullBooleanSelect, DatePicker, HTMXSelect, NumberWithOptions
|
from utilities.forms.widgets import BulkEditNullBooleanSelect, DatePicker, HTMXSelect, NumberWithOptions
|
||||||
@@ -36,18 +36,12 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderBulkEditForm(NetBoxModelBulkEditForm):
|
class ProviderBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
asns = DynamicModelMultipleChoiceField(
|
asns = DynamicModelMultipleChoiceField(
|
||||||
queryset=ASN.objects.all(),
|
queryset=ASN.objects.all(),
|
||||||
label=_('ASNs'),
|
label=_('ASNs'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
model = Provider
|
model = Provider
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -58,18 +52,12 @@ class ProviderBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
|
class ProviderAccountBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -80,7 +68,7 @@ class ProviderAccountBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
class ProviderNetworkBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -91,12 +79,6 @@ class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
required=False,
|
required=False,
|
||||||
label=_('Service ID')
|
label=_('Service ID')
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -107,16 +89,11 @@ class ProviderNetworkBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
class CircuitTypeBulkEditForm(OrganizationalModelBulkEditForm):
|
||||||
color = ColorField(
|
color = ColorField(
|
||||||
label=_('Color'),
|
label=_('Color'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
|
|
||||||
model = CircuitType
|
model = CircuitType
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -125,7 +102,7 @@ class CircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
nullable_fields = ('color', 'description')
|
nullable_fields = ('color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
class CircuitBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
type = DynamicModelChoiceField(
|
type = DynamicModelChoiceField(
|
||||||
label=_('Type'),
|
label=_('Type'),
|
||||||
queryset=CircuitType.objects.all(),
|
queryset=CircuitType.objects.all(),
|
||||||
@@ -183,12 +160,6 @@ class CircuitBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
required=False,
|
required=False,
|
||||||
initial=''
|
initial=''
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=100,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
model = Circuit
|
model = Circuit
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -261,12 +232,7 @@ class CircuitTerminationBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupBulkEditForm(NetBoxModelBulkEditForm):
|
class CircuitGroupBulkEditForm(OrganizationalModelBulkEditForm):
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
tenant = DynamicModelChoiceField(
|
tenant = DynamicModelChoiceField(
|
||||||
label=_('Tenant'),
|
label=_('Tenant'),
|
||||||
queryset=Tenant.objects.all(),
|
queryset=Tenant.objects.all(),
|
||||||
@@ -298,16 +264,11 @@ class CircuitGroupAssignmentBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
nullable_fields = ('priority',)
|
nullable_fields = ('priority',)
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
class VirtualCircuitTypeBulkEditForm(OrganizationalModelBulkEditForm):
|
||||||
color = ColorField(
|
color = ColorField(
|
||||||
label=_('Color'),
|
label=_('Color'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
|
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
@@ -316,7 +277,7 @@ class VirtualCircuitTypeBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
nullable_fields = ('color', 'description')
|
nullable_fields = ('color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitBulkEditForm(NetBoxModelBulkEditForm):
|
class VirtualCircuitBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
provider_network = DynamicModelChoiceField(
|
provider_network = DynamicModelChoiceField(
|
||||||
label=_('Provider network'),
|
label=_('Provider network'),
|
||||||
queryset=ProviderNetwork.objects.all(),
|
queryset=ProviderNetwork.objects.all(),
|
||||||
@@ -343,12 +304,6 @@ class VirtualCircuitBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
queryset=Tenant.objects.all(),
|
queryset=Tenant.objects.all(),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=100,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from circuits.constants import *
|
|||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
from dcim.models import Interface
|
from dcim.models import Interface
|
||||||
from netbox.choices import DistanceUnitChoices
|
from netbox.choices import DistanceUnitChoices
|
||||||
from netbox.forms import NetBoxModelImportForm
|
from netbox.forms import NetBoxModelImportForm, OrganizationalModelImportForm, PrimaryModelImportForm
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from utilities.forms.fields import CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, SlugField
|
from utilities.forms.fields import CSVChoiceField, CSVContentTypeField, CSVModelChoiceField, SlugField
|
||||||
|
|
||||||
@@ -28,17 +28,17 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderImportForm(NetBoxModelImportForm):
|
class ProviderImportForm(PrimaryModelImportForm):
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Provider
|
model = Provider
|
||||||
fields = (
|
fields = (
|
||||||
'name', 'slug', 'description', 'comments', 'tags',
|
'name', 'slug', 'description', 'owner', 'comments', 'tags',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountImportForm(NetBoxModelImportForm):
|
class ProviderAccountImportForm(PrimaryModelImportForm):
|
||||||
provider = CSVModelChoiceField(
|
provider = CSVModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -49,11 +49,11 @@ class ProviderAccountImportForm(NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fields = (
|
fields = (
|
||||||
'provider', 'name', 'account', 'description', 'comments', 'tags',
|
'provider', 'name', 'account', 'description', 'owner', 'comments', 'tags',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkImportForm(NetBoxModelImportForm):
|
class ProviderNetworkImportForm(PrimaryModelImportForm):
|
||||||
provider = CSVModelChoiceField(
|
provider = CSVModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -64,19 +64,19 @@ class ProviderNetworkImportForm(NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fields = [
|
fields = [
|
||||||
'provider', 'name', 'service_id', 'description', 'comments', 'tags'
|
'provider', 'name', 'service_id', 'description', 'owner', 'comments', 'tags'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeImportForm(NetBoxModelImportForm):
|
class CircuitTypeImportForm(OrganizationalModelImportForm):
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitType
|
model = CircuitType
|
||||||
fields = ('name', 'slug', 'color', 'description', 'tags')
|
fields = ('name', 'slug', 'color', 'description', 'owner', 'tags')
|
||||||
|
|
||||||
|
|
||||||
class CircuitImportForm(NetBoxModelImportForm):
|
class CircuitImportForm(PrimaryModelImportForm):
|
||||||
provider = CSVModelChoiceField(
|
provider = CSVModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -119,7 +119,7 @@ class CircuitImportForm(NetBoxModelImportForm):
|
|||||||
model = Circuit
|
model = Circuit
|
||||||
fields = [
|
fields = [
|
||||||
'cid', 'provider', 'provider_account', 'type', 'status', 'tenant', 'install_date', 'termination_date',
|
'cid', 'provider', 'provider_account', 'type', 'status', 'tenant', 'install_date', 'termination_date',
|
||||||
'commit_rate', 'distance', 'distance_unit', 'description', 'comments', 'tags'
|
'commit_rate', 'distance', 'distance_unit', 'description', 'owner', 'comments', 'tags'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -165,7 +165,7 @@ class CircuitTerminationImportForm(NetBoxModelImportForm, BaseCircuitTermination
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupImportForm(NetBoxModelImportForm):
|
class CircuitGroupImportForm(OrganizationalModelImportForm):
|
||||||
tenant = CSVModelChoiceField(
|
tenant = CSVModelChoiceField(
|
||||||
label=_('Tenant'),
|
label=_('Tenant'),
|
||||||
queryset=Tenant.objects.all(),
|
queryset=Tenant.objects.all(),
|
||||||
@@ -176,7 +176,7 @@ class CircuitGroupImportForm(NetBoxModelImportForm):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitGroup
|
model = CircuitGroup
|
||||||
fields = ('name', 'slug', 'description', 'tenant', 'tags')
|
fields = ('name', 'slug', 'description', 'tenant', 'owner', 'tags')
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupAssignmentImportForm(NetBoxModelImportForm):
|
class CircuitGroupAssignmentImportForm(NetBoxModelImportForm):
|
||||||
@@ -195,15 +195,14 @@ class CircuitGroupAssignmentImportForm(NetBoxModelImportForm):
|
|||||||
fields = ('member_type', 'member_id', 'group', 'priority')
|
fields = ('member_type', 'member_id', 'group', 'priority')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTypeImportForm(NetBoxModelImportForm):
|
class VirtualCircuitTypeImportForm(OrganizationalModelImportForm):
|
||||||
slug = SlugField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fields = ('name', 'slug', 'color', 'description', 'tags')
|
fields = ('name', 'slug', 'color', 'description', 'owner', 'tags')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitImportForm(NetBoxModelImportForm):
|
class VirtualCircuitImportForm(PrimaryModelImportForm):
|
||||||
provider_network = CSVModelChoiceField(
|
provider_network = CSVModelChoiceField(
|
||||||
label=_('Provider network'),
|
label=_('Provider network'),
|
||||||
queryset=ProviderNetwork.objects.all(),
|
queryset=ProviderNetwork.objects.all(),
|
||||||
@@ -239,8 +238,8 @@ class VirtualCircuitImportForm(NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fields = [
|
fields = [
|
||||||
'cid', 'provider_network', 'provider_account', 'type', 'status', 'tenant', 'description', 'comments',
|
'cid', 'provider_network', 'provider_account', 'type', 'status', 'tenant', 'description', 'owner',
|
||||||
'tags',
|
'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from circuits.models import *
|
|||||||
from dcim.models import Location, Region, Site, SiteGroup
|
from dcim.models import Location, Region, Site, SiteGroup
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.choices import DistanceUnitChoices
|
from netbox.choices import DistanceUnitChoices
|
||||||
from netbox.forms import NetBoxModelFilterSetForm
|
from netbox.forms import NetBoxModelFilterSetForm, OrganizationalModelFilterSetForm, PrimaryModelFilterSetForm
|
||||||
from tenancy.forms import TenancyFilterForm, ContactModelFilterForm
|
from tenancy.forms import TenancyFilterForm, ContactModelFilterForm
|
||||||
from utilities.forms import add_blank_choice
|
from utilities.forms import add_blank_choice
|
||||||
from utilities.forms.fields import ColorField, DynamicModelMultipleChoiceField, TagFilterField
|
from utilities.forms.fields import ColorField, DynamicModelMultipleChoiceField, TagFilterField
|
||||||
@@ -31,10 +31,10 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
|
class ProviderFilterForm(ContactModelFilterForm, PrimaryModelFilterSetForm):
|
||||||
model = Provider
|
model = Provider
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('region_id', 'site_group_id', 'site_id', name=_('Location')),
|
FieldSet('region_id', 'site_group_id', 'site_id', name=_('Location')),
|
||||||
FieldSet('asn_id', name=_('ASN')),
|
FieldSet('asn_id', name=_('ASN')),
|
||||||
FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')),
|
FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')),
|
||||||
@@ -66,10 +66,10 @@ class ProviderFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
|
class ProviderAccountFilterForm(ContactModelFilterForm, PrimaryModelFilterSetForm):
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('provider_id', 'account', name=_('Attributes')),
|
FieldSet('provider_id', 'account', name=_('Attributes')),
|
||||||
FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')),
|
FieldSet('contact', 'contact_role', 'contact_group', name=_('Contacts')),
|
||||||
)
|
)
|
||||||
@@ -85,10 +85,10 @@ class ProviderAccountFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkFilterForm(NetBoxModelFilterSetForm):
|
class ProviderNetworkFilterForm(PrimaryModelFilterSetForm):
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('provider_id', 'service_id', name=_('Attributes')),
|
FieldSet('provider_id', 'service_id', name=_('Attributes')),
|
||||||
)
|
)
|
||||||
provider_id = DynamicModelMultipleChoiceField(
|
provider_id = DynamicModelMultipleChoiceField(
|
||||||
@@ -104,10 +104,10 @@ class ProviderNetworkFilterForm(NetBoxModelFilterSetForm):
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeFilterForm(NetBoxModelFilterSetForm):
|
class CircuitTypeFilterForm(OrganizationalModelFilterSetForm):
|
||||||
model = CircuitType
|
model = CircuitType
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('color', name=_('Attributes')),
|
FieldSet('color', name=_('Attributes')),
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
@@ -118,10 +118,10 @@ class CircuitTypeFilterForm(NetBoxModelFilterSetForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilterSetForm):
|
class CircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, PrimaryModelFilterSetForm):
|
||||||
model = Circuit
|
model = Circuit
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('provider_id', 'provider_account_id', 'provider_network_id', name=_('Provider')),
|
FieldSet('provider_id', 'provider_account_id', 'provider_network_id', name=_('Provider')),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'type_id', 'status', 'install_date', 'termination_date', 'commit_rate', 'distance', 'distance_unit',
|
'type_id', 'status', 'install_date', 'termination_date', 'commit_rate', 'distance', 'distance_unit',
|
||||||
@@ -271,10 +271,10 @@ class CircuitTerminationFilterForm(NetBoxModelFilterSetForm):
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
class CircuitGroupFilterForm(TenancyFilterForm, OrganizationalModelFilterSetForm):
|
||||||
model = CircuitGroup
|
model = CircuitGroup
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
@@ -309,10 +309,10 @@ class CircuitGroupAssignmentFilterForm(NetBoxModelFilterSetForm):
|
|||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTypeFilterForm(NetBoxModelFilterSetForm):
|
class VirtualCircuitTypeFilterForm(OrganizationalModelFilterSetForm):
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('color', name=_('Attributes')),
|
FieldSet('color', name=_('Attributes')),
|
||||||
)
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
@@ -323,10 +323,10 @@ class VirtualCircuitTypeFilterForm(NetBoxModelFilterSetForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, NetBoxModelFilterSetForm):
|
class VirtualCircuitFilterForm(TenancyFilterForm, ContactModelFilterForm, PrimaryModelFilterSetForm):
|
||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id', 'tag'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('provider_id', 'provider_account_id', 'provider_network_id', name=_('Provider')),
|
FieldSet('provider_id', 'provider_account_id', 'provider_network_id', name=_('Provider')),
|
||||||
FieldSet('type_id', 'status', name=_('Attributes')),
|
FieldSet('type_id', 'status', name=_('Attributes')),
|
||||||
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
FieldSet('tenant_group_id', 'tenant_id', name=_('Tenant')),
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ from circuits.constants import *
|
|||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
from dcim.models import Interface, Site
|
from dcim.models import Interface, Site
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.forms import NetBoxModelForm
|
from netbox.forms import NetBoxModelForm, OrganizationalModelForm, PrimaryModelForm
|
||||||
from tenancy.forms import TenancyForm
|
from tenancy.forms import TenancyForm
|
||||||
from utilities.forms import get_field_value
|
from utilities.forms import get_field_value
|
||||||
from utilities.forms.fields import (
|
from utilities.forms.fields import (
|
||||||
CommentField, ContentTypeChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField,
|
ContentTypeChoiceField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField,
|
||||||
)
|
)
|
||||||
from utilities.forms.mixins import DistanceValidationMixin
|
from utilities.forms.mixins import DistanceValidationMixin
|
||||||
from utilities.forms.rendering import FieldSet, InlineFields
|
from utilities.forms.rendering import FieldSet, InlineFields
|
||||||
@@ -36,14 +36,13 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderForm(NetBoxModelForm):
|
class ProviderForm(PrimaryModelForm):
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
asns = DynamicModelMultipleChoiceField(
|
asns = DynamicModelMultipleChoiceField(
|
||||||
queryset=ASN.objects.all(),
|
queryset=ASN.objects.all(),
|
||||||
label=_('ASNs'),
|
label=_('ASNs'),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'slug', 'asns', 'description', 'tags'),
|
FieldSet('name', 'slug', 'asns', 'description', 'tags'),
|
||||||
@@ -52,34 +51,32 @@ class ProviderForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Provider
|
model = Provider
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'slug', 'asns', 'description', 'comments', 'tags',
|
'name', 'slug', 'asns', 'description', 'owner', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountForm(NetBoxModelForm):
|
class ProviderAccountForm(PrimaryModelForm):
|
||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
selector=True,
|
selector=True,
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fields = [
|
fields = [
|
||||||
'provider', 'name', 'account', 'description', 'comments', 'tags',
|
'provider', 'name', 'account', 'description', 'owner', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkForm(NetBoxModelForm):
|
class ProviderNetworkForm(PrimaryModelForm):
|
||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
selector=True,
|
selector=True,
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('provider', 'name', 'service_id', 'description', 'tags'),
|
FieldSet('provider', 'name', 'service_id', 'description', 'tags'),
|
||||||
@@ -88,15 +85,13 @@ class ProviderNetworkForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fields = [
|
fields = [
|
||||||
'provider', 'name', 'service_id', 'description', 'comments', 'tags',
|
'provider', 'name', 'service_id', 'description', 'owner', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeForm(NetBoxModelForm):
|
class CircuitTypeForm(OrganizationalModelForm):
|
||||||
slug = SlugField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'slug', 'color', 'description', 'tags'),
|
FieldSet('name', 'slug', 'color', 'description', 'owner', 'tags'),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -106,7 +101,7 @@ class CircuitTypeForm(NetBoxModelForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class CircuitForm(DistanceValidationMixin, TenancyForm, NetBoxModelForm):
|
class CircuitForm(DistanceValidationMixin, TenancyForm, PrimaryModelForm):
|
||||||
provider = DynamicModelChoiceField(
|
provider = DynamicModelChoiceField(
|
||||||
label=_('Provider'),
|
label=_('Provider'),
|
||||||
queryset=Provider.objects.all(),
|
queryset=Provider.objects.all(),
|
||||||
@@ -125,7 +120,6 @@ class CircuitForm(DistanceValidationMixin, TenancyForm, NetBoxModelForm):
|
|||||||
queryset=CircuitType.objects.all(),
|
queryset=CircuitType.objects.all(),
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet(
|
FieldSet(
|
||||||
@@ -147,7 +141,7 @@ class CircuitForm(DistanceValidationMixin, TenancyForm, NetBoxModelForm):
|
|||||||
model = Circuit
|
model = Circuit
|
||||||
fields = [
|
fields = [
|
||||||
'cid', 'type', 'provider', 'provider_account', 'status', 'install_date', 'termination_date', 'commit_rate',
|
'cid', 'type', 'provider', 'provider_account', 'status', 'install_date', 'termination_date', 'commit_rate',
|
||||||
'distance', 'distance_unit', 'description', 'tenant_group', 'tenant', 'comments', 'tags',
|
'distance', 'distance_unit', 'description', 'tenant_group', 'tenant', 'owner', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'install_date': DatePicker(),
|
'install_date': DatePicker(),
|
||||||
@@ -233,9 +227,7 @@ class CircuitTerminationForm(NetBoxModelForm):
|
|||||||
self.instance.termination = self.cleaned_data.get('termination')
|
self.instance.termination = self.cleaned_data.get('termination')
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupForm(TenancyForm, NetBoxModelForm):
|
class CircuitGroupForm(TenancyForm, OrganizationalModelForm):
|
||||||
slug = SlugField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'slug', 'description', 'tags', name=_('Circuit Group')),
|
FieldSet('name', 'slug', 'description', 'tags', name=_('Circuit Group')),
|
||||||
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
||||||
@@ -244,7 +236,7 @@ class CircuitGroupForm(TenancyForm, NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = CircuitGroup
|
model = CircuitGroup
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'slug', 'description', 'tenant_group', 'tenant', 'tags',
|
'name', 'slug', 'description', 'tenant_group', 'tenant', 'owner', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -307,9 +299,7 @@ class CircuitGroupAssignmentForm(NetBoxModelForm):
|
|||||||
self.instance.member = self.cleaned_data.get('member')
|
self.instance.member = self.cleaned_data.get('member')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTypeForm(NetBoxModelForm):
|
class VirtualCircuitTypeForm(OrganizationalModelForm):
|
||||||
slug = SlugField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('name', 'slug', 'color', 'description', 'tags'),
|
FieldSet('name', 'slug', 'color', 'description', 'tags'),
|
||||||
)
|
)
|
||||||
@@ -317,11 +307,11 @@ class VirtualCircuitTypeForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'slug', 'color', 'description', 'tags',
|
'name', 'slug', 'color', 'description', 'owner', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitForm(TenancyForm, NetBoxModelForm):
|
class VirtualCircuitForm(TenancyForm, PrimaryModelForm):
|
||||||
provider_network = DynamicModelChoiceField(
|
provider_network = DynamicModelChoiceField(
|
||||||
label=_('Provider network'),
|
label=_('Provider network'),
|
||||||
queryset=ProviderNetwork.objects.all(),
|
queryset=ProviderNetwork.objects.all(),
|
||||||
@@ -336,7 +326,6 @@ class VirtualCircuitForm(TenancyForm, NetBoxModelForm):
|
|||||||
queryset=VirtualCircuitType.objects.all(),
|
queryset=VirtualCircuitType.objects.all(),
|
||||||
quick_add=True
|
quick_add=True
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet(
|
FieldSet(
|
||||||
@@ -350,7 +339,7 @@ class VirtualCircuitForm(TenancyForm, NetBoxModelForm):
|
|||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fields = [
|
fields = [
|
||||||
'cid', 'provider_network', 'provider_account', 'type', 'status', 'description', 'tenant_group', 'tenant',
|
'cid', 'provider_network', 'provider_account', 'type', 'status', 'description', 'tenant_group', 'tenant',
|
||||||
'comments', 'tags',
|
'owner', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from typing import Annotated, TYPE_CHECKING
|
|||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
from strawberry.scalars import ID
|
from strawberry.scalars import ID
|
||||||
from strawberry_django import FilterLookup, DateFilterLookup
|
from strawberry_django import BaseFilterLookup, FilterLookup, DateFilterLookup
|
||||||
|
|
||||||
from circuits import models
|
from circuits import models
|
||||||
from core.graphql.filter_mixins import BaseObjectTypeFilterMixin, ChangeLogFilterMixin
|
from core.graphql.filter_mixins import BaseObjectTypeFilterMixin, ChangeLogFilterMixin
|
||||||
@@ -52,7 +52,9 @@ class CircuitTerminationFilter(
|
|||||||
circuit: Annotated['CircuitFilter', strawberry.lazy('circuits.graphql.filters')] | None = (
|
circuit: Annotated['CircuitFilter', strawberry.lazy('circuits.graphql.filters')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
term_side: Annotated['CircuitTerminationSideEnum', strawberry.lazy('circuits.graphql.enums')] | None = (
|
term_side: (
|
||||||
|
BaseFilterLookup[Annotated['CircuitTerminationSideEnum', strawberry.lazy('circuits.graphql.enums')]] | None
|
||||||
|
) = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
termination_type: Annotated['ContentTypeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
termination_type: Annotated['ContentTypeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
||||||
@@ -108,7 +110,7 @@ class CircuitFilter(
|
|||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
type_id: ID | None = strawberry_django.filter_field()
|
type_id: ID | None = strawberry_django.filter_field()
|
||||||
status: Annotated['CircuitStatusEnum', strawberry.lazy('circuits.graphql.enums')] | None = (
|
status: BaseFilterLookup[Annotated['CircuitStatusEnum', strawberry.lazy('circuits.graphql.enums')]] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
install_date: DateFilterLookup[date] | None = strawberry_django.filter_field()
|
install_date: DateFilterLookup[date] | None = strawberry_django.filter_field()
|
||||||
@@ -143,7 +145,7 @@ class CircuitGroupAssignmentFilter(
|
|||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
group_id: ID | None = strawberry_django.filter_field()
|
group_id: ID | None = strawberry_django.filter_field()
|
||||||
priority: Annotated['CircuitPriorityEnum', strawberry.lazy('circuits.graphql.enums')] | None = (
|
priority: BaseFilterLookup[Annotated['CircuitPriorityEnum', strawberry.lazy('circuits.graphql.enums')]] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -198,7 +200,7 @@ class VirtualCircuitFilter(TenancyFilterMixin, PrimaryModelFilterMixin):
|
|||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
type_id: ID | None = strawberry_django.filter_field()
|
type_id: ID | None = strawberry_django.filter_field()
|
||||||
status: Annotated['CircuitStatusEnum', strawberry.lazy('circuits.graphql.enums')] | None = (
|
status: BaseFilterLookup[Annotated['CircuitStatusEnum', strawberry.lazy('circuits.graphql.enums')]] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
group_assignments: Annotated['CircuitGroupAssignmentFilter', strawberry.lazy('circuits.graphql.filters')] | None = (
|
group_assignments: Annotated['CircuitGroupAssignmentFilter', strawberry.lazy('circuits.graphql.filters')] | None = (
|
||||||
@@ -214,7 +216,11 @@ class VirtualCircuitTerminationFilter(
|
|||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
virtual_circuit_id: ID | None = strawberry_django.filter_field()
|
virtual_circuit_id: ID | None = strawberry_django.filter_field()
|
||||||
role: Annotated['VirtualCircuitTerminationRoleEnum', strawberry.lazy('circuits.graphql.enums')] | None = (
|
role: (
|
||||||
|
BaseFilterLookup[
|
||||||
|
Annotated['VirtualCircuitTerminationRoleEnum', strawberry.lazy('circuits.graphql.enums')]
|
||||||
|
] | None
|
||||||
|
) = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
interface: Annotated['InterfaceFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
|
interface: Annotated['InterfaceFilter', strawberry.lazy('dcim.graphql.filters')] | None = (
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import strawberry_django
|
|||||||
from circuits import models
|
from circuits import models
|
||||||
from dcim.graphql.mixins import CabledObjectMixin
|
from dcim.graphql.mixins import CabledObjectMixin
|
||||||
from extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin
|
from extras.graphql.mixins import ContactsMixin, CustomFieldsMixin, TagsMixin
|
||||||
from netbox.graphql.types import BaseObjectType, NetBoxObjectType, ObjectType, OrganizationalObjectType
|
from netbox.graphql.types import BaseObjectType, ObjectType, OrganizationalObjectType, PrimaryObjectType
|
||||||
from tenancy.graphql.types import TenantType
|
from tenancy.graphql.types import TenantType
|
||||||
from .filters import *
|
from .filters import *
|
||||||
|
|
||||||
@@ -35,8 +35,7 @@ __all__ = (
|
|||||||
filters=ProviderFilter,
|
filters=ProviderFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class ProviderType(NetBoxObjectType, ContactsMixin):
|
class ProviderType(ContactsMixin, PrimaryObjectType):
|
||||||
|
|
||||||
networks: List[Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')]]
|
networks: List[Annotated["ProviderNetworkType", strawberry.lazy('circuits.graphql.types')]]
|
||||||
circuits: List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]
|
circuits: List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]
|
||||||
asns: List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]
|
asns: List[Annotated["ASNType", strawberry.lazy('ipam.graphql.types')]]
|
||||||
@@ -49,9 +48,8 @@ class ProviderType(NetBoxObjectType, ContactsMixin):
|
|||||||
filters=ProviderAccountFilter,
|
filters=ProviderAccountFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class ProviderAccountType(ContactsMixin, NetBoxObjectType):
|
class ProviderAccountType(ContactsMixin, PrimaryObjectType):
|
||||||
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
|
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
|
||||||
|
|
||||||
circuits: List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]
|
circuits: List[Annotated["CircuitType", strawberry.lazy('circuits.graphql.types')]]
|
||||||
|
|
||||||
|
|
||||||
@@ -61,9 +59,8 @@ class ProviderAccountType(ContactsMixin, NetBoxObjectType):
|
|||||||
filters=ProviderNetworkFilter,
|
filters=ProviderNetworkFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class ProviderNetworkType(NetBoxObjectType):
|
class ProviderNetworkType(PrimaryObjectType):
|
||||||
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
|
provider: Annotated["ProviderType", strawberry.lazy('circuits.graphql.types')]
|
||||||
|
|
||||||
circuit_terminations: List[Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]]
|
circuit_terminations: List[Annotated["CircuitTerminationType", strawberry.lazy('circuits.graphql.types')]]
|
||||||
|
|
||||||
|
|
||||||
@@ -105,14 +102,13 @@ class CircuitTypeType(OrganizationalObjectType):
|
|||||||
filters=CircuitFilter,
|
filters=CircuitFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class CircuitType(NetBoxObjectType, ContactsMixin):
|
class CircuitType(PrimaryObjectType, ContactsMixin):
|
||||||
provider: ProviderType
|
provider: ProviderType
|
||||||
provider_account: ProviderAccountType | None
|
provider_account: ProviderAccountType | None
|
||||||
termination_a: CircuitTerminationType | None
|
termination_a: CircuitTerminationType | None
|
||||||
termination_z: CircuitTerminationType | None
|
termination_z: CircuitTerminationType | None
|
||||||
type: CircuitTypeType
|
type: CircuitTypeType
|
||||||
tenant: TenantType | None
|
tenant: TenantType | None
|
||||||
|
|
||||||
terminations: List[CircuitTerminationType]
|
terminations: List[CircuitTerminationType]
|
||||||
|
|
||||||
|
|
||||||
@@ -178,12 +174,11 @@ class VirtualCircuitTerminationType(CustomFieldsMixin, TagsMixin, ObjectType):
|
|||||||
filters=VirtualCircuitFilter,
|
filters=VirtualCircuitFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class VirtualCircuitType(NetBoxObjectType):
|
class VirtualCircuitType(PrimaryObjectType):
|
||||||
provider_network: ProviderNetworkType = strawberry_django.field(select_related=["provider_network"])
|
provider_network: ProviderNetworkType = strawberry_django.field(select_related=["provider_network"])
|
||||||
provider_account: ProviderAccountType | None
|
provider_account: ProviderAccountType | None
|
||||||
type: Annotated["VirtualCircuitTypeType", strawberry.lazy('circuits.graphql.types')] = strawberry_django.field(
|
type: Annotated["VirtualCircuitTypeType", strawberry.lazy('circuits.graphql.types')] = strawberry_django.field(
|
||||||
select_related=["type"]
|
select_related=["type"]
|
||||||
)
|
)
|
||||||
tenant: TenantType | None
|
tenant: TenantType | None
|
||||||
|
|
||||||
terminations: List[VirtualCircuitTerminationType]
|
terminations: List[VirtualCircuitTerminationType]
|
||||||
|
|||||||
68
netbox/circuits/migrations/0053_owner.py
Normal file
68
netbox/circuits/migrations/0053_owner.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('circuits', '0052_extend_circuit_abs_distance_upper_limit'),
|
||||||
|
('users', '0015_owner'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='circuit',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='circuitgroup',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='circuittype',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='provider',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='provideraccount',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='providernetwork',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='virtualcircuit',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='virtualcircuittype',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
netbox/circuits/migrations/0054_cable_position.py
Normal file
23
netbox/circuits/migrations/0054_cable_position.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('circuits', '0053_owner'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='circuittermination',
|
||||||
|
name='cable_position',
|
||||||
|
field=models.PositiveIntegerField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
validators=[
|
||||||
|
django.core.validators.MinValueValidator(1),
|
||||||
|
django.core.validators.MaxValueValidator(1024),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
|
from netbox.tables import NetBoxTable, OrganizationalModelTable, PrimaryModelTable, columns
|
||||||
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
||||||
|
|
||||||
from netbox.tables import NetBoxTable, columns
|
|
||||||
|
|
||||||
from .columns import CommitRateColumn
|
from .columns import CommitRateColumn
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -24,7 +22,7 @@ CIRCUITTERMINATION_LINK = """
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
class CircuitTypeTable(NetBoxTable):
|
class CircuitTypeTable(OrganizationalModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
@@ -39,7 +37,7 @@ class CircuitTypeTable(NetBoxTable):
|
|||||||
verbose_name=_('Circuits')
|
verbose_name=_('Circuits')
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(OrganizationalModelTable.Meta):
|
||||||
model = CircuitType
|
model = CircuitType
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'circuit_count', 'color', 'description', 'slug', 'tags', 'created', 'last_updated',
|
'pk', 'id', 'name', 'circuit_count', 'color', 'description', 'slug', 'tags', 'created', 'last_updated',
|
||||||
@@ -48,7 +46,7 @@ class CircuitTypeTable(NetBoxTable):
|
|||||||
default_columns = ('pk', 'name', 'circuit_count', 'color', 'description')
|
default_columns = ('pk', 'name', 'circuit_count', 'color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, PrimaryModelTable):
|
||||||
cid = tables.Column(
|
cid = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name=_('Circuit ID')
|
verbose_name=_('Circuit ID')
|
||||||
@@ -79,9 +77,6 @@ class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
|||||||
verbose_name=_('Commit Rate')
|
verbose_name=_('Commit Rate')
|
||||||
)
|
)
|
||||||
distance = columns.DistanceColumn()
|
distance = columns.DistanceColumn()
|
||||||
comments = columns.MarkdownColumn(
|
|
||||||
verbose_name=_('Comments')
|
|
||||||
)
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:circuit_list'
|
url_name='circuits:circuit_list'
|
||||||
)
|
)
|
||||||
@@ -90,7 +85,7 @@ class CircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
|||||||
linkify_item=True
|
linkify_item=True
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = Circuit
|
model = Circuit
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'cid', 'provider', 'provider_account', 'type', 'status', 'tenant', 'tenant_group',
|
'pk', 'id', 'cid', 'provider', 'provider_account', 'type', 'status', 'tenant', 'tenant_group',
|
||||||
@@ -163,7 +158,7 @@ class CircuitTerminationTable(NetBoxTable):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CircuitGroupTable(NetBoxTable):
|
class CircuitGroupTable(OrganizationalModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
linkify=True
|
linkify=True
|
||||||
@@ -177,7 +172,7 @@ class CircuitGroupTable(NetBoxTable):
|
|||||||
url_name='circuits:circuitgroup_list'
|
url_name='circuits:circuitgroup_list'
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(OrganizationalModelTable.Meta):
|
||||||
model = CircuitGroup
|
model = CircuitGroup
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'name', 'description', 'circuit_group_assignment_count', 'tags',
|
'pk', 'name', 'description', 'circuit_group_assignment_count', 'tags',
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from circuits.models import *
|
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
from tenancy.tables import ContactsColumnMixin
|
|
||||||
|
|
||||||
from netbox.tables import NetBoxTable, columns
|
from circuits.models import *
|
||||||
|
from netbox.tables import PrimaryModelTable, columns
|
||||||
|
from tenancy.tables import ContactsColumnMixin
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ProviderTable',
|
'ProviderTable',
|
||||||
@@ -13,7 +13,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
class ProviderTable(ContactsColumnMixin, PrimaryModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
linkify=True
|
linkify=True
|
||||||
@@ -42,14 +42,11 @@ class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
url_params={'provider_id': 'pk'},
|
url_params={'provider_id': 'pk'},
|
||||||
verbose_name=_('Circuits')
|
verbose_name=_('Circuits')
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn(
|
|
||||||
verbose_name=_('Comments'),
|
|
||||||
)
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:provider_list'
|
url_name='circuits:provider_list'
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = Provider
|
model = Provider
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'accounts', 'account_count', 'asns', 'asn_count', 'circuit_count', 'description',
|
'pk', 'id', 'name', 'accounts', 'account_count', 'asns', 'asn_count', 'circuit_count', 'description',
|
||||||
@@ -58,7 +55,7 @@ class ProviderTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
default_columns = ('pk', 'name', 'account_count', 'circuit_count')
|
default_columns = ('pk', 'name', 'account_count', 'circuit_count')
|
||||||
|
|
||||||
|
|
||||||
class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
class ProviderAccountTable(ContactsColumnMixin, PrimaryModelTable):
|
||||||
account = tables.Column(
|
account = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name=_('Account'),
|
verbose_name=_('Account'),
|
||||||
@@ -76,14 +73,11 @@ class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
url_params={'provider_account_id': 'pk'},
|
url_params={'provider_account_id': 'pk'},
|
||||||
verbose_name=_('Circuits')
|
verbose_name=_('Circuits')
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn(
|
|
||||||
verbose_name=_('Comments'),
|
|
||||||
)
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:provideraccount_list'
|
url_name='circuits:provideraccount_list'
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = ProviderAccount
|
model = ProviderAccount
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'account', 'name', 'provider', 'circuit_count', 'comments', 'contacts', 'tags', 'created',
|
'pk', 'id', 'account', 'name', 'provider', 'circuit_count', 'comments', 'contacts', 'tags', 'created',
|
||||||
@@ -92,7 +86,7 @@ class ProviderAccountTable(ContactsColumnMixin, NetBoxTable):
|
|||||||
default_columns = ('pk', 'account', 'name', 'provider', 'circuit_count')
|
default_columns = ('pk', 'account', 'name', 'provider', 'circuit_count')
|
||||||
|
|
||||||
|
|
||||||
class ProviderNetworkTable(NetBoxTable):
|
class ProviderNetworkTable(PrimaryModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
linkify=True
|
linkify=True
|
||||||
@@ -101,14 +95,11 @@ class ProviderNetworkTable(NetBoxTable):
|
|||||||
verbose_name=_('Provider'),
|
verbose_name=_('Provider'),
|
||||||
linkify=True
|
linkify=True
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn(
|
|
||||||
verbose_name=_('Comments'),
|
|
||||||
)
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:providernetwork_list'
|
url_name='circuits:providernetwork_list'
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = ProviderNetwork
|
model = ProviderNetwork
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'provider', 'service_id', 'description', 'comments', 'created', 'last_updated', 'tags',
|
'pk', 'id', 'name', 'provider', 'service_id', 'description', 'comments', 'created', 'last_updated', 'tags',
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import django_tables2 as tables
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from circuits.models import *
|
from circuits.models import *
|
||||||
from netbox.tables import NetBoxTable, columns
|
from netbox.tables import NetBoxTable, OrganizationalModelTable, PrimaryModelTable, columns
|
||||||
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
from tenancy.tables import ContactsColumnMixin, TenancyColumnsMixin
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -12,7 +12,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTypeTable(NetBoxTable):
|
class VirtualCircuitTypeTable(OrganizationalModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
@@ -27,7 +27,7 @@ class VirtualCircuitTypeTable(NetBoxTable):
|
|||||||
verbose_name=_('Circuits')
|
verbose_name=_('Circuits')
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(OrganizationalModelTable.Meta):
|
||||||
model = VirtualCircuitType
|
model = VirtualCircuitType
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'virtual_circuit_count', 'color', 'description', 'slug', 'tags', 'created',
|
'pk', 'id', 'name', 'virtual_circuit_count', 'color', 'description', 'slug', 'tags', 'created',
|
||||||
@@ -36,7 +36,7 @@ class VirtualCircuitTypeTable(NetBoxTable):
|
|||||||
default_columns = ('pk', 'name', 'virtual_circuit_count', 'color', 'description')
|
default_columns = ('pk', 'name', 'virtual_circuit_count', 'color', 'description')
|
||||||
|
|
||||||
|
|
||||||
class VirtualCircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable):
|
class VirtualCircuitTable(TenancyColumnsMixin, ContactsColumnMixin, PrimaryModelTable):
|
||||||
cid = tables.Column(
|
cid = tables.Column(
|
||||||
linkify=True,
|
linkify=True,
|
||||||
verbose_name=_('Circuit ID')
|
verbose_name=_('Circuit ID')
|
||||||
@@ -63,14 +63,11 @@ class VirtualCircuitTable(TenancyColumnsMixin, ContactsColumnMixin, NetBoxTable)
|
|||||||
url_params={'virtual_circuit_id': 'pk'},
|
url_params={'virtual_circuit_id': 'pk'},
|
||||||
verbose_name=_('Terminations')
|
verbose_name=_('Terminations')
|
||||||
)
|
)
|
||||||
comments = columns.MarkdownColumn(
|
|
||||||
verbose_name=_('Comments')
|
|
||||||
)
|
|
||||||
tags = columns.TagColumn(
|
tags = columns.TagColumn(
|
||||||
url_name='circuits:virtualcircuit_list'
|
url_name='circuits:virtualcircuit_list'
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = VirtualCircuit
|
model = VirtualCircuit
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'cid', 'provider', 'provider_account', 'provider_network', 'type', 'status', 'tenant',
|
'pk', 'id', 'cid', 'provider', 'provider_account', 'provider_network', 'type', 'status', 'tenant',
|
||||||
|
|||||||
@@ -18,11 +18,6 @@ urlpatterns = [
|
|||||||
path('circuit-types/<int:pk>/', include(get_model_urls('circuits', 'circuittype'))),
|
path('circuit-types/<int:pk>/', include(get_model_urls('circuits', 'circuittype'))),
|
||||||
|
|
||||||
path('circuits/', include(get_model_urls('circuits', 'circuit', detail=False))),
|
path('circuits/', include(get_model_urls('circuits', 'circuit', detail=False))),
|
||||||
path(
|
|
||||||
'circuits/<int:pk>/terminations/swap/',
|
|
||||||
views.CircuitSwapTerminations.as_view(),
|
|
||||||
name='circuit_terminations_swap'
|
|
||||||
),
|
|
||||||
path('circuits/<int:pk>/', include(get_model_urls('circuits', 'circuit'))),
|
path('circuits/<int:pk>/', include(get_model_urls('circuits', 'circuit'))),
|
||||||
|
|
||||||
path('circuit-terminations/', include(get_model_urls('circuits', 'circuittermination', detail=False))),
|
path('circuit-terminations/', include(get_model_urls('circuits', 'circuittermination', detail=False))),
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
from django.contrib import messages
|
|
||||||
from django.db import router, transaction
|
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
|
||||||
|
|
||||||
from dcim.views import PathTraceView
|
from dcim.views import PathTraceView
|
||||||
from ipam.models import ASN
|
from ipam.models import ASN
|
||||||
from netbox.object_actions import AddObject, BulkDelete, BulkEdit, BulkExport, BulkImport
|
from netbox.object_actions import AddObject, BulkDelete, BulkEdit, BulkExport, BulkImport
|
||||||
from netbox.views import generic
|
from netbox.views import generic
|
||||||
from utilities.forms import ConfirmationForm
|
|
||||||
from utilities.query import count_related
|
from utilities.query import count_related
|
||||||
from utilities.views import GetRelatedModelsMixin, register_model_view
|
from utilities.views import GetRelatedModelsMixin, register_model_view
|
||||||
from . import filtersets, forms, tables
|
from . import filtersets, forms, tables
|
||||||
@@ -83,6 +78,7 @@ class ProviderBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(Provider, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(Provider, 'bulk_rename', path='rename', detail=False)
|
||||||
class ProviderBulkRenameView(generic.BulkRenameView):
|
class ProviderBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = Provider.objects.all()
|
queryset = Provider.objects.all()
|
||||||
|
filterset = filtersets.ProviderFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(Provider, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(Provider, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -150,6 +146,7 @@ class ProviderAccountBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(ProviderAccount, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(ProviderAccount, 'bulk_rename', path='rename', detail=False)
|
||||||
class ProviderAccountBulkRenameView(generic.BulkRenameView):
|
class ProviderAccountBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = ProviderAccount.objects.all()
|
queryset = ProviderAccount.objects.all()
|
||||||
|
filterset = filtersets.ProviderAccountFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(ProviderAccount, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(ProviderAccount, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -226,6 +223,7 @@ class ProviderNetworkBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(ProviderNetwork, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(ProviderNetwork, 'bulk_rename', path='rename', detail=False)
|
||||||
class ProviderNetworkBulkRenameView(generic.BulkRenameView):
|
class ProviderNetworkBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = ProviderNetwork.objects.all()
|
queryset = ProviderNetwork.objects.all()
|
||||||
|
filterset = filtersets.ProviderNetworkFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(ProviderNetwork, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(ProviderNetwork, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -290,6 +288,7 @@ class CircuitTypeBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(CircuitType, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(CircuitType, 'bulk_rename', path='rename', detail=False)
|
||||||
class CircuitTypeBulkRenameView(generic.BulkRenameView):
|
class CircuitTypeBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = CircuitType.objects.all()
|
queryset = CircuitType.objects.all()
|
||||||
|
filterset = filtersets.CircuitTypeFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(CircuitType, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(CircuitType, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -362,6 +361,7 @@ class CircuitBulkEditView(generic.BulkEditView):
|
|||||||
class CircuitBulkRenameView(generic.BulkRenameView):
|
class CircuitBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = Circuit.objects.all()
|
queryset = Circuit.objects.all()
|
||||||
field_name = 'cid'
|
field_name = 'cid'
|
||||||
|
filterset = filtersets.CircuitFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(Circuit, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(Circuit, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -373,82 +373,6 @@ class CircuitBulkDeleteView(generic.BulkDeleteView):
|
|||||||
table = tables.CircuitTable
|
table = tables.CircuitTable
|
||||||
|
|
||||||
|
|
||||||
class CircuitSwapTerminations(generic.ObjectEditView):
|
|
||||||
"""
|
|
||||||
Swap the A and Z terminations of a circuit.
|
|
||||||
"""
|
|
||||||
queryset = Circuit.objects.all()
|
|
||||||
|
|
||||||
def get(self, request, pk):
|
|
||||||
circuit = get_object_or_404(self.queryset, pk=pk)
|
|
||||||
form = ConfirmationForm()
|
|
||||||
|
|
||||||
# Circuit must have at least one termination to swap
|
|
||||||
if not circuit.termination_a and not circuit.termination_z:
|
|
||||||
messages.error(request, _(
|
|
||||||
"No terminations have been defined for circuit {circuit}."
|
|
||||||
).format(circuit=circuit))
|
|
||||||
return redirect('circuits:circuit', pk=circuit.pk)
|
|
||||||
|
|
||||||
return render(request, 'circuits/circuit_terminations_swap.html', {
|
|
||||||
'circuit': circuit,
|
|
||||||
'termination_a': circuit.termination_a,
|
|
||||||
'termination_z': circuit.termination_z,
|
|
||||||
'form': form,
|
|
||||||
'panel_class': 'light',
|
|
||||||
'button_class': 'primary',
|
|
||||||
'return_url': circuit.get_absolute_url(),
|
|
||||||
})
|
|
||||||
|
|
||||||
def post(self, request, pk):
|
|
||||||
circuit = get_object_or_404(self.queryset, pk=pk)
|
|
||||||
form = ConfirmationForm(request.POST)
|
|
||||||
|
|
||||||
if form.is_valid():
|
|
||||||
|
|
||||||
termination_a = CircuitTermination.objects.filter(pk=circuit.termination_a_id).first()
|
|
||||||
termination_z = CircuitTermination.objects.filter(pk=circuit.termination_z_id).first()
|
|
||||||
|
|
||||||
if termination_a and termination_z:
|
|
||||||
# Use a placeholder to avoid an IntegrityError on the (circuit, term_side) unique constraint
|
|
||||||
with transaction.atomic(using=router.db_for_write(CircuitTermination)):
|
|
||||||
termination_a.term_side = '_'
|
|
||||||
termination_a.save()
|
|
||||||
termination_z.term_side = 'A'
|
|
||||||
termination_z.save()
|
|
||||||
termination_a.term_side = 'Z'
|
|
||||||
termination_a.save()
|
|
||||||
circuit.refresh_from_db()
|
|
||||||
circuit.termination_a = termination_z
|
|
||||||
circuit.termination_z = termination_a
|
|
||||||
circuit.save()
|
|
||||||
elif termination_a:
|
|
||||||
termination_a.term_side = 'Z'
|
|
||||||
termination_a.save()
|
|
||||||
circuit.refresh_from_db()
|
|
||||||
circuit.termination_a = None
|
|
||||||
circuit.save()
|
|
||||||
else:
|
|
||||||
termination_z.term_side = 'A'
|
|
||||||
termination_z.save()
|
|
||||||
circuit.refresh_from_db()
|
|
||||||
circuit.termination_z = None
|
|
||||||
circuit.save()
|
|
||||||
|
|
||||||
messages.success(request, _("Swapped terminations for circuit {circuit}.").format(circuit=circuit))
|
|
||||||
return redirect('circuits:circuit', pk=circuit.pk)
|
|
||||||
|
|
||||||
return render(request, 'circuits/circuit_terminations_swap.html', {
|
|
||||||
'circuit': circuit,
|
|
||||||
'termination_a': circuit.termination_a,
|
|
||||||
'termination_z': circuit.termination_z,
|
|
||||||
'form': form,
|
|
||||||
'panel_class': 'default',
|
|
||||||
'button_class': 'primary',
|
|
||||||
'return_url': circuit.get_absolute_url(),
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Circuit terminations
|
# Circuit terminations
|
||||||
#
|
#
|
||||||
@@ -557,6 +481,7 @@ class CircuitGroupBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(CircuitGroup, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(CircuitGroup, 'bulk_rename', path='rename', detail=False)
|
||||||
class CircuitGroupBulkRenameView(generic.BulkRenameView):
|
class CircuitGroupBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = CircuitGroup.objects.all()
|
queryset = CircuitGroup.objects.all()
|
||||||
|
filterset = filtersets.CircuitGroupFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(CircuitGroup, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(CircuitGroup, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -672,6 +597,7 @@ class VirtualCircuitTypeBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(VirtualCircuitType, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(VirtualCircuitType, 'bulk_rename', path='rename', detail=False)
|
||||||
class VirtualCircuitTypeBulkRenameView(generic.BulkRenameView):
|
class VirtualCircuitTypeBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = VirtualCircuitType.objects.all()
|
queryset = VirtualCircuitType.objects.all()
|
||||||
|
filterset = filtersets.VirtualCircuitTypeFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(VirtualCircuitType, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(VirtualCircuitType, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -744,6 +670,7 @@ class VirtualCircuitBulkEditView(generic.BulkEditView):
|
|||||||
class VirtualCircuitBulkRenameView(generic.BulkRenameView):
|
class VirtualCircuitBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = VirtualCircuit.objects.all()
|
queryset = VirtualCircuit.objects.all()
|
||||||
field_name = 'cid'
|
field_name = 'cid'
|
||||||
|
filterset = filtersets.VirtualCircuitFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(VirtualCircuit, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(VirtualCircuit, 'bulk_delete', path='delete', detail=False)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from drf_spectacular.utils import Direction
|
|||||||
|
|
||||||
from netbox.api.fields import ChoiceField
|
from netbox.api.fields import ChoiceField
|
||||||
from netbox.api.serializers import WritableNestedSerializer
|
from netbox.api.serializers import WritableNestedSerializer
|
||||||
|
from netbox.api.viewsets import NetBoxModelViewSet
|
||||||
|
|
||||||
# see netbox.api.routers.NetBoxRouter
|
# see netbox.api.routers.NetBoxRouter
|
||||||
BULK_ACTIONS = ("bulk_destroy", "bulk_partial_update", "bulk_update")
|
BULK_ACTIONS = ("bulk_destroy", "bulk_partial_update", "bulk_update")
|
||||||
@@ -49,6 +50,11 @@ class ChoiceFieldFix(OpenApiSerializerFieldExtension):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def viewset_handles_bulk_create(view):
|
||||||
|
"""Check if view automatically provides list-based bulk create"""
|
||||||
|
return isinstance(view, NetBoxModelViewSet)
|
||||||
|
|
||||||
|
|
||||||
class NetBoxAutoSchema(AutoSchema):
|
class NetBoxAutoSchema(AutoSchema):
|
||||||
"""
|
"""
|
||||||
Overrides to drf_spectacular.openapi.AutoSchema to fix following issues:
|
Overrides to drf_spectacular.openapi.AutoSchema to fix following issues:
|
||||||
@@ -128,6 +134,36 @@ class NetBoxAutoSchema(AutoSchema):
|
|||||||
|
|
||||||
return response_serializers
|
return response_serializers
|
||||||
|
|
||||||
|
def _get_request_for_media_type(self, serializer, direction='request'):
|
||||||
|
"""
|
||||||
|
Override to generate oneOf schema for serializers that support both
|
||||||
|
single object and array input (NetBoxModelViewSet POST operations).
|
||||||
|
|
||||||
|
Refs: #20638
|
||||||
|
"""
|
||||||
|
# Get the standard schema first
|
||||||
|
schema, required = super()._get_request_for_media_type(serializer, direction)
|
||||||
|
|
||||||
|
# If this serializer supports arrays (marked in get_request_serializer),
|
||||||
|
# wrap the schema in oneOf to allow single object OR array
|
||||||
|
if (
|
||||||
|
direction == 'request' and
|
||||||
|
schema is not None and
|
||||||
|
getattr(self.view, 'action', None) == 'create' and
|
||||||
|
viewset_handles_bulk_create(self.view)
|
||||||
|
):
|
||||||
|
return {
|
||||||
|
'oneOf': [
|
||||||
|
schema, # Single object
|
||||||
|
{
|
||||||
|
'type': 'array',
|
||||||
|
'items': schema, # Array of objects
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, required
|
||||||
|
|
||||||
|
return schema, required
|
||||||
|
|
||||||
def _get_serializer_name(self, serializer, direction, bypass_extensions=False) -> str:
|
def _get_serializer_name(self, serializer, direction, bypass_extensions=False) -> str:
|
||||||
name = super()._get_serializer_name(serializer, direction, bypass_extensions)
|
name = super()._get_serializer_name(serializer, direction, bypass_extensions)
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
from drf_spectacular.utils import extend_schema_field
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from core.choices import *
|
from core.choices import *
|
||||||
from core.models import ObjectChange
|
from core.models import ObjectChange
|
||||||
from netbox.api.exceptions import SerializerNotFound
|
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField
|
from netbox.api.fields import ChoiceField, ContentTypeField
|
||||||
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
from netbox.api.serializers import BaseModelSerializer
|
from netbox.api.serializers import BaseModelSerializer
|
||||||
from users.api.serializers_.users import UserSerializer
|
from users.api.serializers_.users import UserSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ObjectChangeSerializer',
|
'ObjectChangeSerializer',
|
||||||
@@ -26,7 +24,10 @@ class ObjectChangeSerializer(BaseModelSerializer):
|
|||||||
changed_object_type = ContentTypeField(
|
changed_object_type = ContentTypeField(
|
||||||
read_only=True
|
read_only=True
|
||||||
)
|
)
|
||||||
changed_object = serializers.SerializerMethodField(
|
changed_object = GFKSerializerField(
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
object_repr = serializers.CharField(
|
||||||
read_only=True
|
read_only=True
|
||||||
)
|
)
|
||||||
prechange_data = serializers.JSONField(
|
prechange_data = serializers.JSONField(
|
||||||
@@ -44,22 +45,6 @@ class ObjectChangeSerializer(BaseModelSerializer):
|
|||||||
model = ObjectChange
|
model = ObjectChange
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'time', 'user', 'user_name', 'request_id', 'action',
|
'id', 'url', 'display_url', 'display', 'time', 'user', 'user_name', 'request_id', 'action',
|
||||||
'changed_object_type', 'changed_object_id', 'changed_object', 'message', 'prechange_data',
|
'changed_object_type', 'changed_object_id', 'changed_object', 'object_repr', 'message',
|
||||||
'postchange_data',
|
'prechange_data', 'postchange_data',
|
||||||
]
|
]
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_changed_object(self, obj):
|
|
||||||
"""
|
|
||||||
Serialize a nested representation of the changed object.
|
|
||||||
"""
|
|
||||||
if obj.changed_object is None:
|
|
||||||
return None
|
|
||||||
|
|
||||||
try:
|
|
||||||
serializer = get_serializer_for_model(obj.changed_object)
|
|
||||||
except SerializerNotFound:
|
|
||||||
return obj.object_repr
|
|
||||||
data = serializer(obj.changed_object, nested=True, context={'request': self.context['request']}).data
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from core.choices import *
|
from core.choices import *
|
||||||
from core.models import DataFile, DataSource
|
from core.models import DataFile, DataSource
|
||||||
from netbox.api.fields import ChoiceField, RelatedObjectCountField
|
from netbox.api.fields import ChoiceField, RelatedObjectCountField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import NetBoxModelSerializer, PrimaryModelSerializer
|
||||||
from netbox.utils import get_data_backend_choices
|
from netbox.utils import get_data_backend_choices
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -10,7 +10,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceSerializer(NetBoxModelSerializer):
|
class DataSourceSerializer(PrimaryModelSerializer):
|
||||||
type = ChoiceField(
|
type = ChoiceField(
|
||||||
choices=get_data_backend_choices()
|
choices=get_data_backend_choices()
|
||||||
)
|
)
|
||||||
@@ -26,8 +26,8 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
|||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'type', 'source_url', 'enabled', 'status', 'description',
|
'id', 'url', 'display_url', 'display', 'name', 'type', 'source_url', 'enabled', 'status', 'description',
|
||||||
'sync_interval', 'parameters', 'ignore_rules', 'comments', 'custom_fields', 'created', 'last_updated',
|
'sync_interval', 'parameters', 'ignore_rules', 'owner', 'comments', 'custom_fields', 'created',
|
||||||
'last_synced', 'file_count',
|
'last_updated', 'last_synced', 'file_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
|
from drf_spectacular.utils import extend_schema_field
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
from core.choices import *
|
from core.choices import *
|
||||||
from core.models import Job
|
from core.models import Job
|
||||||
|
from netbox.api.exceptions import SerializerNotFound
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField
|
from netbox.api.fields import ChoiceField, ContentTypeField
|
||||||
from netbox.api.serializers import BaseModelSerializer
|
from netbox.api.serializers import BaseModelSerializer
|
||||||
from users.api.serializers_.users import UserSerializer
|
from users.api.serializers_.users import UserSerializer
|
||||||
|
from utilities.api import get_serializer_for_model
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'JobSerializer',
|
'JobSerializer',
|
||||||
@@ -18,11 +23,28 @@ class JobSerializer(BaseModelSerializer):
|
|||||||
object_type = ContentTypeField(
|
object_type = ContentTypeField(
|
||||||
read_only=True
|
read_only=True
|
||||||
)
|
)
|
||||||
|
object = serializers.SerializerMethodField(
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Job
|
model = Job
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'object_type', 'object_id', 'name', 'status', 'created', 'scheduled',
|
'id', 'url', 'display_url', 'display', 'object_type', 'object_id', 'object', 'name', 'status', 'created',
|
||||||
'interval', 'started', 'completed', 'user', 'data', 'error', 'job_id', 'log_entries',
|
'scheduled', 'interval', 'started', 'completed', 'user', 'data', 'error', 'job_id', 'log_entries',
|
||||||
]
|
]
|
||||||
brief_fields = ('url', 'created', 'completed', 'user', 'status')
|
brief_fields = ('url', 'created', 'completed', 'user', 'status')
|
||||||
|
|
||||||
|
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||||
|
def get_object(self, obj):
|
||||||
|
"""
|
||||||
|
Serialize a nested representation of the object.
|
||||||
|
"""
|
||||||
|
if obj.object is None:
|
||||||
|
return None
|
||||||
|
try:
|
||||||
|
serializer = get_serializer_for_model(obj.object)
|
||||||
|
except SerializerNotFound:
|
||||||
|
return obj.object_repr
|
||||||
|
context = {'request': self.context['request']}
|
||||||
|
return serializer(obj.object, nested=True, context=context).data
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from drf_spectacular.utils import OpenApiParameter, extend_schema
|
|||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.permissions import IsAdminUser
|
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.routers import APIRootView
|
from rest_framework.routers import APIRootView
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||||
@@ -24,7 +23,7 @@ from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired
|
|||||||
from netbox.api.metadata import ContentTypeMetadata
|
from netbox.api.metadata import ContentTypeMetadata
|
||||||
from netbox.api.pagination import LimitOffsetListPagination
|
from netbox.api.pagination import LimitOffsetListPagination
|
||||||
from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
|
from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
|
||||||
|
from utilities.api import IsSuperuser
|
||||||
from . import serializers
|
from . import serializers
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +99,7 @@ class BaseRQViewSet(viewsets.ViewSet):
|
|||||||
"""
|
"""
|
||||||
Base class for RQ view sets. Provides a list() method. Subclasses must implement get_data().
|
Base class for RQ view sets. Provides a list() method. Subclasses must implement get_data().
|
||||||
"""
|
"""
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsSuperuser]
|
||||||
serializer_class = None
|
serializer_class = None
|
||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from netbox.filtersets import BaseFilterSet, ChangeLoggedModelFilterSet, NetBoxModelFilterSet
|
from netbox.filtersets import BaseFilterSet, ChangeLoggedModelFilterSet, PrimaryModelFilterSet
|
||||||
|
from netbox.plugins.registration import register_filterset
|
||||||
from netbox.utils import get_data_backend_choices
|
from netbox.utils import get_data_backend_choices
|
||||||
from users.models import User
|
from users.models import User
|
||||||
from utilities.filters import ContentTypeFilter
|
from utilities.filters import ContentTypeFilter
|
||||||
@@ -20,7 +21,8 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceFilterSet(NetBoxModelFilterSet):
|
@register_filterset
|
||||||
|
class DataSourceFilterSet(PrimaryModelFilterSet):
|
||||||
type = django_filters.MultipleChoiceFilter(
|
type = django_filters.MultipleChoiceFilter(
|
||||||
choices=get_data_backend_choices,
|
choices=get_data_backend_choices,
|
||||||
null_value=None
|
null_value=None
|
||||||
@@ -48,6 +50,7 @@ class DataSourceFilterSet(NetBoxModelFilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class DataFileFilterSet(ChangeLoggedModelFilterSet):
|
class DataFileFilterSet(ChangeLoggedModelFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search'
|
method='search'
|
||||||
@@ -75,11 +78,17 @@ class DataFileFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class JobFilterSet(BaseFilterSet):
|
class JobFilterSet(BaseFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
label=_('Search'),
|
label=_('Search'),
|
||||||
)
|
)
|
||||||
|
object_type_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
queryset=ObjectType.objects.with_feature('jobs'),
|
||||||
|
field_name='object_type_id',
|
||||||
|
)
|
||||||
|
object_type = ContentTypeFilter()
|
||||||
created = django_filters.DateTimeFilter()
|
created = django_filters.DateTimeFilter()
|
||||||
created__before = django_filters.DateTimeFilter(
|
created__before = django_filters.DateTimeFilter(
|
||||||
field_name='created',
|
field_name='created',
|
||||||
@@ -123,7 +132,7 @@ class JobFilterSet(BaseFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Job
|
model = Job
|
||||||
fields = ('id', 'object_type', 'object_id', 'name', 'interval', 'status', 'user', 'job_id')
|
fields = ('id', 'object_type', 'object_type_id', 'object_id', 'name', 'interval', 'status', 'user', 'job_id')
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
@@ -134,6 +143,7 @@ class JobFilterSet(BaseFilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class ObjectTypeFilterSet(BaseFilterSet):
|
class ObjectTypeFilterSet(BaseFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
@@ -159,6 +169,7 @@ class ObjectTypeFilterSet(BaseFilterSet):
|
|||||||
return queryset.filter(features__icontains=value)
|
return queryset.filter(features__icontains=value)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class ObjectChangeFilterSet(BaseFilterSet):
|
class ObjectChangeFilterSet(BaseFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
@@ -169,6 +180,7 @@ class ObjectChangeFilterSet(BaseFilterSet):
|
|||||||
changed_object_type_id = django_filters.ModelMultipleChoiceFilter(
|
changed_object_type_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
queryset=ContentType.objects.all()
|
queryset=ContentType.objects.all()
|
||||||
)
|
)
|
||||||
|
related_object_type = ContentTypeFilter()
|
||||||
user_id = django_filters.ModelMultipleChoiceFilter(
|
user_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
queryset=User.objects.all(),
|
queryset=User.objects.all(),
|
||||||
label=_('User (ID)'),
|
label=_('User (ID)'),
|
||||||
@@ -197,6 +209,7 @@ class ObjectChangeFilterSet(BaseFilterSet):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@register_filterset
|
||||||
class ConfigRevisionFilterSet(BaseFilterSet):
|
class ConfigRevisionFilterSet(BaseFilterSet):
|
||||||
q = django_filters.CharFilter(
|
q = django_filters.CharFilter(
|
||||||
method='search',
|
method='search',
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from core.choices import JobIntervalChoices
|
from core.choices import JobIntervalChoices
|
||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.forms import NetBoxModelBulkEditForm
|
from netbox.forms import PrimaryModelBulkEditForm
|
||||||
from netbox.utils import get_data_backend_choices
|
from netbox.utils import get_data_backend_choices
|
||||||
from utilities.forms.fields import CommentField
|
|
||||||
from utilities.forms.rendering import FieldSet
|
from utilities.forms.rendering import FieldSet
|
||||||
from utilities.forms.widgets import BulkEditNullBooleanSelect
|
from utilities.forms.widgets import BulkEditNullBooleanSelect
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
class DataSourceBulkEditForm(PrimaryModelBulkEditForm):
|
||||||
type = forms.ChoiceField(
|
type = forms.ChoiceField(
|
||||||
label=_('Type'),
|
label=_('Type'),
|
||||||
choices=get_data_backend_choices,
|
choices=get_data_backend_choices,
|
||||||
@@ -25,17 +24,11 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
widget=BulkEditNullBooleanSelect(),
|
widget=BulkEditNullBooleanSelect(),
|
||||||
label=_('Enabled')
|
label=_('Enabled')
|
||||||
)
|
)
|
||||||
description = forms.CharField(
|
|
||||||
label=_('Description'),
|
|
||||||
max_length=200,
|
|
||||||
required=False
|
|
||||||
)
|
|
||||||
sync_interval = forms.ChoiceField(
|
sync_interval = forms.ChoiceField(
|
||||||
choices=JobIntervalChoices,
|
choices=JobIntervalChoices,
|
||||||
required=False,
|
required=False,
|
||||||
label=_('Sync interval')
|
label=_('Sync interval')
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
parameters = forms.JSONField(
|
parameters = forms.JSONField(
|
||||||
label=_('Parameters'),
|
label=_('Parameters'),
|
||||||
required=False
|
required=False
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.forms import NetBoxModelImportForm
|
from netbox.forms import PrimaryModelImportForm
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'DataSourceImportForm',
|
'DataSourceImportForm',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceImportForm(NetBoxModelImportForm):
|
class DataSourceImportForm(PrimaryModelImportForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
fields = (
|
||||||
'name', 'type', 'source_url', 'enabled', 'description', 'sync_interval', 'parameters', 'ignore_rules',
|
'name', 'type', 'source_url', 'enabled', 'description', 'sync_interval', 'parameters', 'ignore_rules',
|
||||||
'comments',
|
'owner', 'comments',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from core.choices import *
|
from core.choices import *
|
||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.forms import NetBoxModelFilterSetForm
|
from netbox.forms import NetBoxModelFilterSetForm, PrimaryModelFilterSetForm
|
||||||
from netbox.forms.mixins import SavedFiltersMixin
|
from netbox.forms.mixins import SavedFiltersMixin
|
||||||
from netbox.utils import get_data_backend_choices
|
from netbox.utils import get_data_backend_choices
|
||||||
from users.models import User
|
from users.models import User
|
||||||
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, FilterForm, add_blank_choice
|
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, FilterForm, add_blank_choice
|
||||||
from utilities.forms.fields import (
|
from utilities.forms.fields import (
|
||||||
ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelMultipleChoiceField,
|
ContentTypeChoiceField, ContentTypeMultipleChoiceField, DynamicModelMultipleChoiceField, TagFilterField,
|
||||||
)
|
)
|
||||||
from utilities.forms.rendering import FieldSet
|
from utilities.forms.rendering import FieldSet
|
||||||
from utilities.forms.widgets import DateTimePicker
|
from utilities.forms.widgets import DateTimePicker
|
||||||
@@ -23,10 +23,10 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceFilterForm(NetBoxModelFilterSetForm):
|
class DataSourceFilterForm(PrimaryModelFilterSetForm):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id'),
|
FieldSet('q', 'filter_id', 'tag', 'owner_id'),
|
||||||
FieldSet('type', 'status', 'enabled', 'sync_interval', name=_('Data Source')),
|
FieldSet('type', 'status', 'enabled', 'sync_interval', name=_('Data Source')),
|
||||||
)
|
)
|
||||||
type = forms.MultipleChoiceField(
|
type = forms.MultipleChoiceField(
|
||||||
@@ -51,6 +51,7 @@ class DataSourceFilterForm(NetBoxModelFilterSetForm):
|
|||||||
choices=JobIntervalChoices,
|
choices=JobIntervalChoices,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
class DataFileFilterForm(NetBoxModelFilterSetForm):
|
class DataFileFilterForm(NetBoxModelFilterSetForm):
|
||||||
@@ -70,13 +71,13 @@ class JobFilterForm(SavedFiltersMixin, FilterForm):
|
|||||||
model = Job
|
model = Job
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
FieldSet('q', 'filter_id'),
|
FieldSet('q', 'filter_id'),
|
||||||
FieldSet('object_type', 'status', name=_('Attributes')),
|
FieldSet('object_type_id', 'status', name=_('Attributes')),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'created__before', 'created__after', 'scheduled__before', 'scheduled__after', 'started__before',
|
'created__before', 'created__after', 'scheduled__before', 'scheduled__after', 'started__before',
|
||||||
'started__after', 'completed__before', 'completed__after', 'user', name=_('Creation')
|
'started__after', 'completed__before', 'completed__after', 'user', name=_('Creation')
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
object_type = ContentTypeChoiceField(
|
object_type_id = ContentTypeChoiceField(
|
||||||
label=_('Object Type'),
|
label=_('Object Type'),
|
||||||
queryset=ObjectType.objects.with_feature('jobs'),
|
queryset=ObjectType.objects.with_feature('jobs'),
|
||||||
required=False,
|
required=False,
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from core.forms.mixins import SyncedDataMixin
|
from core.forms.mixins import SyncedDataMixin
|
||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.config import get_config, PARAMS
|
from netbox.config import get_config, PARAMS
|
||||||
from netbox.forms import NetBoxModelForm
|
from netbox.forms import NetBoxModelForm, PrimaryModelForm
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
from netbox.utils import get_data_backend_choices
|
from netbox.utils import get_data_backend_choices
|
||||||
from utilities.forms import get_field_value
|
from utilities.forms import get_field_value
|
||||||
from utilities.forms.fields import CommentField, JSONField
|
from utilities.forms.fields import JSONField
|
||||||
from utilities.forms.rendering import FieldSet
|
from utilities.forms.rendering import FieldSet
|
||||||
from utilities.forms.widgets import HTMXSelect
|
from utilities.forms.widgets import HTMXSelect
|
||||||
|
|
||||||
@@ -26,17 +26,17 @@ __all__ = (
|
|||||||
EMPTY_VALUES = ('', None, [], ())
|
EMPTY_VALUES = ('', None, [], ())
|
||||||
|
|
||||||
|
|
||||||
class DataSourceForm(NetBoxModelForm):
|
class DataSourceForm(PrimaryModelForm):
|
||||||
type = forms.ChoiceField(
|
type = forms.ChoiceField(
|
||||||
choices=get_data_backend_choices,
|
choices=get_data_backend_choices,
|
||||||
widget=HTMXSelect()
|
widget=HTMXSelect()
|
||||||
)
|
)
|
||||||
comments = CommentField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'type', 'source_url', 'enabled', 'description', 'sync_interval', 'ignore_rules', 'comments', 'tags',
|
'name', 'type', 'source_url', 'enabled', 'description', 'sync_interval', 'ignore_rules', 'owner',
|
||||||
|
'comments', 'tags',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'ignore_rules': forms.Textarea(
|
'ignore_rules': forms.Textarea(
|
||||||
@@ -166,8 +166,8 @@ class ConfigRevisionForm(forms.ModelForm, metaclass=ConfigFormMetaclass):
|
|||||||
FieldSet('CUSTOM_VALIDATORS', 'PROTECTION_RULES', name=_('Validation')),
|
FieldSet('CUSTOM_VALIDATORS', 'PROTECTION_RULES', name=_('Validation')),
|
||||||
FieldSet('DEFAULT_USER_PREFERENCES', name=_('User Preferences')),
|
FieldSet('DEFAULT_USER_PREFERENCES', name=_('User Preferences')),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', 'MAPS_URL',
|
'MAINTENANCE_MODE', 'COPILOT_ENABLED', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION',
|
||||||
name=_('Miscellaneous')
|
'MAPS_URL', name=_('Miscellaneous'),
|
||||||
),
|
),
|
||||||
FieldSet('comment', name=_('Config Revision'))
|
FieldSet('comment', name=_('Config Revision'))
|
||||||
)
|
)
|
||||||
|
|||||||
11
netbox/core/graphql/enums.py
Normal file
11
netbox/core/graphql/enums.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import strawberry
|
||||||
|
|
||||||
|
from core.choices import *
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'DataSourceStatusEnum',
|
||||||
|
'ObjectChangeActionEnum',
|
||||||
|
)
|
||||||
|
|
||||||
|
DataSourceStatusEnum = strawberry.enum(DataSourceStatusChoices.as_enum(prefix='status'))
|
||||||
|
ObjectChangeActionEnum = strawberry.enum(ObjectChangeActionChoices.as_enum(prefix='action'))
|
||||||
@@ -5,7 +5,7 @@ from typing import Annotated, TYPE_CHECKING
|
|||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
from strawberry import ID
|
from strawberry import ID
|
||||||
from strawberry_django import DatetimeFilterLookup
|
from strawberry_django import FilterLookup, DatetimeFilterLookup
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .filters import *
|
from .filters import *
|
||||||
@@ -23,12 +23,13 @@ class BaseFilterMixin: ...
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BaseObjectTypeFilterMixin(BaseFilterMixin):
|
class BaseObjectTypeFilterMixin(BaseFilterMixin):
|
||||||
id: ID | None = strawberry.UNSET
|
id: FilterLookup[ID] | None = strawberry_django.filter_field()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ChangeLogFilterMixin(BaseFilterMixin):
|
class ChangeLogFilterMixin(BaseFilterMixin):
|
||||||
id: ID | None = strawberry.UNSET
|
id: FilterLookup[ID] | None = strawberry_django.filter_field()
|
||||||
|
# TODO: "changelog" is not a valid field name; needs to be updated for ObjectChange
|
||||||
changelog: Annotated['ObjectChangeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
changelog: Annotated['ObjectChangeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ import strawberry
|
|||||||
import strawberry_django
|
import strawberry_django
|
||||||
from django.contrib.contenttypes.models import ContentType as DjangoContentType
|
from django.contrib.contenttypes.models import ContentType as DjangoContentType
|
||||||
from strawberry.scalars import ID
|
from strawberry.scalars import ID
|
||||||
from strawberry_django import DatetimeFilterLookup, FilterLookup
|
from strawberry_django import BaseFilterLookup, DatetimeFilterLookup, FilterLookup
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
from core.graphql.filter_mixins import BaseFilterMixin
|
from core.graphql.filter_mixins import BaseFilterMixin
|
||||||
from netbox.graphql.filter_mixins import PrimaryModelFilterMixin
|
from netbox.graphql.filter_mixins import PrimaryModelFilterMixin
|
||||||
|
from .enums import *
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from netbox.graphql.filter_lookups import IntegerLookup, JSONFilter
|
from netbox.graphql.filter_lookups import IntegerLookup, JSONFilter
|
||||||
@@ -25,7 +26,7 @@ __all__ = (
|
|||||||
|
|
||||||
@strawberry_django.filter_type(models.DataFile, lookups=True)
|
@strawberry_django.filter_type(models.DataFile, lookups=True)
|
||||||
class DataFileFilter(BaseFilterMixin):
|
class DataFileFilter(BaseFilterMixin):
|
||||||
id: ID | None = strawberry_django.filter_field()
|
id: FilterLookup[ID] | None = strawberry_django.filter_field()
|
||||||
created: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
created: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
||||||
last_updated: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
last_updated: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
||||||
source: Annotated['DataSourceFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
source: Annotated['DataSourceFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
||||||
@@ -44,7 +45,9 @@ class DataSourceFilter(PrimaryModelFilterMixin):
|
|||||||
name: FilterLookup[str] | None = strawberry_django.filter_field()
|
name: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
type: FilterLookup[str] | None = strawberry_django.filter_field()
|
type: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
source_url: FilterLookup[str] | None = strawberry_django.filter_field()
|
source_url: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
status: FilterLookup[str] | None = strawberry_django.filter_field()
|
status: (
|
||||||
|
BaseFilterLookup[Annotated['DataSourceStatusEnum', strawberry.lazy('core.graphql.enums')]] | None
|
||||||
|
) = strawberry_django.filter_field()
|
||||||
enabled: FilterLookup[bool] | None = strawberry_django.filter_field()
|
enabled: FilterLookup[bool] | None = strawberry_django.filter_field()
|
||||||
ignore_rules: FilterLookup[str] | None = strawberry_django.filter_field()
|
ignore_rules: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
parameters: Annotated['JSONFilter', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
parameters: Annotated['JSONFilter', strawberry.lazy('netbox.graphql.filter_lookups')] | None = (
|
||||||
@@ -58,12 +61,14 @@ class DataSourceFilter(PrimaryModelFilterMixin):
|
|||||||
|
|
||||||
@strawberry_django.filter_type(models.ObjectChange, lookups=True)
|
@strawberry_django.filter_type(models.ObjectChange, lookups=True)
|
||||||
class ObjectChangeFilter(BaseFilterMixin):
|
class ObjectChangeFilter(BaseFilterMixin):
|
||||||
id: ID | None = strawberry_django.filter_field()
|
id: FilterLookup[ID] | None = strawberry_django.filter_field()
|
||||||
time: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
time: DatetimeFilterLookup[datetime] | None = strawberry_django.filter_field()
|
||||||
user: Annotated['UserFilter', strawberry.lazy('users.graphql.filters')] | None = strawberry_django.filter_field()
|
user: Annotated['UserFilter', strawberry.lazy('users.graphql.filters')] | None = strawberry_django.filter_field()
|
||||||
user_name: FilterLookup[str] | None = strawberry_django.filter_field()
|
user_name: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
request_id: FilterLookup[str] | None = strawberry_django.filter_field()
|
request_id: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
action: FilterLookup[str] | None = strawberry_django.filter_field()
|
action: (
|
||||||
|
BaseFilterLookup[Annotated['ObjectChangeActionEnum', strawberry.lazy('core.graphql.enums')]] | None
|
||||||
|
) = strawberry_django.filter_field()
|
||||||
changed_object_type: Annotated['ContentTypeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
changed_object_type: Annotated['ContentTypeFilter', strawberry.lazy('core.graphql.filters')] | None = (
|
||||||
strawberry_django.filter_field()
|
strawberry_django.filter_field()
|
||||||
)
|
)
|
||||||
@@ -84,6 +89,6 @@ class ObjectChangeFilter(BaseFilterMixin):
|
|||||||
|
|
||||||
@strawberry_django.filter_type(DjangoContentType, lookups=True)
|
@strawberry_django.filter_type(DjangoContentType, lookups=True)
|
||||||
class ContentTypeFilter(BaseFilterMixin):
|
class ContentTypeFilter(BaseFilterMixin):
|
||||||
id: ID | None = strawberry_django.filter_field()
|
id: FilterLookup[ID] | None = strawberry_django.filter_field()
|
||||||
app_label: FilterLookup[str] | None = strawberry_django.filter_field()
|
app_label: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
model: FilterLookup[str] | None = strawberry_django.filter_field()
|
model: FilterLookup[str] | None = strawberry_django.filter_field()
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ from typing import Annotated, List, TYPE_CHECKING
|
|||||||
import strawberry
|
import strawberry
|
||||||
import strawberry_django
|
import strawberry_django
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from strawberry.types import Info
|
||||||
|
|
||||||
from core.models import ObjectChange
|
from core.models import ObjectChange
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from core.graphql.types import DataFileType, DataSourceType
|
from core.graphql.types import DataFileType, DataSourceType, ObjectChangeType
|
||||||
from netbox.core.graphql.types import ObjectChangeType
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ChangelogMixin',
|
'ChangelogMixin',
|
||||||
@@ -20,7 +20,7 @@ __all__ = (
|
|||||||
class ChangelogMixin:
|
class ChangelogMixin:
|
||||||
|
|
||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def changelog(self, info) -> List[Annotated["ObjectChangeType", strawberry.lazy('.types')]]: # noqa: F821
|
def changelog(self, info: Info) -> List[Annotated['ObjectChangeType', strawberry.lazy('.types')]]: # noqa: F821
|
||||||
content_type = ContentType.objects.get_for_model(self)
|
content_type = ContentType.objects.get_for_model(self)
|
||||||
object_changes = ObjectChange.objects.filter(
|
object_changes = ObjectChange.objects.filter(
|
||||||
changed_object_type=content_type,
|
changed_object_type=content_type,
|
||||||
@@ -31,5 +31,5 @@ class ChangelogMixin:
|
|||||||
|
|
||||||
@strawberry.type
|
@strawberry.type
|
||||||
class SyncedDataMixin:
|
class SyncedDataMixin:
|
||||||
data_source: Annotated["DataSourceType", strawberry.lazy('core.graphql.types')] | None
|
data_source: Annotated['DataSourceType', strawberry.lazy('core.graphql.types')] | None
|
||||||
data_file: Annotated["DataFileType", strawberry.lazy('core.graphql.types')] | None
|
data_file: Annotated['DataFileType', strawberry.lazy('core.graphql.types')] | None
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import strawberry_django
|
|||||||
from django.contrib.contenttypes.models import ContentType as DjangoContentType
|
from django.contrib.contenttypes.models import ContentType as DjangoContentType
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
from netbox.graphql.types import BaseObjectType, NetBoxObjectType
|
from netbox.graphql.types import BaseObjectType, PrimaryObjectType
|
||||||
from .filters import *
|
from .filters import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@@ -32,8 +32,7 @@ class DataFileType(BaseObjectType):
|
|||||||
filters=DataSourceFilter,
|
filters=DataSourceFilter,
|
||||||
pagination=True
|
pagination=True
|
||||||
)
|
)
|
||||||
class DataSourceType(NetBoxObjectType):
|
class DataSourceType(PrimaryObjectType):
|
||||||
|
|
||||||
datafiles: List[Annotated["DataFileType", strawberry.lazy('core.graphql.types')]]
|
datafiles: List[Annotated["DataFileType", strawberry.lazy('core.graphql.types')]]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
48
netbox/core/migrations/0019_configrevision_active.py
Normal file
48
netbox/core/migrations/0019_configrevision_active.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# Generated by Django 5.2.5 on 2025-09-09 16:48
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def get_active(apps, schema_editor):
|
||||||
|
from django.core.cache import cache
|
||||||
|
ConfigRevision = apps.get_model('core', 'ConfigRevision')
|
||||||
|
version = None
|
||||||
|
revision = None
|
||||||
|
|
||||||
|
# Try and get the latest version from cache
|
||||||
|
try:
|
||||||
|
version = cache.get('config_version')
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# If there is a version in cache, attempt to set revision to the current version from cache
|
||||||
|
# If the version in cache does not exist or there is no version, try the lastest revision in the database
|
||||||
|
if not version or (version and not (revision := ConfigRevision.objects.filter(pk=version).first())):
|
||||||
|
revision = ConfigRevision.objects.order_by('-created').first()
|
||||||
|
|
||||||
|
# If there is a revision set, set the active revision
|
||||||
|
if revision:
|
||||||
|
revision.active = True
|
||||||
|
revision.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0018_concrete_objecttype'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='configrevision',
|
||||||
|
name='active',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
migrations.RunPython(code=get_active, reverse_code=migrations.RunPython.noop),
|
||||||
|
migrations.AddConstraint(
|
||||||
|
model_name='configrevision',
|
||||||
|
constraint=models.UniqueConstraint(
|
||||||
|
condition=models.Q(('active', True)), fields=('active',), name='unique_active_config_revision'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
19
netbox/core/migrations/0020_owner.py
Normal file
19
netbox/core/migrations/0020_owner.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('core', '0019_configrevision_active'),
|
||||||
|
('users', '0015_owner'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='users.owner'
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -14,6 +14,9 @@ class ConfigRevision(models.Model):
|
|||||||
"""
|
"""
|
||||||
An atomic revision of NetBox's configuration.
|
An atomic revision of NetBox's configuration.
|
||||||
"""
|
"""
|
||||||
|
active = models.BooleanField(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
created = models.DateTimeField(
|
created = models.DateTimeField(
|
||||||
verbose_name=_('created'),
|
verbose_name=_('created'),
|
||||||
auto_now_add=True
|
auto_now_add=True
|
||||||
@@ -35,6 +38,13 @@ class ConfigRevision(models.Model):
|
|||||||
ordering = ['-created']
|
ordering = ['-created']
|
||||||
verbose_name = _('config revision')
|
verbose_name = _('config revision')
|
||||||
verbose_name_plural = _('config revisions')
|
verbose_name_plural = _('config revisions')
|
||||||
|
constraints = [
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=('active',),
|
||||||
|
condition=models.Q(active=True),
|
||||||
|
name='unique_active_config_revision',
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if not self.pk:
|
if not self.pk:
|
||||||
@@ -59,8 +69,13 @@ class ConfigRevision(models.Model):
|
|||||||
"""
|
"""
|
||||||
cache.set('config', self.data, None)
|
cache.set('config', self.data, None)
|
||||||
cache.set('config_version', self.pk, None)
|
cache.set('config_version', self.pk, None)
|
||||||
|
|
||||||
|
# Set all instances of ConfigRevision to false and set this instance to true
|
||||||
|
ConfigRevision.objects.all().update(active=False)
|
||||||
|
ConfigRevision.objects.filter(pk=self.pk).update(active=True)
|
||||||
|
|
||||||
activate.alters_data = True
|
activate.alters_data = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_active(self):
|
def is_active(self):
|
||||||
return cache.get('config_version') == self.pk
|
return self.active
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
# TODO: Remove this module in NetBox v4.5
|
|
||||||
# Provided for backward compatibility
|
|
||||||
from .object_types import *
|
|
||||||
@@ -6,7 +6,6 @@ from django.conf import settings
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.files.storage import storages
|
from django.core.files.storage import storages
|
||||||
from django.urls import reverse
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from ..choices import ManagedFileRootPathChoices
|
from ..choices import ManagedFileRootPathChoices
|
||||||
@@ -64,9 +63,6 @@ class ManagedFile(SyncedDataMixin, models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('core:managedfile', args=[self.pk])
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.file_path
|
return self.file_path
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
from django.contrib.postgres.indexes import GinIndex
|
from django.contrib.postgres.indexes import GinIndex
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db import models
|
from django.db import connection, models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
@@ -66,6 +66,14 @@ class ObjectTypeManager(models.Manager):
|
|||||||
"""
|
"""
|
||||||
from netbox.models.features import get_model_features, model_is_public
|
from netbox.models.features import get_model_features, model_is_public
|
||||||
|
|
||||||
|
# TODO: Remove this in NetBox v5.0
|
||||||
|
# If the ObjectType table has not yet been provisioned (e.g. because we're in a pre-v4.4 migration),
|
||||||
|
# fall back to ContentType.
|
||||||
|
if 'core_objecttype' not in connection.introspection.table_names():
|
||||||
|
ct = ContentType.objects.get_for_model(model, for_concrete_model=for_concrete_model)
|
||||||
|
ct.features = get_model_features(ct.model_class())
|
||||||
|
return ct
|
||||||
|
|
||||||
if not inspect.isclass(model):
|
if not inspect.isclass(model):
|
||||||
model = model.__class__
|
model = model.__class__
|
||||||
opts = self._get_opts(model, for_concrete_model)
|
opts = self._get_opts(model, for_concrete_model)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from netbox.object_actions import ObjectAction
|
from netbox.object_actions import ObjectAction
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from threading import local
|
|||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||||
|
from django.db.models import CASCADE
|
||||||
from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel
|
from django.db.models.fields.reverse_related import ManyToManyRel, ManyToOneRel
|
||||||
from django.db.models.signals import m2m_changed, post_migrate, post_save, pre_delete
|
from django.db.models.signals import m2m_changed, post_migrate, post_save, pre_delete
|
||||||
from django.dispatch import receiver, Signal
|
from django.dispatch import receiver, Signal
|
||||||
@@ -220,14 +221,8 @@ def handle_deleted_object(sender, instance, **kwargs):
|
|||||||
obj.snapshot() # Ensure the change record includes the "before" state
|
obj.snapshot() # Ensure the change record includes the "before" state
|
||||||
if type(relation) is ManyToManyRel:
|
if type(relation) is ManyToManyRel:
|
||||||
getattr(obj, related_field_name).remove(instance)
|
getattr(obj, related_field_name).remove(instance)
|
||||||
elif type(relation) is ManyToOneRel and relation.field.null is True:
|
elif type(relation) is ManyToOneRel and relation.null and relation.on_delete is not CASCADE:
|
||||||
setattr(obj, related_field_name, None)
|
setattr(obj, related_field_name, None)
|
||||||
# make sure the object hasn't been deleted - in case of
|
|
||||||
# deletion chaining of related objects
|
|
||||||
try:
|
|
||||||
obj.refresh_from_db()
|
|
||||||
except DoesNotExist:
|
|
||||||
continue
|
|
||||||
obj.save()
|
obj.save()
|
||||||
|
|
||||||
# Enqueue the object for event processing
|
# Enqueue the object for event processing
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
|
|
||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.tables import NetBoxTable, columns
|
from netbox.tables import NetBoxTable, PrimaryModelTable, columns
|
||||||
from .columns import BackendTypeColumn
|
from .columns import BackendTypeColumn
|
||||||
from .template_code import DATA_SOURCE_SYNC_BUTTON
|
from .template_code import DATA_SOURCE_SYNC_BUTTON
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceTable(NetBoxTable):
|
class DataSourceTable(PrimaryModelTable):
|
||||||
name = tables.Column(
|
name = tables.Column(
|
||||||
verbose_name=_('Name'),
|
verbose_name=_('Name'),
|
||||||
linkify=True,
|
linkify=True,
|
||||||
@@ -42,7 +42,7 @@ class DataSourceTable(NetBoxTable):
|
|||||||
extra_buttons=DATA_SOURCE_SYNC_BUTTON,
|
extra_buttons=DATA_SOURCE_SYNC_BUTTON,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta(NetBoxTable.Meta):
|
class Meta(PrimaryModelTable.Meta):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
fields = (
|
||||||
'pk', 'id', 'name', 'type', 'status', 'enabled', 'source_url', 'description', 'sync_interval', 'comments',
|
'pk', 'id', 'name', 'type', 'status', 'enabled', 'source_url', 'description', 'sync_interval', 'comments',
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from rq.job import Job as RQ_Job, JobStatus
|
|||||||
from rq.registry import FailedJobRegistry, StartedJobRegistry
|
from rq.registry import FailedJobRegistry, StartedJobRegistry
|
||||||
|
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
from users.constants import TOKEN_PREFIX
|
||||||
from users.models import Token, User
|
from users.models import Token, User
|
||||||
from utilities.testing import APITestCase, APIViewTestCases, TestCase
|
from utilities.testing import APITestCase, APIViewTestCases, TestCase
|
||||||
from utilities.testing.utils import disable_logging
|
from utilities.testing.utils import disable_logging
|
||||||
@@ -107,14 +108,14 @@ class ObjectTypeTest(APITestCase):
|
|||||||
def test_list_objects(self):
|
def test_list_objects(self):
|
||||||
object_type_count = ObjectType.objects.count()
|
object_type_count = ObjectType.objects.count()
|
||||||
|
|
||||||
response = self.client.get(reverse('extras-api:objecttype-list'), **self.header)
|
response = self.client.get(reverse('core-api:objecttype-list'), **self.header)
|
||||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data['count'], object_type_count)
|
self.assertEqual(response.data['count'], object_type_count)
|
||||||
|
|
||||||
def test_get_object(self):
|
def test_get_object(self):
|
||||||
object_type = ObjectType.objects.first()
|
object_type = ObjectType.objects.first()
|
||||||
|
|
||||||
url = reverse('extras-api:objecttype-detail', kwargs={'pk': object_type.pk})
|
url = reverse('core-api:objecttype-detail', kwargs={'pk': object_type.pk})
|
||||||
self.assertHttpStatus(self.client.get(url, **self.header), status.HTTP_200_OK)
|
self.assertHttpStatus(self.client.get(url, **self.header), status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
@@ -134,12 +135,9 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
Create a user and token for API calls.
|
Create a user and token for API calls.
|
||||||
"""
|
"""
|
||||||
# Create the test user and assign permissions
|
# Create the test user and assign permissions
|
||||||
self.user = User.objects.create_user(username='testuser')
|
self.user = User.objects.create_user(username='testuser', is_active=True)
|
||||||
self.user.is_staff = True
|
|
||||||
self.user.is_active = True
|
|
||||||
self.user.save()
|
|
||||||
self.token = Token.objects.create(user=self.user)
|
self.token = Token.objects.create(user=self.user)
|
||||||
self.header = {'HTTP_AUTHORIZATION': f'Token {self.token.key}'}
|
self.header = {'HTTP_AUTHORIZATION': f'Bearer {TOKEN_PREFIX}{self.token.key}.{self.token.token}'}
|
||||||
|
|
||||||
# Clear all queues prior to running each test
|
# Clear all queues prior to running each test
|
||||||
get_queue('default').connection.flushall()
|
get_queue('default').connection.flushall()
|
||||||
@@ -150,13 +148,11 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
url = reverse('core-api:rqqueue-list')
|
url = reverse('core-api:rqqueue-list')
|
||||||
|
|
||||||
# Attempt to load view without permission
|
# Attempt to load view without permission
|
||||||
self.user.is_staff = False
|
|
||||||
self.user.save()
|
|
||||||
response = self.client.get(url, **self.header)
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
# Load view with permission
|
# Load view with permission
|
||||||
self.user.is_staff = True
|
self.user.is_superuser = True
|
||||||
self.user.save()
|
self.user.save()
|
||||||
response = self.client.get(url, **self.header)
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
@@ -165,7 +161,16 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
self.assertIn('low', str(response.content))
|
self.assertIn('low', str(response.content))
|
||||||
|
|
||||||
def test_background_queue(self):
|
def test_background_queue(self):
|
||||||
response = self.client.get(reverse('core-api:rqqueue-detail', args=['default']), **self.header)
|
url = reverse('core-api:rqqueue-detail', args=['default'])
|
||||||
|
|
||||||
|
# Attempt to load view without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Load view with permission
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn('default', str(response.content))
|
self.assertIn('default', str(response.content))
|
||||||
self.assertIn('oldest_job_timestamp', str(response.content))
|
self.assertIn('oldest_job_timestamp', str(response.content))
|
||||||
@@ -174,8 +179,16 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
def test_background_task_list(self):
|
def test_background_task_list(self):
|
||||||
queue = get_queue('default')
|
queue = get_queue('default')
|
||||||
queue.enqueue(self.dummy_job_default)
|
queue.enqueue(self.dummy_job_default)
|
||||||
|
url = reverse('core-api:rqtask-list')
|
||||||
|
|
||||||
response = self.client.get(reverse('core-api:rqtask-list'), **self.header)
|
# Attempt to load view without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Load view with permission
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn('origin', str(response.content))
|
self.assertIn('origin', str(response.content))
|
||||||
self.assertIn('core.tests.test_api.BackgroundTaskTestCase.dummy_job_default()', str(response.content))
|
self.assertIn('core.tests.test_api.BackgroundTaskTestCase.dummy_job_default()', str(response.content))
|
||||||
@@ -183,8 +196,16 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
def test_background_task(self):
|
def test_background_task(self):
|
||||||
queue = get_queue('default')
|
queue = get_queue('default')
|
||||||
job = queue.enqueue(self.dummy_job_default)
|
job = queue.enqueue(self.dummy_job_default)
|
||||||
|
url = reverse('core-api:rqtask-detail', args=[job.id])
|
||||||
|
|
||||||
response = self.client.get(reverse('core-api:rqtask-detail', args=[job.id]), **self.header)
|
# Attempt to load view without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Load view with permission
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn(str(job.id), str(response.content))
|
self.assertIn(str(job.id), str(response.content))
|
||||||
self.assertIn('origin', str(response.content))
|
self.assertIn('origin', str(response.content))
|
||||||
@@ -194,45 +215,65 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
def test_background_task_delete(self):
|
def test_background_task_delete(self):
|
||||||
queue = get_queue('default')
|
queue = get_queue('default')
|
||||||
job = queue.enqueue(self.dummy_job_default)
|
job = queue.enqueue(self.dummy_job_default)
|
||||||
|
url = reverse('core-api:rqtask-delete', args=[job.id])
|
||||||
|
|
||||||
response = self.client.post(reverse('core-api:rqtask-delete', args=[job.id]), **self.header)
|
# Attempt to load view without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Load view with permission
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertFalse(RQ_Job.exists(job.id, connection=queue.connection))
|
self.assertFalse(RQ_Job.exists(job.id, connection=queue.connection))
|
||||||
queue = get_queue('default')
|
queue = get_queue('default')
|
||||||
self.assertNotIn(job.id, queue.job_ids)
|
self.assertNotIn(job.id, queue.job_ids)
|
||||||
|
|
||||||
def test_background_task_requeue(self):
|
def test_background_task_requeue(self):
|
||||||
queue = get_queue('default')
|
|
||||||
|
|
||||||
# Enqueue & run a job that will fail
|
# Enqueue & run a job that will fail
|
||||||
|
queue = get_queue('default')
|
||||||
job = queue.enqueue(self.dummy_job_failing)
|
job = queue.enqueue(self.dummy_job_failing)
|
||||||
worker = get_worker('default')
|
worker = get_worker('default')
|
||||||
with disable_logging():
|
with disable_logging():
|
||||||
worker.work(burst=True)
|
worker.work(burst=True)
|
||||||
self.assertTrue(job.is_failed)
|
self.assertTrue(job.is_failed)
|
||||||
|
url = reverse('core-api:rqtask-requeue', args=[job.id])
|
||||||
|
|
||||||
|
# Attempt to requeue the job without permission
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
# Re-enqueue the failed job and check that its status has been reset
|
# Re-enqueue the failed job and check that its status has been reset
|
||||||
response = self.client.post(reverse('core-api:rqtask-requeue', args=[job.id]), **self.header)
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
job = RQ_Job.fetch(job.id, queue.connection)
|
job = RQ_Job.fetch(job.id, queue.connection)
|
||||||
self.assertFalse(job.is_failed)
|
self.assertFalse(job.is_failed)
|
||||||
|
|
||||||
def test_background_task_enqueue(self):
|
def test_background_task_enqueue(self):
|
||||||
queue = get_queue('default')
|
|
||||||
|
|
||||||
# Enqueue some jobs that each depends on its predecessor
|
# Enqueue some jobs that each depends on its predecessor
|
||||||
|
queue = get_queue('default')
|
||||||
job = previous_job = None
|
job = previous_job = None
|
||||||
for _ in range(0, 3):
|
for _ in range(0, 3):
|
||||||
job = queue.enqueue(self.dummy_job_default, depends_on=previous_job)
|
job = queue.enqueue(self.dummy_job_default, depends_on=previous_job)
|
||||||
previous_job = job
|
previous_job = job
|
||||||
|
url = reverse('core-api:rqtask-enqueue', args=[job.id])
|
||||||
|
|
||||||
# Check that the last job to be enqueued has a status of deferred
|
# Check that the last job to be enqueued has a status of deferred
|
||||||
self.assertIsNotNone(job)
|
self.assertIsNotNone(job)
|
||||||
self.assertEqual(job.get_status(), JobStatus.DEFERRED)
|
self.assertEqual(job.get_status(), JobStatus.DEFERRED)
|
||||||
self.assertIsNone(job.enqueued_at)
|
self.assertIsNone(job.enqueued_at)
|
||||||
|
|
||||||
|
# Attempt to force-enqueue the job without permission
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
# Force-enqueue the deferred job
|
# Force-enqueue the deferred job
|
||||||
response = self.client.post(reverse('core-api:rqtask-enqueue', args=[job.id]), **self.header)
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
# Check that job's status is updated correctly
|
# Check that job's status is updated correctly
|
||||||
@@ -242,19 +283,27 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
|
|
||||||
def test_background_task_stop(self):
|
def test_background_task_stop(self):
|
||||||
queue = get_queue('default')
|
queue = get_queue('default')
|
||||||
|
|
||||||
worker = get_worker('default')
|
worker = get_worker('default')
|
||||||
job = queue.enqueue(self.dummy_job_default)
|
job = queue.enqueue(self.dummy_job_default)
|
||||||
worker.prepare_job_execution(job)
|
worker.prepare_job_execution(job)
|
||||||
|
url = reverse('core-api:rqtask-stop', args=[job.id])
|
||||||
self.assertEqual(job.get_status(), JobStatus.STARTED)
|
self.assertEqual(job.get_status(), JobStatus.STARTED)
|
||||||
response = self.client.post(reverse('core-api:rqtask-stop', args=[job.id]), **self.header)
|
|
||||||
|
# Attempt to stop the task without permission
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Stop the task
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.post(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
with disable_logging():
|
with disable_logging():
|
||||||
worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started
|
worker.monitor_work_horse(job, queue) # Sets the job as Failed and removes from Started
|
||||||
started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection)
|
started_job_registry = StartedJobRegistry(queue.name, connection=queue.connection)
|
||||||
self.assertEqual(len(started_job_registry), 0)
|
self.assertEqual(len(started_job_registry), 0)
|
||||||
|
|
||||||
|
# Verify that the task was cancelled
|
||||||
canceled_job_registry = FailedJobRegistry(queue.name, connection=queue.connection)
|
canceled_job_registry = FailedJobRegistry(queue.name, connection=queue.connection)
|
||||||
self.assertEqual(len(canceled_job_registry), 1)
|
self.assertEqual(len(canceled_job_registry), 1)
|
||||||
self.assertIn(job.id, canceled_job_registry)
|
self.assertIn(job.id, canceled_job_registry)
|
||||||
@@ -262,19 +311,34 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
def test_worker_list(self):
|
def test_worker_list(self):
|
||||||
worker1 = get_worker('default', name=uuid.uuid4().hex)
|
worker1 = get_worker('default', name=uuid.uuid4().hex)
|
||||||
worker1.register_birth()
|
worker1.register_birth()
|
||||||
|
|
||||||
worker2 = get_worker('high')
|
worker2 = get_worker('high')
|
||||||
worker2.register_birth()
|
worker2.register_birth()
|
||||||
|
url = reverse('core-api:rqworker-list')
|
||||||
|
|
||||||
response = self.client.get(reverse('core-api:rqworker-list'), **self.header)
|
# Attempt to fetch the worker list without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Fetch the worker list
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn(str(worker1.name), str(response.content))
|
self.assertIn(str(worker1.name), str(response.content))
|
||||||
|
|
||||||
def test_worker(self):
|
def test_worker(self):
|
||||||
worker1 = get_worker('default', name=uuid.uuid4().hex)
|
worker1 = get_worker('default', name=uuid.uuid4().hex)
|
||||||
worker1.register_birth()
|
worker1.register_birth()
|
||||||
|
url = reverse('core-api:rqworker-detail', args=[worker1.name])
|
||||||
|
|
||||||
response = self.client.get(reverse('core-api:rqworker-detail', args=[worker1.name]), **self.header)
|
# Attempt to fetch a worker without permission
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
|
# Fetch the worker
|
||||||
|
self.user.is_superuser = True
|
||||||
|
self.user.save()
|
||||||
|
response = self.client.get(url, **self.header)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn(str(worker1.name), str(response.content))
|
self.assertIn(str(worker1.name), str(response.content))
|
||||||
self.assertIn('birth_date', str(response.content))
|
self.assertIn('birth_date', str(response.content))
|
||||||
|
|||||||
@@ -5,14 +5,16 @@ from rest_framework import status
|
|||||||
|
|
||||||
from core.choices import ObjectChangeActionChoices
|
from core.choices import ObjectChangeActionChoices
|
||||||
from core.models import ObjectChange, ObjectType
|
from core.models import ObjectChange, ObjectType
|
||||||
from dcim.choices import SiteStatusChoices
|
from dcim.choices import InterfaceTypeChoices, ModuleStatusChoices, SiteStatusChoices
|
||||||
from dcim.models import Site, CableTermination, Device, DeviceType, DeviceRole, Interface, Cable
|
from dcim.models import (
|
||||||
|
Cable, CableTermination, Device, DeviceRole, DeviceType, Manufacturer, Module, ModuleBay, ModuleType, Interface,
|
||||||
|
Site,
|
||||||
|
)
|
||||||
from extras.choices import *
|
from extras.choices import *
|
||||||
from extras.models import CustomField, CustomFieldChoiceSet, Tag
|
from extras.models import CustomField, CustomFieldChoiceSet, Tag
|
||||||
from utilities.testing import APITestCase
|
from utilities.testing import APITestCase
|
||||||
from utilities.testing.utils import create_tags, post_data
|
from utilities.testing.utils import create_tags, create_test_device, post_data
|
||||||
from utilities.testing.views import ModelViewTestCase
|
from utilities.testing.views import ModelViewTestCase
|
||||||
from dcim.models import Manufacturer
|
|
||||||
|
|
||||||
|
|
||||||
class ChangeLogViewTest(ModelViewTestCase):
|
class ChangeLogViewTest(ModelViewTestCase):
|
||||||
@@ -622,3 +624,64 @@ class ChangeLogAPITest(APITestCase):
|
|||||||
self.assertEqual(objectchange.prechange_data['name'], 'Site 1')
|
self.assertEqual(objectchange.prechange_data['name'], 'Site 1')
|
||||||
self.assertEqual(objectchange.prechange_data['slug'], 'site-1')
|
self.assertEqual(objectchange.prechange_data['slug'], 'site-1')
|
||||||
self.assertEqual(objectchange.postchange_data, None)
|
self.assertEqual(objectchange.postchange_data, None)
|
||||||
|
|
||||||
|
def test_deletion_ordering(self):
|
||||||
|
"""
|
||||||
|
Check that the cascading deletion of dependent objects is recorded in the correct order.
|
||||||
|
"""
|
||||||
|
device = create_test_device('device1')
|
||||||
|
module_bay = ModuleBay.objects.create(device=device, name='Module Bay 1')
|
||||||
|
module_type = ModuleType.objects.create(manufacturer=Manufacturer.objects.first(), model='Module Type 1')
|
||||||
|
self.add_permissions('dcim.add_module', 'dcim.add_interface', 'dcim.delete_module')
|
||||||
|
self.assertEqual(ObjectChange.objects.count(), 0) # Sanity check
|
||||||
|
|
||||||
|
# Create a new Module
|
||||||
|
data = {
|
||||||
|
'device': device.pk,
|
||||||
|
'module_bay': module_bay.pk,
|
||||||
|
'module_type': module_type.pk,
|
||||||
|
'status': ModuleStatusChoices.STATUS_ACTIVE,
|
||||||
|
}
|
||||||
|
url = reverse('dcim-api:module-list')
|
||||||
|
response = self.client.post(url, data, format='json', **self.header)
|
||||||
|
self.assertHttpStatus(response, status.HTTP_201_CREATED)
|
||||||
|
module = device.modules.first()
|
||||||
|
|
||||||
|
# Create an Interface on the Module
|
||||||
|
data = {
|
||||||
|
'device': device.pk,
|
||||||
|
'module': module.pk,
|
||||||
|
'name': 'Interface 1',
|
||||||
|
'type': InterfaceTypeChoices.TYPE_1GE_FIXED,
|
||||||
|
}
|
||||||
|
url = reverse('dcim-api:interface-list')
|
||||||
|
response = self.client.post(url, data, format='json', **self.header)
|
||||||
|
self.assertHttpStatus(response, status.HTTP_201_CREATED)
|
||||||
|
interface = device.interfaces.first()
|
||||||
|
|
||||||
|
# Delete the Module
|
||||||
|
url = reverse('dcim-api:module-detail', kwargs={'pk': module.pk})
|
||||||
|
response = self.client.delete(url, **self.header)
|
||||||
|
self.assertHttpStatus(response, status.HTTP_204_NO_CONTENT)
|
||||||
|
self.assertEqual(Module.objects.count(), 0)
|
||||||
|
self.assertEqual(Interface.objects.count(), 0)
|
||||||
|
|
||||||
|
# Verify the creation of the expected ObjectChange records. We should see four total records, in this order:
|
||||||
|
# 1. Module created
|
||||||
|
# 2. Interface created
|
||||||
|
# 3. Interface deleted
|
||||||
|
# 4. Module deleted
|
||||||
|
changes = ObjectChange.objects.order_by('time')
|
||||||
|
self.assertEqual(len(changes), 4)
|
||||||
|
self.assertEqual(changes[0].changed_object_type, ContentType.objects.get_for_model(Module))
|
||||||
|
self.assertEqual(changes[0].changed_object_id, module.pk)
|
||||||
|
self.assertEqual(changes[0].action, ObjectChangeActionChoices.ACTION_CREATE)
|
||||||
|
self.assertEqual(changes[1].changed_object_type, ContentType.objects.get_for_model(Interface))
|
||||||
|
self.assertEqual(changes[1].changed_object_id, interface.pk)
|
||||||
|
self.assertEqual(changes[1].action, ObjectChangeActionChoices.ACTION_CREATE)
|
||||||
|
self.assertEqual(changes[2].changed_object_type, ContentType.objects.get_for_model(Interface))
|
||||||
|
self.assertEqual(changes[2].changed_object_id, interface.pk)
|
||||||
|
self.assertEqual(changes[2].action, ObjectChangeActionChoices.ACTION_DELETE)
|
||||||
|
self.assertEqual(changes[3].changed_object_type, ContentType.objects.get_for_model(Module))
|
||||||
|
self.assertEqual(changes[3].changed_object_id, module.pk)
|
||||||
|
self.assertEqual(changes[3].action, ObjectChangeActionChoices.ACTION_DELETE)
|
||||||
|
|||||||
108
netbox/core/tests/test_openapi_schema.py
Normal file
108
netbox/core/tests/test_openapi_schema.py
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
"""
|
||||||
|
Unit tests for OpenAPI schema generation.
|
||||||
|
|
||||||
|
Refs: #20638
|
||||||
|
"""
|
||||||
|
import json
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
class OpenAPISchemaTestCase(TestCase):
|
||||||
|
"""Tests for OpenAPI schema generation."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""Fetch schema via API endpoint."""
|
||||||
|
response = self.client.get('/api/schema/', {'format': 'json'})
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.schema = json.loads(response.content)
|
||||||
|
|
||||||
|
def test_post_operation_documents_single_or_array(self):
|
||||||
|
"""
|
||||||
|
POST operations on NetBoxModelViewSet endpoints should document
|
||||||
|
support for both single objects and arrays via oneOf.
|
||||||
|
|
||||||
|
Refs: #20638
|
||||||
|
"""
|
||||||
|
# Test representative endpoints across different apps
|
||||||
|
test_paths = [
|
||||||
|
'/api/core/data-sources/',
|
||||||
|
'/api/dcim/sites/',
|
||||||
|
'/api/users/users/',
|
||||||
|
'/api/ipam/ip-addresses/',
|
||||||
|
]
|
||||||
|
|
||||||
|
for path in test_paths:
|
||||||
|
with self.subTest(path=path):
|
||||||
|
operation = self.schema['paths'][path]['post']
|
||||||
|
|
||||||
|
# Get the request body schema
|
||||||
|
request_schema = operation['requestBody']['content']['application/json']['schema']
|
||||||
|
|
||||||
|
# Should have oneOf with two options
|
||||||
|
self.assertIn('oneOf', request_schema, f"POST {path} should have oneOf schema")
|
||||||
|
self.assertEqual(
|
||||||
|
len(request_schema['oneOf']), 2,
|
||||||
|
f"POST {path} oneOf should have exactly 2 options"
|
||||||
|
)
|
||||||
|
|
||||||
|
# First option: single object (has $ref or properties)
|
||||||
|
single_schema = request_schema['oneOf'][0]
|
||||||
|
self.assertTrue(
|
||||||
|
'$ref' in single_schema or 'properties' in single_schema,
|
||||||
|
f"POST {path} first oneOf option should be single object"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Second option: array of objects
|
||||||
|
array_schema = request_schema['oneOf'][1]
|
||||||
|
self.assertEqual(
|
||||||
|
array_schema['type'], 'array',
|
||||||
|
f"POST {path} second oneOf option should be array"
|
||||||
|
)
|
||||||
|
self.assertIn('items', array_schema, f"POST {path} array should have items")
|
||||||
|
|
||||||
|
def test_bulk_update_operations_require_array_only(self):
|
||||||
|
"""
|
||||||
|
Bulk update/patch operations should require arrays only, not oneOf.
|
||||||
|
They don't support single object input.
|
||||||
|
|
||||||
|
Refs: #20638
|
||||||
|
"""
|
||||||
|
test_paths = [
|
||||||
|
'/api/dcim/sites/',
|
||||||
|
'/api/users/users/',
|
||||||
|
]
|
||||||
|
|
||||||
|
for path in test_paths:
|
||||||
|
for method in ['put', 'patch']:
|
||||||
|
with self.subTest(path=path, method=method):
|
||||||
|
operation = self.schema['paths'][path][method]
|
||||||
|
request_schema = operation['requestBody']['content']['application/json']['schema']
|
||||||
|
|
||||||
|
# Should be array-only, not oneOf
|
||||||
|
self.assertNotIn(
|
||||||
|
'oneOf', request_schema,
|
||||||
|
f"{method.upper()} {path} should NOT have oneOf (array-only)"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
request_schema['type'], 'array',
|
||||||
|
f"{method.upper()} {path} should require array"
|
||||||
|
)
|
||||||
|
self.assertIn(
|
||||||
|
'items', request_schema,
|
||||||
|
f"{method.upper()} {path} array should have items"
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_bulk_delete_requires_array(self):
|
||||||
|
"""
|
||||||
|
Bulk delete operations should require arrays.
|
||||||
|
|
||||||
|
Refs: #20638
|
||||||
|
"""
|
||||||
|
path = '/api/dcim/sites/'
|
||||||
|
operation = self.schema['paths'][path]['delete']
|
||||||
|
request_schema = operation['requestBody']['content']['application/json']['schema']
|
||||||
|
|
||||||
|
# Should be array-only
|
||||||
|
self.assertNotIn('oneOf', request_schema, "DELETE should NOT have oneOf")
|
||||||
|
self.assertEqual(request_schema['type'], 'array', "DELETE should require array")
|
||||||
|
self.assertIn('items', request_schema, "DELETE array should have items")
|
||||||
@@ -158,7 +158,7 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.user.is_staff = True
|
self.user.is_superuser = True
|
||||||
self.user.is_active = True
|
self.user.is_active = True
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
@@ -171,13 +171,13 @@ class BackgroundTaskTestCase(TestCase):
|
|||||||
url = reverse('core:background_queue_list')
|
url = reverse('core:background_queue_list')
|
||||||
|
|
||||||
# Attempt to load view without permission
|
# Attempt to load view without permission
|
||||||
self.user.is_staff = False
|
self.user.is_superuser = False
|
||||||
self.user.save()
|
self.user.save()
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
# Load view with permission
|
# Load view with permission
|
||||||
self.user.is_staff = True
|
self.user.is_superuser = True
|
||||||
self.user.save()
|
self.user.save()
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
@@ -356,7 +356,7 @@ class SystemTestCase(TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.user.is_staff = True
|
self.user.is_superuser = True
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
def test_system_view_default(self):
|
def test_system_view_default(self):
|
||||||
|
|||||||
@@ -125,6 +125,7 @@ class DataSourceBulkEditView(generic.BulkEditView):
|
|||||||
@register_model_view(DataSource, 'bulk_rename', path='rename', detail=False)
|
@register_model_view(DataSource, 'bulk_rename', path='rename', detail=False)
|
||||||
class DataSourceBulkRenameView(generic.BulkRenameView):
|
class DataSourceBulkRenameView(generic.BulkRenameView):
|
||||||
queryset = DataSource.objects.all()
|
queryset = DataSource.objects.all()
|
||||||
|
filterset = filtersets.DataSourceFilterSet
|
||||||
|
|
||||||
|
|
||||||
@register_model_view(DataSource, 'bulk_delete', path='delete', detail=False)
|
@register_model_view(DataSource, 'bulk_delete', path='delete', detail=False)
|
||||||
@@ -372,7 +373,7 @@ class ConfigRevisionRestoreView(ContentTypePermissionRequiredMixin, View):
|
|||||||
class BaseRQView(UserPassesTestMixin, View):
|
class BaseRQView(UserPassesTestMixin, View):
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
return self.request.user.is_staff
|
return self.request.user.is_superuser
|
||||||
|
|
||||||
|
|
||||||
class BackgroundQueueListView(TableMixin, BaseRQView):
|
class BackgroundQueueListView(TableMixin, BaseRQView):
|
||||||
@@ -555,7 +556,7 @@ class WorkerView(BaseRQView):
|
|||||||
class SystemView(UserPassesTestMixin, View):
|
class SystemView(UserPassesTestMixin, View):
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
return self.request.user.is_staff
|
return self.request.user.is_superuser
|
||||||
|
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
|
|
||||||
@@ -638,7 +639,7 @@ class BasePluginView(UserPassesTestMixin, View):
|
|||||||
CACHE_KEY_CATALOG_ERROR = 'plugins-catalog-error'
|
CACHE_KEY_CATALOG_ERROR = 'plugins-catalog-error'
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
return self.request.user.is_staff
|
return self.request.user.is_superuser
|
||||||
|
|
||||||
def get_cached_plugins(self, request):
|
def get_cached_plugins(self, request):
|
||||||
catalog_plugins = {}
|
catalog_plugins = {}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from drf_spectacular.types import OpenApiTypes
|
from drf_spectacular.types import OpenApiTypes
|
||||||
from drf_spectacular.utils import extend_schema_field
|
from drf_spectacular.utils import extend_schema_field
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.constants import *
|
|
||||||
from dcim.models import Cable, CablePath, CableTermination
|
from dcim.models import Cable, CablePath, CableTermination
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField
|
from netbox.api.fields import ChoiceField, ContentTypeField
|
||||||
from netbox.api.serializers import BaseModelSerializer, GenericObjectSerializer, NetBoxModelSerializer
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
|
from netbox.api.serializers import (
|
||||||
|
BaseModelSerializer, GenericObjectSerializer, NetBoxModelSerializer, PrimaryModelSerializer,
|
||||||
|
)
|
||||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
from utilities.api import get_serializer_for_model
|
||||||
|
|
||||||
@@ -20,19 +21,20 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CableSerializer(NetBoxModelSerializer):
|
class CableSerializer(PrimaryModelSerializer):
|
||||||
a_terminations = GenericObjectSerializer(many=True, required=False)
|
a_terminations = GenericObjectSerializer(many=True, required=False)
|
||||||
b_terminations = GenericObjectSerializer(many=True, required=False)
|
b_terminations = GenericObjectSerializer(many=True, required=False)
|
||||||
status = ChoiceField(choices=LinkStatusChoices, required=False)
|
status = ChoiceField(choices=LinkStatusChoices, required=False)
|
||||||
|
profile = ChoiceField(choices=CableProfileChoices, required=False)
|
||||||
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
|
tenant = TenantSerializer(nested=True, required=False, allow_null=True)
|
||||||
length_unit = ChoiceField(choices=CableLengthUnitChoices, allow_blank=True, required=False, allow_null=True)
|
length_unit = ChoiceField(choices=CableLengthUnitChoices, allow_blank=True, required=False, allow_null=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Cable
|
model = Cable
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'type', 'a_terminations', 'b_terminations', 'status', 'tenant',
|
'id', 'url', 'display_url', 'display', 'type', 'a_terminations', 'b_terminations', 'status', 'profile',
|
||||||
'label', 'color', 'length', 'length_unit', 'description', 'comments', 'tags', 'custom_fields', 'created',
|
'tenant', 'label', 'color', 'length', 'length_unit', 'description', 'owner', 'comments', 'tags',
|
||||||
'last_updated',
|
'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'label', 'description')
|
brief_fields = ('id', 'url', 'display', 'label', 'description')
|
||||||
|
|
||||||
@@ -51,22 +53,20 @@ class TracedCableSerializer(BaseModelSerializer):
|
|||||||
|
|
||||||
class CableTerminationSerializer(NetBoxModelSerializer):
|
class CableTerminationSerializer(NetBoxModelSerializer):
|
||||||
termination_type = ContentTypeField(
|
termination_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.filter(CABLE_TERMINATION_MODELS)
|
read_only=True,
|
||||||
)
|
)
|
||||||
termination = serializers.SerializerMethodField(read_only=True)
|
termination = GFKSerializerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CableTermination
|
model = CableTermination
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'cable', 'cable_end', 'termination_type', 'termination_id',
|
'id', 'url', 'display', 'cable', 'cable_end', 'termination_type', 'termination_id',
|
||||||
'termination', 'created', 'last_updated',
|
'termination', 'position', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
|
read_only_fields = fields
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
brief_fields = (
|
||||||
def get_termination(self, obj):
|
'id', 'url', 'display', 'cable', 'cable_end', 'position', 'termination_type', 'termination_id',
|
||||||
serializer = get_serializer_for_model(obj.termination)
|
)
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.termination, nested=True, context=context).data
|
|
||||||
|
|
||||||
|
|
||||||
class CablePathSerializer(serializers.ModelSerializer):
|
class CablePathSerializer(serializers.ModelSerializer):
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from drf_spectacular.utils import extend_schema_field
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
@@ -13,8 +12,8 @@ from ipam.api.serializers_.vlans import VLANSerializer, VLANTranslationPolicySer
|
|||||||
from ipam.api.serializers_.vrfs import VRFSerializer
|
from ipam.api.serializers_.vrfs import VRFSerializer
|
||||||
from ipam.models import VLAN
|
from ipam.models import VLAN
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
from netbox.api.fields import ChoiceField, ContentTypeField, SerializedPKRelatedField
|
||||||
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
|
from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
|
||||||
from vpn.api.serializers_.l2vpn import L2VPNTerminationSerializer
|
from vpn.api.serializers_.l2vpn import L2VPNTerminationSerializer
|
||||||
from wireless.api.serializers_.nested import NestedWirelessLinkSerializer
|
from wireless.api.serializers_.nested import NestedWirelessLinkSerializer
|
||||||
from wireless.api.serializers_.wirelesslans import WirelessLANSerializer
|
from wireless.api.serializers_.wirelesslans import WirelessLANSerializer
|
||||||
@@ -394,7 +393,7 @@ class InventoryItemSerializer(NetBoxModelSerializer):
|
|||||||
required=False,
|
required=False,
|
||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
component = serializers.SerializerMethodField(read_only=True, allow_null=True)
|
component = GFKSerializerField(read_only=True)
|
||||||
_depth = serializers.IntegerField(source='level', read_only=True)
|
_depth = serializers.IntegerField(source='level', read_only=True)
|
||||||
status = ChoiceField(choices=InventoryItemStatusChoices, required=False)
|
status = ChoiceField(choices=InventoryItemStatusChoices, required=False)
|
||||||
|
|
||||||
@@ -406,11 +405,3 @@ class InventoryItemSerializer(NetBoxModelSerializer):
|
|||||||
'component_id', 'component', 'tags', 'custom_fields', 'created', 'last_updated', '_depth',
|
'component_id', 'component', 'tags', 'custom_fields', 'created', 'last_updated', '_depth',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', '_depth')
|
brief_fields = ('id', 'url', 'display', 'device', 'name', 'description', '_depth')
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_component(self, obj):
|
|
||||||
if obj.component is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.component)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.component, nested=True, context=context).data
|
|
||||||
|
|||||||
@@ -11,15 +11,15 @@ from dcim.models import Device, DeviceBay, MACAddress, Module, VirtualDeviceCont
|
|||||||
from extras.api.serializers_.configtemplates import ConfigTemplateSerializer
|
from extras.api.serializers_.configtemplates import ConfigTemplateSerializer
|
||||||
from ipam.api.serializers_.ip import IPAddressSerializer
|
from ipam.api.serializers_.ip import IPAddressSerializer
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
from netbox.api.fields import ChoiceField, ContentTypeField, RelatedObjectCountField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
|
from netbox.api.serializers import PrimaryModelSerializer
|
||||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
|
||||||
from virtualization.api.serializers_.clusters import ClusterSerializer
|
from virtualization.api.serializers_.clusters import ClusterSerializer
|
||||||
from .devicetypes import *
|
from .devicetypes import *
|
||||||
|
from .nested import NestedDeviceBaySerializer, NestedDeviceSerializer, NestedModuleBaySerializer
|
||||||
from .platforms import PlatformSerializer
|
from .platforms import PlatformSerializer
|
||||||
from .racks import RackSerializer
|
from .racks import RackSerializer
|
||||||
from .roles import DeviceRoleSerializer
|
from .roles import DeviceRoleSerializer
|
||||||
from .nested import NestedDeviceBaySerializer, NestedDeviceSerializer, NestedModuleBaySerializer
|
|
||||||
from .sites import LocationSerializer, SiteSerializer
|
from .sites import LocationSerializer, SiteSerializer
|
||||||
from .virtualchassis import VirtualChassisSerializer
|
from .virtualchassis import VirtualChassisSerializer
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DeviceSerializer(NetBoxModelSerializer):
|
class DeviceSerializer(PrimaryModelSerializer):
|
||||||
device_type = DeviceTypeSerializer(nested=True)
|
device_type = DeviceTypeSerializer(nested=True)
|
||||||
role = DeviceRoleSerializer(nested=True)
|
role = DeviceRoleSerializer(nested=True)
|
||||||
tenant = TenantSerializer(
|
tenant = TenantSerializer(
|
||||||
@@ -84,8 +84,8 @@ class DeviceSerializer(NetBoxModelSerializer):
|
|||||||
'id', 'url', 'display_url', 'display', 'name', 'device_type', 'role', 'tenant', 'platform', 'serial',
|
'id', 'url', 'display_url', 'display', 'name', 'device_type', 'role', 'tenant', 'platform', 'serial',
|
||||||
'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'latitude', 'longitude', 'parent_device',
|
'asset_tag', 'site', 'location', 'rack', 'position', 'face', 'latitude', 'longitude', 'parent_device',
|
||||||
'status', 'airflow', 'primary_ip', 'primary_ip4', 'primary_ip6', 'oob_ip', 'cluster', 'virtual_chassis',
|
'status', 'airflow', 'primary_ip', 'primary_ip4', 'primary_ip6', 'oob_ip', 'cluster', 'virtual_chassis',
|
||||||
'vc_position', 'vc_priority', 'description', 'comments', 'config_template', 'local_context_data', 'tags',
|
'vc_position', 'vc_priority', 'description', 'owner', 'comments', 'config_template', 'local_context_data',
|
||||||
'custom_fields', 'created', 'last_updated', 'console_port_count', 'console_server_port_count',
|
'tags', 'custom_fields', 'created', 'last_updated', 'console_port_count', 'console_server_port_count',
|
||||||
'power_port_count', 'power_outlet_count', 'interface_count', 'front_port_count', 'rear_port_count',
|
'power_port_count', 'power_outlet_count', 'interface_count', 'front_port_count', 'rear_port_count',
|
||||||
'device_bay_count', 'module_bay_count', 'inventory_item_count',
|
'device_bay_count', 'module_bay_count', 'inventory_item_count',
|
||||||
]
|
]
|
||||||
@@ -122,7 +122,7 @@ class DeviceWithConfigContextSerializer(DeviceSerializer):
|
|||||||
return obj.get_config_context()
|
return obj.get_config_context()
|
||||||
|
|
||||||
|
|
||||||
class VirtualDeviceContextSerializer(NetBoxModelSerializer):
|
class VirtualDeviceContextSerializer(PrimaryModelSerializer):
|
||||||
device = DeviceSerializer(nested=True)
|
device = DeviceSerializer(nested=True)
|
||||||
identifier = serializers.IntegerField(allow_null=True, max_value=32767, min_value=0, required=False, default=None)
|
identifier = serializers.IntegerField(allow_null=True, max_value=32767, min_value=0, required=False, default=None)
|
||||||
tenant = TenantSerializer(nested=True, required=False, allow_null=True, default=None)
|
tenant = TenantSerializer(nested=True, required=False, allow_null=True, default=None)
|
||||||
@@ -138,13 +138,13 @@ class VirtualDeviceContextSerializer(NetBoxModelSerializer):
|
|||||||
model = VirtualDeviceContext
|
model = VirtualDeviceContext
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'device', 'identifier', 'tenant', 'primary_ip',
|
'id', 'url', 'display_url', 'display', 'name', 'device', 'identifier', 'tenant', 'primary_ip',
|
||||||
'primary_ip4', 'primary_ip6', 'status', 'description', 'comments', 'tags', 'custom_fields',
|
'primary_ip4', 'primary_ip6', 'status', 'description', 'owner', 'comments', 'tags', 'custom_fields',
|
||||||
'created', 'last_updated', 'interface_count',
|
'created', 'last_updated', 'interface_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'identifier', 'device', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'identifier', 'device', 'description')
|
||||||
|
|
||||||
|
|
||||||
class ModuleSerializer(NetBoxModelSerializer):
|
class ModuleSerializer(PrimaryModelSerializer):
|
||||||
device = DeviceSerializer(nested=True)
|
device = DeviceSerializer(nested=True)
|
||||||
module_bay = NestedModuleBaySerializer()
|
module_bay = NestedModuleBaySerializer()
|
||||||
module_type = ModuleTypeSerializer(nested=True)
|
module_type = ModuleTypeSerializer(nested=True)
|
||||||
@@ -154,31 +154,23 @@ class ModuleSerializer(NetBoxModelSerializer):
|
|||||||
model = Module
|
model = Module
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'device', 'module_bay', 'module_type', 'status', 'serial',
|
'id', 'url', 'display_url', 'display', 'device', 'module_bay', 'module_type', 'status', 'serial',
|
||||||
'asset_tag', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
'asset_tag', 'description', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'device', 'module_bay', 'module_type', 'description')
|
brief_fields = ('id', 'url', 'display', 'device', 'module_bay', 'module_type', 'description')
|
||||||
|
|
||||||
|
|
||||||
class MACAddressSerializer(NetBoxModelSerializer):
|
class MACAddressSerializer(PrimaryModelSerializer):
|
||||||
assigned_object_type = ContentTypeField(
|
assigned_object_type = ContentTypeField(
|
||||||
queryset=ContentType.objects.filter(MACADDRESS_ASSIGNMENT_MODELS),
|
queryset=ContentType.objects.filter(MACADDRESS_ASSIGNMENT_MODELS),
|
||||||
required=False,
|
required=False,
|
||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
assigned_object = serializers.SerializerMethodField(read_only=True)
|
assigned_object = GFKSerializerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MACAddress
|
model = MACAddress
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'mac_address', 'assigned_object_type', 'assigned_object_id',
|
'id', 'url', 'display_url', 'display', 'mac_address', 'assigned_object_type', 'assigned_object_id',
|
||||||
'assigned_object', 'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
'assigned_object', 'description', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'mac_address', 'description')
|
brief_fields = ('id', 'url', 'display', 'mac_address', 'description')
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_assigned_object(self, obj):
|
|
||||||
if obj.assigned_object is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.assigned_object)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.assigned_object, nested=True, context=context).data
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from drf_spectacular.utils import extend_schema_field
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
@@ -9,8 +8,8 @@ from dcim.models import (
|
|||||||
InventoryItemTemplate, ModuleBayTemplate, PowerOutletTemplate, PowerPortTemplate, RearPortTemplate,
|
InventoryItemTemplate, ModuleBayTemplate, PowerOutletTemplate, PowerPortTemplate, RearPortTemplate,
|
||||||
)
|
)
|
||||||
from netbox.api.fields import ChoiceField, ContentTypeField
|
from netbox.api.fields import ChoiceField, ContentTypeField
|
||||||
|
from netbox.api.gfk_fields import GFKSerializerField
|
||||||
from netbox.api.serializers import ChangeLogMessageSerializer, ValidatedModelSerializer
|
from netbox.api.serializers import ChangeLogMessageSerializer, ValidatedModelSerializer
|
||||||
from utilities.api import get_serializer_for_model
|
|
||||||
from wireless.choices import *
|
from wireless.choices import *
|
||||||
from .devicetypes import DeviceTypeSerializer, ModuleTypeSerializer
|
from .devicetypes import DeviceTypeSerializer, ModuleTypeSerializer
|
||||||
from .manufacturers import ManufacturerSerializer
|
from .manufacturers import ManufacturerSerializer
|
||||||
@@ -155,7 +154,7 @@ class PowerOutletTemplateSerializer(ComponentTemplateSerializer):
|
|||||||
model = PowerOutletTemplate
|
model = PowerOutletTemplate
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type',
|
'id', 'url', 'display', 'device_type', 'module_type', 'name', 'label', 'type',
|
||||||
'power_port', 'feed_leg', 'description', 'created', 'last_updated',
|
'color', 'power_port', 'feed_leg', 'description', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||||
|
|
||||||
@@ -313,7 +312,7 @@ class InventoryItemTemplateSerializer(ComponentTemplateSerializer):
|
|||||||
required=False,
|
required=False,
|
||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
component = serializers.SerializerMethodField(read_only=True, allow_null=True)
|
component = GFKSerializerField(read_only=True)
|
||||||
_depth = serializers.IntegerField(source='level', read_only=True)
|
_depth = serializers.IntegerField(source='level', read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@@ -324,11 +323,3 @@ class InventoryItemTemplateSerializer(ComponentTemplateSerializer):
|
|||||||
'_depth',
|
'_depth',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description', '_depth')
|
brief_fields = ('id', 'url', 'display', 'name', 'description', '_depth')
|
||||||
|
|
||||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
|
||||||
def get_component(self, obj):
|
|
||||||
if obj.component is None:
|
|
||||||
return None
|
|
||||||
serializer = get_serializer_for_model(obj.component)
|
|
||||||
context = {'request': self.context['request']}
|
|
||||||
return serializer(obj.component, nested=True, context=context).data
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ from rest_framework import serializers
|
|||||||
|
|
||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.models import DeviceType, ModuleType, ModuleTypeProfile
|
from dcim.models import DeviceType, ModuleType, ModuleTypeProfile
|
||||||
from netbox.api.fields import AttributesField, ChoiceField, RelatedObjectCountField
|
from netbox.api.fields import AttributesField, ChoiceField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import PrimaryModelSerializer
|
||||||
from netbox.choices import *
|
from netbox.choices import *
|
||||||
from .manufacturers import ManufacturerSerializer
|
from .manufacturers import ManufacturerSerializer
|
||||||
from .platforms import PlatformSerializer
|
from .platforms import PlatformSerializer
|
||||||
@@ -18,7 +18,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DeviceTypeSerializer(NetBoxModelSerializer):
|
class DeviceTypeSerializer(PrimaryModelSerializer):
|
||||||
manufacturer = ManufacturerSerializer(nested=True)
|
manufacturer = ManufacturerSerializer(nested=True)
|
||||||
default_platform = PlatformSerializer(nested=True, required=False, allow_null=True)
|
default_platform = PlatformSerializer(nested=True, required=False, allow_null=True)
|
||||||
u_height = serializers.DecimalField(
|
u_height = serializers.DecimalField(
|
||||||
@@ -45,16 +45,14 @@ class DeviceTypeSerializer(NetBoxModelSerializer):
|
|||||||
device_bay_template_count = serializers.IntegerField(read_only=True)
|
device_bay_template_count = serializers.IntegerField(read_only=True)
|
||||||
module_bay_template_count = serializers.IntegerField(read_only=True)
|
module_bay_template_count = serializers.IntegerField(read_only=True)
|
||||||
inventory_item_template_count = serializers.IntegerField(read_only=True)
|
inventory_item_template_count = serializers.IntegerField(read_only=True)
|
||||||
|
device_count = serializers.IntegerField(read_only=True)
|
||||||
# Related object counts
|
|
||||||
device_count = RelatedObjectCountField('instances')
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DeviceType
|
model = DeviceType
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'manufacturer', 'default_platform', 'model', 'slug', 'part_number',
|
'id', 'url', 'display_url', 'display', 'manufacturer', 'default_platform', 'model', 'slug', 'part_number',
|
||||||
'u_height', 'exclude_from_utilization', 'is_full_depth', 'subdevice_role', 'airflow', 'weight',
|
'u_height', 'exclude_from_utilization', 'is_full_depth', 'subdevice_role', 'airflow', 'weight',
|
||||||
'weight_unit', 'front_image', 'rear_image', 'description', 'comments', 'tags', 'custom_fields',
|
'weight_unit', 'front_image', 'rear_image', 'description', 'owner', 'comments', 'tags', 'custom_fields',
|
||||||
'created', 'last_updated', 'device_count', 'console_port_template_count',
|
'created', 'last_updated', 'device_count', 'console_port_template_count',
|
||||||
'console_server_port_template_count', 'power_port_template_count', 'power_outlet_template_count',
|
'console_server_port_template_count', 'power_port_template_count', 'power_outlet_template_count',
|
||||||
'interface_template_count', 'front_port_template_count', 'rear_port_template_count',
|
'interface_template_count', 'front_port_template_count', 'rear_port_template_count',
|
||||||
@@ -63,18 +61,18 @@ class DeviceTypeSerializer(NetBoxModelSerializer):
|
|||||||
brief_fields = ('id', 'url', 'display', 'manufacturer', 'model', 'slug', 'description', 'device_count')
|
brief_fields = ('id', 'url', 'display', 'manufacturer', 'model', 'slug', 'description', 'device_count')
|
||||||
|
|
||||||
|
|
||||||
class ModuleTypeProfileSerializer(NetBoxModelSerializer):
|
class ModuleTypeProfileSerializer(PrimaryModelSerializer):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleTypeProfile
|
model = ModuleTypeProfile
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'description', 'schema', 'comments', 'tags', 'custom_fields',
|
'id', 'url', 'display_url', 'display', 'name', 'description', 'schema', 'owner', 'comments', 'tags',
|
||||||
'created', 'last_updated',
|
'custom_fields', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
brief_fields = ('id', 'url', 'display', 'name', 'description')
|
||||||
|
|
||||||
|
|
||||||
class ModuleTypeSerializer(NetBoxModelSerializer):
|
class ModuleTypeSerializer(PrimaryModelSerializer):
|
||||||
profile = ModuleTypeProfileSerializer(
|
profile = ModuleTypeProfileSerializer(
|
||||||
nested=True,
|
nested=True,
|
||||||
required=False,
|
required=False,
|
||||||
@@ -100,12 +98,13 @@ class ModuleTypeSerializer(NetBoxModelSerializer):
|
|||||||
required=False,
|
required=False,
|
||||||
allow_null=True
|
allow_null=True
|
||||||
)
|
)
|
||||||
|
module_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleType
|
model = ModuleType
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'profile', 'manufacturer', 'model', 'part_number', 'airflow',
|
'id', 'url', 'display_url', 'display', 'profile', 'manufacturer', 'model', 'part_number', 'airflow',
|
||||||
'weight', 'weight_unit', 'description', 'attributes', 'comments', 'tags', 'custom_fields', 'created',
|
'weight', 'weight_unit', 'description', 'attributes', 'owner', 'comments', 'tags', 'custom_fields',
|
||||||
'last_updated',
|
'created', 'last_updated', 'module_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'profile', 'manufacturer', 'model', 'description')
|
brief_fields = ('id', 'url', 'display', 'profile', 'manufacturer', 'model', 'description', 'module_count')
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
from dcim.models import Manufacturer
|
from dcim.models import Manufacturer
|
||||||
from netbox.api.fields import RelatedObjectCountField
|
from netbox.api.fields import RelatedObjectCountField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import OrganizationalModelSerializer
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ManufacturerSerializer',
|
'ManufacturerSerializer',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ManufacturerSerializer(NetBoxModelSerializer):
|
class ManufacturerSerializer(OrganizationalModelSerializer):
|
||||||
|
|
||||||
# Related object counts
|
# Related object counts
|
||||||
devicetype_count = RelatedObjectCountField('device_types')
|
devicetype_count = RelatedObjectCountField('device_types')
|
||||||
@@ -17,7 +17,7 @@ class ManufacturerSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = Manufacturer
|
model = Manufacturer
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'tags', 'custom_fields',
|
'id', 'url', 'display_url', 'display', 'name', 'slug', 'description', 'owner', 'tags', 'custom_fields',
|
||||||
'created', 'last_updated', 'devicetype_count', 'inventoryitem_count', 'platform_count',
|
'created', 'last_updated', 'devicetype_count', 'inventoryitem_count', 'platform_count',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'devicetype_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'slug', 'description', 'devicetype_count')
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class PlatformSerializer(NestedGroupModelSerializer):
|
|||||||
model = Platform
|
model = Platform
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'parent', 'name', 'slug', 'manufacturer', 'config_template',
|
'id', 'url', 'display_url', 'display', 'parent', 'name', 'slug', 'manufacturer', 'config_template',
|
||||||
'description', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count',
|
'description', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'device_count',
|
||||||
'virtualmachine_count', '_depth',
|
'virtualmachine_count', '_depth',
|
||||||
]
|
]
|
||||||
brief_fields = (
|
brief_fields = (
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from dcim.choices import *
|
from dcim.choices import *
|
||||||
from dcim.models import PowerFeed, PowerPanel
|
from dcim.models import PowerFeed, PowerPanel
|
||||||
from netbox.api.fields import ChoiceField, RelatedObjectCountField
|
from netbox.api.fields import ChoiceField, RelatedObjectCountField
|
||||||
from netbox.api.serializers import NetBoxModelSerializer
|
from netbox.api.serializers import PrimaryModelSerializer
|
||||||
from tenancy.api.serializers_.tenants import TenantSerializer
|
from tenancy.api.serializers_.tenants import TenantSerializer
|
||||||
from .base import ConnectedEndpointsSerializer
|
from .base import ConnectedEndpointsSerializer
|
||||||
from .cables import CabledObjectSerializer
|
from .cables import CabledObjectSerializer
|
||||||
@@ -14,7 +14,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class PowerPanelSerializer(NetBoxModelSerializer):
|
class PowerPanelSerializer(PrimaryModelSerializer):
|
||||||
site = SiteSerializer(nested=True)
|
site = SiteSerializer(nested=True)
|
||||||
location = LocationSerializer(
|
location = LocationSerializer(
|
||||||
nested=True,
|
nested=True,
|
||||||
@@ -29,13 +29,13 @@ class PowerPanelSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = PowerPanel
|
model = PowerPanel
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display_url', 'display', 'site', 'location', 'name', 'description', 'comments', 'tags',
|
'id', 'url', 'display_url', 'display', 'site', 'location', 'name', 'description', 'owner', 'comments',
|
||||||
'custom_fields', 'powerfeed_count', 'created', 'last_updated',
|
'tags', 'custom_fields', 'powerfeed_count', 'created', 'last_updated',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description', 'powerfeed_count')
|
brief_fields = ('id', 'url', 'display', 'name', 'description', 'powerfeed_count')
|
||||||
|
|
||||||
|
|
||||||
class PowerFeedSerializer(NetBoxModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
|
class PowerFeedSerializer(PrimaryModelSerializer, CabledObjectSerializer, ConnectedEndpointsSerializer):
|
||||||
power_panel = PowerPanelSerializer(nested=True)
|
power_panel = PowerPanelSerializer(nested=True)
|
||||||
rack = RackSerializer(
|
rack = RackSerializer(
|
||||||
nested=True,
|
nested=True,
|
||||||
@@ -71,6 +71,7 @@ class PowerFeedSerializer(NetBoxModelSerializer, CabledObjectSerializer, Connect
|
|||||||
'id', 'url', 'display_url', 'display', 'power_panel', 'rack', 'name', 'status', 'type', 'supply',
|
'id', 'url', 'display_url', 'display', 'power_panel', 'rack', 'name', 'status', 'type', 'supply',
|
||||||
'phase', 'voltage', 'amperage', 'max_utilization', 'mark_connected', 'cable', 'cable_end', 'link_peers',
|
'phase', 'voltage', 'amperage', 'max_utilization', 'mark_connected', 'cable', 'cable_end', 'link_peers',
|
||||||
'link_peers_type', 'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable',
|
'link_peers_type', 'connected_endpoints', 'connected_endpoints_type', 'connected_endpoints_reachable',
|
||||||
'description', 'tenant', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', '_occupied',
|
'description', 'tenant', 'owner', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||||
|
'_occupied',
|
||||||
]
|
]
|
||||||
brief_fields = ('id', 'url', 'display', 'name', 'description', 'cable', '_occupied')
|
brief_fields = ('id', 'url', 'display', 'name', 'description', 'cable', '_occupied')
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user