netbox-data-import 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netbox_data_import-1.0.1/LICENSE +201 -0
- netbox_data_import-1.0.1/PKG-INFO +61 -0
- netbox_data_import-1.0.1/README.md +46 -0
- netbox_data_import-1.0.1/netbox_data_import/__init__.py +54 -0
- netbox_data_import-1.0.1/netbox_data_import/api/__init__.py +2 -0
- netbox_data_import-1.0.1/netbox_data_import/api/serializers.py +131 -0
- netbox_data_import-1.0.1/netbox_data_import/api/urls.py +29 -0
- netbox_data_import-1.0.1/netbox_data_import/api/views.py +151 -0
- netbox_data_import-1.0.1/netbox_data_import/engine.py +1023 -0
- netbox_data_import-1.0.1/netbox_data_import/filters.py +19 -0
- netbox_data_import-1.0.1/netbox_data_import/forms.py +98 -0
- netbox_data_import-1.0.1/netbox_data_import/jobs.py +2 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0001_initial.py +151 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0002_importjob.py +40 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0003_remove_classrolemapping_unique_class_role_mapping_per_profile_and_more.py +42 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0004_features.py +183 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0005_deviceexistingmatch.py +36 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0006_deviceexistingmatch_asset_tag.py +17 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/0007_manufacturermapping.py +43 -0
- netbox_data_import-1.0.1/netbox_data_import/migrations/__init__.py +0 -0
- netbox_data_import-1.0.1/netbox_data_import/models.py +398 -0
- netbox_data_import-1.0.1/netbox_data_import/navigation.py +50 -0
- netbox_data_import-1.0.1/netbox_data_import/signals.py +2 -0
- netbox_data_import-1.0.1/netbox_data_import/tables.py +154 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/__init__.py +2 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/test_api.py +361 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/test_engine.py +437 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/test_engine_extended.py +1814 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/test_models.py +154 -0
- netbox_data_import-1.0.1/netbox_data_import/tests/test_views.py +2133 -0
- netbox_data_import-1.0.1/netbox_data_import/urls.py +100 -0
- netbox_data_import-1.0.1/netbox_data_import/utils.py +2 -0
- netbox_data_import-1.0.1/netbox_data_import/views.py +1474 -0
- netbox_data_import-1.0.1/netbox_data_import.egg-info/PKG-INFO +61 -0
- netbox_data_import-1.0.1/netbox_data_import.egg-info/SOURCES.txt +38 -0
- netbox_data_import-1.0.1/netbox_data_import.egg-info/dependency_links.txt +1 -0
- netbox_data_import-1.0.1/netbox_data_import.egg-info/requires.txt +1 -0
- netbox_data_import-1.0.1/netbox_data_import.egg-info/top_level.txt +1 -0
- netbox_data_import-1.0.1/pyproject.toml +98 -0
- netbox_data_import-1.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. Please also get an in-depth
|
|
186
|
+
understanding of the Apache License by reading the FAQ at
|
|
187
|
+
<http://www.apache.org/foundation/license-faq.html>
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Marcin Zieba
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netbox-data-import
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: NetBox plugin for importing data from external DCIM systems
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
9
|
+
Classifier: Framework :: Django
|
|
10
|
+
Requires-Python: >=3.12.0
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: openpyxl>=3.1
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
<!--
|
|
17
|
+
SPDX-License-Identifier: Apache-2.0
|
|
18
|
+
Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
19
|
+
-->
|
|
20
|
+
# NetBox Data Import Plugin
|
|
21
|
+
|
|
22
|
+
[](https://github.com/marcinpsk/netbox-data-import-plugin/actions/workflows/test.yaml)
|
|
23
|
+
[](https://marcinpsk.github.io/netbox-data-import-plugin/coverage/)
|
|
24
|
+
[](LICENSE)
|
|
25
|
+
[](https://www.python.org/)
|
|
26
|
+
[](https://github.com/netbox-community/netbox)
|
|
27
|
+
|
|
28
|
+
A NetBox plugin for importing device inventory and rack layouts from external DCIM systems via configurable field mappings.
|
|
29
|
+
|
|
30
|
+
## Overview
|
|
31
|
+
|
|
32
|
+
This plugin allows you to:
|
|
33
|
+
|
|
34
|
+
- Define **import profiles** that configure how your source data (Excel/CSV) maps to NetBox objects
|
|
35
|
+
- Configure **field mappings** per column with transformation rules
|
|
36
|
+
- Define **class/role mappings** to translate your source system's device categories to NetBox roles
|
|
37
|
+
- **Preview** the import before applying changes
|
|
38
|
+
- **Run imports** and track results per object
|
|
39
|
+
|
|
40
|
+
Currently supports importing from Excel (`.xlsx`) files in the CANS format, with the mapping configuration stored in NetBox so it can be reused and adapted for other source formats.
|
|
41
|
+
|
|
42
|
+
## Requirements
|
|
43
|
+
|
|
44
|
+
- NetBox ≥ 4.2.0
|
|
45
|
+
- Python ≥ 3.12
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install netbox-data-import
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Add to `PLUGINS` in your NetBox configuration:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
PLUGINS = ["netbox_data_import"]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
4
|
+
-->
|
|
5
|
+
# NetBox Data Import Plugin
|
|
6
|
+
|
|
7
|
+
[](https://github.com/marcinpsk/netbox-data-import-plugin/actions/workflows/test.yaml)
|
|
8
|
+
[](https://marcinpsk.github.io/netbox-data-import-plugin/coverage/)
|
|
9
|
+
[](LICENSE)
|
|
10
|
+
[](https://www.python.org/)
|
|
11
|
+
[](https://github.com/netbox-community/netbox)
|
|
12
|
+
|
|
13
|
+
A NetBox plugin for importing device inventory and rack layouts from external DCIM systems via configurable field mappings.
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
This plugin allows you to:
|
|
18
|
+
|
|
19
|
+
- Define **import profiles** that configure how your source data (Excel/CSV) maps to NetBox objects
|
|
20
|
+
- Configure **field mappings** per column with transformation rules
|
|
21
|
+
- Define **class/role mappings** to translate your source system's device categories to NetBox roles
|
|
22
|
+
- **Preview** the import before applying changes
|
|
23
|
+
- **Run imports** and track results per object
|
|
24
|
+
|
|
25
|
+
Currently supports importing from Excel (`.xlsx`) files in the CANS format, with the mapping configuration stored in NetBox so it can be reused and adapted for other source formats.
|
|
26
|
+
|
|
27
|
+
## Requirements
|
|
28
|
+
|
|
29
|
+
- NetBox ≥ 4.2.0
|
|
30
|
+
- Python ≥ 3.12
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install netbox-data-import
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Add to `PLUGINS` in your NetBox configuration:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
PLUGINS = ["netbox_data_import"]
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
Apache-2.0 — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
3
|
+
from netbox.plugins import PluginConfig
|
|
4
|
+
|
|
5
|
+
__version__ = "1.0.1"
|
|
6
|
+
|
|
7
|
+
DATA_IMPORT_CF_NAME = "data_import_source"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _ensure_import_custom_fields(sender, **kwargs):
|
|
11
|
+
"""Auto-create the data_import_source JSON custom field on Device after migrations."""
|
|
12
|
+
try:
|
|
13
|
+
from extras.models import CustomField
|
|
14
|
+
from django.contrib.contenttypes.models import ContentType
|
|
15
|
+
from dcim.models import Device
|
|
16
|
+
|
|
17
|
+
device_ct = ContentType.objects.get_for_model(Device)
|
|
18
|
+
cf, created = CustomField.objects.get_or_create(
|
|
19
|
+
name=DATA_IMPORT_CF_NAME,
|
|
20
|
+
defaults={
|
|
21
|
+
"type": "json",
|
|
22
|
+
"label": "Data Import Source",
|
|
23
|
+
"description": ("Metadata set by the Data Import plugin: source_id, profile_id, profile_name."),
|
|
24
|
+
"required": False,
|
|
25
|
+
"weight": 9999,
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
if created:
|
|
29
|
+
cf.object_types.set([device_ct])
|
|
30
|
+
except Exception:
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class NetBoxDataImportConfig(PluginConfig):
|
|
35
|
+
"""NetBox plugin configuration for the Data Import plugin."""
|
|
36
|
+
|
|
37
|
+
name = "netbox_data_import"
|
|
38
|
+
verbose_name = "NetBox Data Import"
|
|
39
|
+
description = "NetBox plugin for importing data from external DCIM systems"
|
|
40
|
+
version = __version__
|
|
41
|
+
base_url = "data-import"
|
|
42
|
+
author = "Marcin Zieba"
|
|
43
|
+
author_email = "marcinpsk@gmail.com"
|
|
44
|
+
min_version = "4.2.0"
|
|
45
|
+
|
|
46
|
+
def ready(self):
|
|
47
|
+
"""Register post_migrate signal to auto-create the data_import_source custom field."""
|
|
48
|
+
super().ready()
|
|
49
|
+
from django.db.models.signals import post_migrate
|
|
50
|
+
|
|
51
|
+
post_migrate.connect(_ensure_import_custom_fields, sender=self)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
config = NetBoxDataImportConfig
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
3
|
+
"""DRF serializers for the data-import plugin models."""
|
|
4
|
+
|
|
5
|
+
from netbox.api.serializers import NetBoxModelSerializer
|
|
6
|
+
from rest_framework import serializers
|
|
7
|
+
|
|
8
|
+
from ..models import (
|
|
9
|
+
ImportProfile,
|
|
10
|
+
ColumnMapping,
|
|
11
|
+
ClassRoleMapping,
|
|
12
|
+
DeviceTypeMapping,
|
|
13
|
+
IgnoredDevice,
|
|
14
|
+
ColumnTransformRule,
|
|
15
|
+
SourceResolution,
|
|
16
|
+
ImportJob,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ImportProfileSerializer(NetBoxModelSerializer):
|
|
21
|
+
"""Full serializer for ImportProfile (NetBoxModel)."""
|
|
22
|
+
|
|
23
|
+
url = serializers.HyperlinkedIdentityField(
|
|
24
|
+
view_name="plugins-api:netbox_data_import-api:importprofile-detail",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
class Meta:
|
|
28
|
+
model = ImportProfile
|
|
29
|
+
fields = [
|
|
30
|
+
"id",
|
|
31
|
+
"url",
|
|
32
|
+
"display",
|
|
33
|
+
"name",
|
|
34
|
+
"description",
|
|
35
|
+
"sheet_name",
|
|
36
|
+
"source_id_column",
|
|
37
|
+
"custom_field_name",
|
|
38
|
+
"update_existing",
|
|
39
|
+
"create_missing_device_types",
|
|
40
|
+
"preview_view_mode",
|
|
41
|
+
"tags",
|
|
42
|
+
"custom_fields",
|
|
43
|
+
"created",
|
|
44
|
+
"last_updated",
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ColumnMappingSerializer(serializers.ModelSerializer):
|
|
49
|
+
"""Serializer for ColumnMapping (plain model)."""
|
|
50
|
+
|
|
51
|
+
class Meta:
|
|
52
|
+
model = ColumnMapping
|
|
53
|
+
fields = ["id", "profile", "source_column", "target_field"]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ClassRoleMappingSerializer(serializers.ModelSerializer):
|
|
57
|
+
"""Serializer for ClassRoleMapping (plain model)."""
|
|
58
|
+
|
|
59
|
+
class Meta:
|
|
60
|
+
model = ClassRoleMapping
|
|
61
|
+
fields = ["id", "profile", "source_class", "creates_rack", "role_slug", "ignore"]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DeviceTypeMappingSerializer(serializers.ModelSerializer):
|
|
65
|
+
"""Serializer for DeviceTypeMapping (plain model)."""
|
|
66
|
+
|
|
67
|
+
class Meta:
|
|
68
|
+
model = DeviceTypeMapping
|
|
69
|
+
fields = [
|
|
70
|
+
"id",
|
|
71
|
+
"profile",
|
|
72
|
+
"source_make",
|
|
73
|
+
"source_model",
|
|
74
|
+
"netbox_manufacturer_slug",
|
|
75
|
+
"netbox_device_type_slug",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class IgnoredDeviceSerializer(serializers.ModelSerializer):
|
|
80
|
+
"""Serializer for IgnoredDevice (plain model)."""
|
|
81
|
+
|
|
82
|
+
class Meta:
|
|
83
|
+
model = IgnoredDevice
|
|
84
|
+
fields = ["id", "profile", "source_id", "device_name"]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class ColumnTransformRuleSerializer(serializers.ModelSerializer):
|
|
88
|
+
"""Serializer for ColumnTransformRule (plain model)."""
|
|
89
|
+
|
|
90
|
+
class Meta:
|
|
91
|
+
model = ColumnTransformRule
|
|
92
|
+
fields = [
|
|
93
|
+
"id",
|
|
94
|
+
"profile",
|
|
95
|
+
"source_column",
|
|
96
|
+
"pattern",
|
|
97
|
+
"group_1_target",
|
|
98
|
+
"group_2_target",
|
|
99
|
+
]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class SourceResolutionSerializer(serializers.ModelSerializer):
|
|
103
|
+
"""Serializer for SourceResolution (rerere, plain model)."""
|
|
104
|
+
|
|
105
|
+
class Meta:
|
|
106
|
+
model = SourceResolution
|
|
107
|
+
fields = [
|
|
108
|
+
"id",
|
|
109
|
+
"profile",
|
|
110
|
+
"source_id",
|
|
111
|
+
"source_column",
|
|
112
|
+
"original_value",
|
|
113
|
+
"resolved_fields",
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class ImportJobSerializer(serializers.ModelSerializer):
|
|
118
|
+
"""Read-only serializer for ImportJob (plain model)."""
|
|
119
|
+
|
|
120
|
+
class Meta:
|
|
121
|
+
model = ImportJob
|
|
122
|
+
fields = [
|
|
123
|
+
"id",
|
|
124
|
+
"profile",
|
|
125
|
+
"created",
|
|
126
|
+
"input_filename",
|
|
127
|
+
"dry_run",
|
|
128
|
+
"site_name",
|
|
129
|
+
"result_counts",
|
|
130
|
+
]
|
|
131
|
+
read_only_fields = fields
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
3
|
+
"""URL router for the data-import plugin API."""
|
|
4
|
+
|
|
5
|
+
from netbox.api.routers import NetBoxRouter
|
|
6
|
+
|
|
7
|
+
from .views import (
|
|
8
|
+
ImportProfileViewSet,
|
|
9
|
+
ColumnMappingViewSet,
|
|
10
|
+
ClassRoleMappingViewSet,
|
|
11
|
+
DeviceTypeMappingViewSet,
|
|
12
|
+
IgnoredDeviceViewSet,
|
|
13
|
+
ColumnTransformRuleViewSet,
|
|
14
|
+
SourceResolutionViewSet,
|
|
15
|
+
ImportJobViewSet,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
router = NetBoxRouter()
|
|
19
|
+
router.register("profiles", ImportProfileViewSet)
|
|
20
|
+
router.register("column-mappings", ColumnMappingViewSet)
|
|
21
|
+
router.register("class-role-mappings", ClassRoleMappingViewSet)
|
|
22
|
+
router.register("device-type-mappings", DeviceTypeMappingViewSet)
|
|
23
|
+
router.register("ignored-devices", IgnoredDeviceViewSet)
|
|
24
|
+
router.register("column-transforms", ColumnTransformRuleViewSet)
|
|
25
|
+
router.register("source-resolutions", SourceResolutionViewSet)
|
|
26
|
+
router.register("jobs", ImportJobViewSet)
|
|
27
|
+
|
|
28
|
+
app_name = "netbox_data_import"
|
|
29
|
+
urlpatterns = router.urls
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# Copyright (C) 2025 Marcin Zieba <marcinpsk@gmail.com>
|
|
3
|
+
"""DRF viewsets for the data-import plugin API."""
|
|
4
|
+
|
|
5
|
+
from netbox.api.viewsets import NetBoxModelViewSet
|
|
6
|
+
from rest_framework import viewsets, permissions
|
|
7
|
+
|
|
8
|
+
from ..models import (
|
|
9
|
+
ImportProfile,
|
|
10
|
+
ColumnMapping,
|
|
11
|
+
ClassRoleMapping,
|
|
12
|
+
DeviceTypeMapping,
|
|
13
|
+
IgnoredDevice,
|
|
14
|
+
ColumnTransformRule,
|
|
15
|
+
SourceResolution,
|
|
16
|
+
ImportJob,
|
|
17
|
+
)
|
|
18
|
+
from .serializers import (
|
|
19
|
+
ImportProfileSerializer,
|
|
20
|
+
ColumnMappingSerializer,
|
|
21
|
+
ClassRoleMappingSerializer,
|
|
22
|
+
DeviceTypeMappingSerializer,
|
|
23
|
+
IgnoredDeviceSerializer,
|
|
24
|
+
ColumnTransformRuleSerializer,
|
|
25
|
+
SourceResolutionSerializer,
|
|
26
|
+
ImportJobSerializer,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ImportProfileViewSet(NetBoxModelViewSet):
|
|
31
|
+
"""CRUD viewset for ImportProfile (NetBoxModel)."""
|
|
32
|
+
|
|
33
|
+
queryset = ImportProfile.objects.prefetch_related(
|
|
34
|
+
"tags",
|
|
35
|
+
"column_mappings",
|
|
36
|
+
"class_role_mappings",
|
|
37
|
+
"device_type_mappings",
|
|
38
|
+
)
|
|
39
|
+
serializer_class = ImportProfileSerializer
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class _PluginModelViewSet(viewsets.ModelViewSet):
|
|
43
|
+
"""Base class for plain-model viewsets in this plugin."""
|
|
44
|
+
|
|
45
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ColumnMappingViewSet(_PluginModelViewSet):
|
|
49
|
+
"""CRUD viewset for ColumnMapping."""
|
|
50
|
+
|
|
51
|
+
queryset = ColumnMapping.objects.select_related("profile")
|
|
52
|
+
serializer_class = ColumnMappingSerializer
|
|
53
|
+
|
|
54
|
+
def get_queryset(self):
|
|
55
|
+
"""Filter by profile_id query param if provided."""
|
|
56
|
+
qs = super().get_queryset()
|
|
57
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
58
|
+
if profile_id:
|
|
59
|
+
qs = qs.filter(profile_id=profile_id)
|
|
60
|
+
return qs
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class ClassRoleMappingViewSet(_PluginModelViewSet):
|
|
64
|
+
"""CRUD viewset for ClassRoleMapping."""
|
|
65
|
+
|
|
66
|
+
queryset = ClassRoleMapping.objects.select_related("profile")
|
|
67
|
+
serializer_class = ClassRoleMappingSerializer
|
|
68
|
+
|
|
69
|
+
def get_queryset(self):
|
|
70
|
+
"""Filter by profile_id query param if provided."""
|
|
71
|
+
qs = super().get_queryset()
|
|
72
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
73
|
+
if profile_id:
|
|
74
|
+
qs = qs.filter(profile_id=profile_id)
|
|
75
|
+
return qs
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class DeviceTypeMappingViewSet(_PluginModelViewSet):
|
|
79
|
+
"""CRUD viewset for DeviceTypeMapping."""
|
|
80
|
+
|
|
81
|
+
queryset = DeviceTypeMapping.objects.select_related("profile")
|
|
82
|
+
serializer_class = DeviceTypeMappingSerializer
|
|
83
|
+
|
|
84
|
+
def get_queryset(self):
|
|
85
|
+
"""Filter by profile_id query param if provided."""
|
|
86
|
+
qs = super().get_queryset()
|
|
87
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
88
|
+
if profile_id:
|
|
89
|
+
qs = qs.filter(profile_id=profile_id)
|
|
90
|
+
return qs
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class IgnoredDeviceViewSet(_PluginModelViewSet):
|
|
94
|
+
"""CRUD viewset for IgnoredDevice."""
|
|
95
|
+
|
|
96
|
+
queryset = IgnoredDevice.objects.select_related("profile")
|
|
97
|
+
serializer_class = IgnoredDeviceSerializer
|
|
98
|
+
|
|
99
|
+
def get_queryset(self):
|
|
100
|
+
"""Filter by profile_id query param if provided."""
|
|
101
|
+
qs = super().get_queryset()
|
|
102
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
103
|
+
if profile_id:
|
|
104
|
+
qs = qs.filter(profile_id=profile_id)
|
|
105
|
+
return qs
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class ColumnTransformRuleViewSet(_PluginModelViewSet):
|
|
109
|
+
"""CRUD viewset for ColumnTransformRule."""
|
|
110
|
+
|
|
111
|
+
queryset = ColumnTransformRule.objects.select_related("profile")
|
|
112
|
+
serializer_class = ColumnTransformRuleSerializer
|
|
113
|
+
|
|
114
|
+
def get_queryset(self):
|
|
115
|
+
"""Filter by profile_id query param if provided."""
|
|
116
|
+
qs = super().get_queryset()
|
|
117
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
118
|
+
if profile_id:
|
|
119
|
+
qs = qs.filter(profile_id=profile_id)
|
|
120
|
+
return qs
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class SourceResolutionViewSet(_PluginModelViewSet):
|
|
124
|
+
"""CRUD viewset for SourceResolution (rerere)."""
|
|
125
|
+
|
|
126
|
+
queryset = SourceResolution.objects.select_related("profile")
|
|
127
|
+
serializer_class = SourceResolutionSerializer
|
|
128
|
+
|
|
129
|
+
def get_queryset(self):
|
|
130
|
+
"""Filter by profile_id query param if provided."""
|
|
131
|
+
qs = super().get_queryset()
|
|
132
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
133
|
+
if profile_id:
|
|
134
|
+
qs = qs.filter(profile_id=profile_id)
|
|
135
|
+
return qs
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class ImportJobViewSet(viewsets.ReadOnlyModelViewSet):
|
|
139
|
+
"""Read-only viewset for ImportJob history."""
|
|
140
|
+
|
|
141
|
+
queryset = ImportJob.objects.select_related("profile")
|
|
142
|
+
serializer_class = ImportJobSerializer
|
|
143
|
+
permission_classes = [permissions.IsAuthenticated]
|
|
144
|
+
|
|
145
|
+
def get_queryset(self):
|
|
146
|
+
"""Filter by profile_id query param if provided."""
|
|
147
|
+
qs = super().get_queryset()
|
|
148
|
+
profile_id = self.request.query_params.get("profile_id")
|
|
149
|
+
if profile_id:
|
|
150
|
+
qs = qs.filter(profile_id=profile_id)
|
|
151
|
+
return qs
|