ipfabric_netbox 3.1.2__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.
Potentially problematic release.
This version of ipfabric_netbox might be problematic. Click here for more details.
- ipfabric_netbox-3.1.2/PKG-INFO +88 -0
- ipfabric_netbox-3.1.2/README.md +64 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/__init__.py +42 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/api/__init__.py +2 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/api/nested_serializers.py +99 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/api/serializers.py +160 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/api/urls.py +21 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/api/views.py +111 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/choices.py +226 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/filtersets.py +125 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/forms.py +1063 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/jobs.py +95 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0001_initial.py +342 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0002_ipfabricsnapshot_status.py +17 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0003_ipfabricsource_type_and_more.py +49 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0004_ipfabricsync_auto_merge.py +17 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0005_alter_ipfabricrelationshipfield_source_model_and_more.py +64 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/0006_alter_ipfabrictransformmap_target_model.py +48 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/migrations/__init__.py +0 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/models.py +874 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/navigation.py +62 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/signals.py +68 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/tables.py +208 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/template_content.py +13 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/diff.html +72 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/json.html +20 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/logs_pending.html +6 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/merge_form.html +22 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_button.html +70 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_modal.html +61 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/snapshotdata.html +60 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/sync_delete.html +19 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_field_map.html +11 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_relationship_map.html +11 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabric_table.html +55 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabricbranch.html +141 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabricsnapshot.html +105 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabricsource.html +111 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabricsync.html +103 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap.html +41 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_list.html +17 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_restore.html +59 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/partials/branch_all.html +10 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/partials/branch_progress.html +19 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/partials/branch_status.html +1 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/partials/job_logs.html +53 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/partials/sync_last_branch.html +1 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/ipfabric_netbox/sync_list.html +126 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/templates/static/ipfabric_netbox/css/rack.css +9 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/tests/__init__.py +0 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/tests/test_models.py +1340 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/urls.py +141 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/utilities/__init__.py +0 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/utilities/ipfutils.py +591 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/utilities/logging.py +93 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/utilities/nbutils.py +105 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/utilities/transform_map.py +35 -0
- ipfabric_netbox-3.1.2/ipfabric_netbox/views.py +845 -0
- ipfabric_netbox-3.1.2/pyproject.toml +38 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ipfabric_netbox
|
|
3
|
+
Version: 3.1.2
|
|
4
|
+
Summary: NetBox plugin to sync IP Fabric data into NetBox
|
|
5
|
+
Home-page: https://gitlab.com/ip-fabric/integrations/ipfabric-netbox-sync
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: netbox,ipfabric,plugin,sync
|
|
8
|
+
Author: Solution Architecture
|
|
9
|
+
Author-email: solution.architecture@ipfabric.io
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Requires-Dist: ipfabric (>=6.6.4)
|
|
19
|
+
Requires-Dist: netutils
|
|
20
|
+
Project-URL: Bug Tracker, https://gitlab.com/ip-fabric/integrations/ipfabric-netbox-sync/-/issues
|
|
21
|
+
Project-URL: Repository, https://gitlab.com/ip-fabric/integrations/ipfabric-netbox-sync
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# IP Fabric Netbox Plugin
|
|
25
|
+
|
|
26
|
+
## IP Fabric
|
|
27
|
+
|
|
28
|
+
IP Fabric is a vendor-neutral network assurance platform that automates the
|
|
29
|
+
holistic discovery, verification, visualization, and documentation of
|
|
30
|
+
large-scale enterprise networks, reducing the associated costs and required
|
|
31
|
+
resources whilst improving security and efficiency.
|
|
32
|
+
|
|
33
|
+
It supports your engineering and operations teams, underpinning migration and
|
|
34
|
+
transformation projects. IP Fabric will revolutionize how you approach network
|
|
35
|
+
visibility and assurance, security assurance, automation, multi-cloud
|
|
36
|
+
networking, and trouble resolution.
|
|
37
|
+
|
|
38
|
+
**Integrations or scripts should not be installed directly on the IP Fabric VM unless directly communicated from the
|
|
39
|
+
IP Fabric Support or Solution Architect teams. Any action on the Command-Line Interface (CLI) using the root, osadmin,
|
|
40
|
+
or autoboss account may cause irreversible, detrimental changes to the product and can render the system unusable.**
|
|
41
|
+
|
|
42
|
+
## Overview
|
|
43
|
+
|
|
44
|
+
This plugin allows the integration and data synchronization between IP Fabric and NetBox.
|
|
45
|
+
|
|
46
|
+
The plugin uses IP Fabric collect network data utilizing the [IP Fabric Python SDK](https://gitlab.com/ip-fabric/integrations/python-ipfabric). This plugin relies on helpful features in NetBox like [Staged Changes](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/staged-changes/) and [Background Tasks](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/background-tasks/) to make the job of bringing in data to NetBox easier.
|
|
47
|
+
|
|
48
|
+
- Multiple IP Fabric Sources
|
|
49
|
+
- Transform Maps
|
|
50
|
+
- Scheduled Synchronization
|
|
51
|
+
- Diff Visualization
|
|
52
|
+
|
|
53
|
+
## NetBox Compatibility
|
|
54
|
+
|
|
55
|
+
| Netbox Version | Plugin Version |
|
|
56
|
+
| -------------- | -------------- |
|
|
57
|
+
| 3.4 | <=1.0.11 |
|
|
58
|
+
| 3.5 | <=1.0.11 |
|
|
59
|
+
| 3.6 | <=1.0.11 |
|
|
60
|
+
| 3.7 | >=2.0.0 |
|
|
61
|
+
| 4.0 | >=3.0.0 |
|
|
62
|
+
| 4.0.1 | >=3.0.1 |
|
|
63
|
+
| 4.1.0 | >=3.1.0 |
|
|
64
|
+
| 4.1.5 | >=3.1.1 |
|
|
65
|
+
|
|
66
|
+
## Screenshots
|
|
67
|
+
|
|
68
|
+

|
|
69
|
+
|
|
70
|
+

|
|
71
|
+
|
|
72
|
+

|
|
73
|
+
|
|
74
|
+

|
|
75
|
+
|
|
76
|
+

|
|
77
|
+
|
|
78
|
+
## Documentation
|
|
79
|
+
|
|
80
|
+
Full documentation for this plugin can be found at [IP Fabric Docs](https://docs.ipfabric.io/main/integrations/netbox/).
|
|
81
|
+
|
|
82
|
+
- User Guide
|
|
83
|
+
- Administrator Guide
|
|
84
|
+
|
|
85
|
+
## Contributing
|
|
86
|
+
|
|
87
|
+
If you would like to contribute to this plugin, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
|
88
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# IP Fabric Netbox Plugin
|
|
2
|
+
|
|
3
|
+
## IP Fabric
|
|
4
|
+
|
|
5
|
+
IP Fabric is a vendor-neutral network assurance platform that automates the
|
|
6
|
+
holistic discovery, verification, visualization, and documentation of
|
|
7
|
+
large-scale enterprise networks, reducing the associated costs and required
|
|
8
|
+
resources whilst improving security and efficiency.
|
|
9
|
+
|
|
10
|
+
It supports your engineering and operations teams, underpinning migration and
|
|
11
|
+
transformation projects. IP Fabric will revolutionize how you approach network
|
|
12
|
+
visibility and assurance, security assurance, automation, multi-cloud
|
|
13
|
+
networking, and trouble resolution.
|
|
14
|
+
|
|
15
|
+
**Integrations or scripts should not be installed directly on the IP Fabric VM unless directly communicated from the
|
|
16
|
+
IP Fabric Support or Solution Architect teams. Any action on the Command-Line Interface (CLI) using the root, osadmin,
|
|
17
|
+
or autoboss account may cause irreversible, detrimental changes to the product and can render the system unusable.**
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
This plugin allows the integration and data synchronization between IP Fabric and NetBox.
|
|
22
|
+
|
|
23
|
+
The plugin uses IP Fabric collect network data utilizing the [IP Fabric Python SDK](https://gitlab.com/ip-fabric/integrations/python-ipfabric). This plugin relies on helpful features in NetBox like [Staged Changes](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/staged-changes/) and [Background Tasks](https://netboxlabs.com/docs/netbox/en/stable/plugins/development/background-tasks/) to make the job of bringing in data to NetBox easier.
|
|
24
|
+
|
|
25
|
+
- Multiple IP Fabric Sources
|
|
26
|
+
- Transform Maps
|
|
27
|
+
- Scheduled Synchronization
|
|
28
|
+
- Diff Visualization
|
|
29
|
+
|
|
30
|
+
## NetBox Compatibility
|
|
31
|
+
|
|
32
|
+
| Netbox Version | Plugin Version |
|
|
33
|
+
| -------------- | -------------- |
|
|
34
|
+
| 3.4 | <=1.0.11 |
|
|
35
|
+
| 3.5 | <=1.0.11 |
|
|
36
|
+
| 3.6 | <=1.0.11 |
|
|
37
|
+
| 3.7 | >=2.0.0 |
|
|
38
|
+
| 4.0 | >=3.0.0 |
|
|
39
|
+
| 4.0.1 | >=3.0.1 |
|
|
40
|
+
| 4.1.0 | >=3.1.0 |
|
|
41
|
+
| 4.1.5 | >=3.1.1 |
|
|
42
|
+
|
|
43
|
+
## Screenshots
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
## Documentation
|
|
56
|
+
|
|
57
|
+
Full documentation for this plugin can be found at [IP Fabric Docs](https://docs.ipfabric.io/main/integrations/netbox/).
|
|
58
|
+
|
|
59
|
+
- User Guide
|
|
60
|
+
- Administrator Guide
|
|
61
|
+
|
|
62
|
+
## Contributing
|
|
63
|
+
|
|
64
|
+
If you would like to contribute to this plugin, please see the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from django.db import connection
|
|
3
|
+
from netbox.plugins import PluginConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class NetboxIPFabricConfig(PluginConfig):
|
|
7
|
+
name = "ipfabric_netbox"
|
|
8
|
+
verbose_name = "NetBox IP Fabric SoT Plugin"
|
|
9
|
+
description = "Sync IP Fabric into NetBox"
|
|
10
|
+
version = "3.1.1"
|
|
11
|
+
base_url = "ipfabric"
|
|
12
|
+
min_version = "4.1"
|
|
13
|
+
|
|
14
|
+
def ready(self):
|
|
15
|
+
super().ready()
|
|
16
|
+
try:
|
|
17
|
+
from ipfabric_netbox.signals import ipfabric_netbox_init
|
|
18
|
+
|
|
19
|
+
all_tables = connection.introspection.table_names()
|
|
20
|
+
if all(
|
|
21
|
+
item in all_tables
|
|
22
|
+
for item in [
|
|
23
|
+
"extras_customfield",
|
|
24
|
+
"ipfabric_netbox_ipfabricbranch",
|
|
25
|
+
"ipfabric_netbox_ipfabricsource",
|
|
26
|
+
]
|
|
27
|
+
):
|
|
28
|
+
ipfabric_netbox_init()
|
|
29
|
+
if "ipfabric_netbox_ipfabrictransformmap" in all_tables:
|
|
30
|
+
from ipfabric_netbox.models import IPFabricTransformMap
|
|
31
|
+
from ipfabric_netbox.utilities.transform_map import BuildTransformMaps
|
|
32
|
+
|
|
33
|
+
if IPFabricTransformMap.objects.count() == 0:
|
|
34
|
+
data = requests.get(
|
|
35
|
+
"https://gitlab.com/ip-fabric/integrations/ipfabric-netbox/-/raw/main/scripts/transform_map.json"
|
|
36
|
+
).json()
|
|
37
|
+
BuildTransformMaps(data=data)
|
|
38
|
+
except Exception as e:
|
|
39
|
+
print(f"Failed to initialize IP Fabric plugin: {e}.")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
config = NetboxIPFabricConfig
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from drf_spectacular.types import OpenApiTypes
|
|
2
|
+
from drf_spectacular.utils import extend_schema_field
|
|
3
|
+
from netbox.api.fields import ContentTypeField
|
|
4
|
+
from netbox.api.serializers import NetBoxModelSerializer
|
|
5
|
+
from netbox.api.serializers import WritableNestedSerializer
|
|
6
|
+
from rest_framework import serializers
|
|
7
|
+
from users.api.serializers_.nested import NestedUserSerializer
|
|
8
|
+
|
|
9
|
+
from ipfabric_netbox.models import IPFabricBranch
|
|
10
|
+
from ipfabric_netbox.models import IPFabricSnapshot
|
|
11
|
+
from ipfabric_netbox.models import IPFabricSource
|
|
12
|
+
from ipfabric_netbox.models import IPFabricSync
|
|
13
|
+
from ipfabric_netbox.models import IPFabricTransformMap
|
|
14
|
+
|
|
15
|
+
# from .serializers import IPFabricSyncSerializer
|
|
16
|
+
|
|
17
|
+
__all__ = (
|
|
18
|
+
"NestedIPFabricSourceSerializer",
|
|
19
|
+
"NestedIPFabricSnapshotSerializer",
|
|
20
|
+
"NestedIPFabricTransformMapSerializer",
|
|
21
|
+
"NestedIPFabricBranchSerializer",
|
|
22
|
+
"NestedIPFabricSyncSerializer",
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class NestedIPFabricSourceSerializer(WritableNestedSerializer):
|
|
27
|
+
url = serializers.URLField()
|
|
28
|
+
|
|
29
|
+
class Meta:
|
|
30
|
+
model = IPFabricSource
|
|
31
|
+
fields = ["id", "url", "display", "name", "type"]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class NestedIPFabricSnapshotSerializer(NetBoxModelSerializer):
|
|
35
|
+
source = NestedIPFabricSourceSerializer(read_only=True)
|
|
36
|
+
display = serializers.SerializerMethodField(read_only=True)
|
|
37
|
+
|
|
38
|
+
class Meta:
|
|
39
|
+
model = IPFabricSnapshot
|
|
40
|
+
fields = [
|
|
41
|
+
"id",
|
|
42
|
+
"name",
|
|
43
|
+
"source",
|
|
44
|
+
"snapshot_id",
|
|
45
|
+
"status",
|
|
46
|
+
"date",
|
|
47
|
+
"display",
|
|
48
|
+
"sites",
|
|
49
|
+
]
|
|
50
|
+
|
|
51
|
+
@extend_schema_field(OpenApiTypes.STR)
|
|
52
|
+
def get_display(self, obj):
|
|
53
|
+
return f"{obj.name} ({obj.snapshot_id})"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class NestedIPFabricSyncSerializer(NetBoxModelSerializer):
|
|
57
|
+
snapshot_data = NestedIPFabricSnapshotSerializer(read_only=True)
|
|
58
|
+
|
|
59
|
+
class Meta:
|
|
60
|
+
model = IPFabricSync
|
|
61
|
+
fields = [
|
|
62
|
+
"id",
|
|
63
|
+
"name",
|
|
64
|
+
"display",
|
|
65
|
+
"snapshot_data",
|
|
66
|
+
"type",
|
|
67
|
+
"status",
|
|
68
|
+
"parameters",
|
|
69
|
+
"last_synced",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class NestedIPFabricTransformMapSerializer(NetBoxModelSerializer):
|
|
74
|
+
target_model = ContentTypeField(read_only=True)
|
|
75
|
+
|
|
76
|
+
class Meta:
|
|
77
|
+
model = IPFabricTransformMap
|
|
78
|
+
fields = [
|
|
79
|
+
"id",
|
|
80
|
+
"source_model",
|
|
81
|
+
"target_model",
|
|
82
|
+
"status",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class NestedIPFabricBranchSerializer(NetBoxModelSerializer):
|
|
87
|
+
user = NestedUserSerializer(read_only=True)
|
|
88
|
+
sync = NestedIPFabricSyncSerializer(read_only=True)
|
|
89
|
+
|
|
90
|
+
class Meta:
|
|
91
|
+
model = IPFabricBranch
|
|
92
|
+
fields = [
|
|
93
|
+
"id",
|
|
94
|
+
"name",
|
|
95
|
+
"display",
|
|
96
|
+
"sync",
|
|
97
|
+
"description",
|
|
98
|
+
"user",
|
|
99
|
+
]
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from core.choices import DataSourceStatusChoices
|
|
2
|
+
from netbox.api.fields import ChoiceField
|
|
3
|
+
from netbox.api.fields import ContentTypeField
|
|
4
|
+
from netbox.api.serializers import NetBoxModelSerializer
|
|
5
|
+
from rest_framework import serializers
|
|
6
|
+
from users.api.serializers_.nested import NestedUserSerializer
|
|
7
|
+
|
|
8
|
+
from .nested_serializers import NestedIPFabricBranchSerializer # noqa: F401
|
|
9
|
+
from .nested_serializers import NestedIPFabricSnapshotSerializer
|
|
10
|
+
from .nested_serializers import NestedIPFabricSourceSerializer
|
|
11
|
+
from .nested_serializers import NestedIPFabricTransformMapSerializer
|
|
12
|
+
from ipfabric_netbox.models import IPFabricBranch
|
|
13
|
+
from ipfabric_netbox.models import IPFabricRelationshipField
|
|
14
|
+
from ipfabric_netbox.models import IPFabricSnapshot
|
|
15
|
+
from ipfabric_netbox.models import IPFabricSource
|
|
16
|
+
from ipfabric_netbox.models import IPFabricSync
|
|
17
|
+
from ipfabric_netbox.models import IPFabricTransformField
|
|
18
|
+
from ipfabric_netbox.models import IPFabricTransformMap
|
|
19
|
+
|
|
20
|
+
__all__ = (
|
|
21
|
+
"IPFabricSyncSerializer",
|
|
22
|
+
"IPFabricSnapshotSerializer",
|
|
23
|
+
"IPFabricRelationshipFieldSerializer",
|
|
24
|
+
"IPFabricTransformFieldSerializer",
|
|
25
|
+
"IPFabricTransformMapSerializer",
|
|
26
|
+
"IPFabricBranchSerializer",
|
|
27
|
+
"IPFabricSourceSerializer",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class IPFabricSyncSerializer(NetBoxModelSerializer):
|
|
32
|
+
snapshot_data = NestedIPFabricSnapshotSerializer(read_only=True)
|
|
33
|
+
|
|
34
|
+
class Meta:
|
|
35
|
+
model = IPFabricSync
|
|
36
|
+
fields = [
|
|
37
|
+
"id",
|
|
38
|
+
"name",
|
|
39
|
+
"display",
|
|
40
|
+
"snapshot_data",
|
|
41
|
+
"type",
|
|
42
|
+
"status",
|
|
43
|
+
"parameters",
|
|
44
|
+
"last_synced",
|
|
45
|
+
"created",
|
|
46
|
+
"last_updated",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class IPFabricSnapshotSerializer(NetBoxModelSerializer):
|
|
51
|
+
source = NestedIPFabricSourceSerializer()
|
|
52
|
+
data = serializers.JSONField()
|
|
53
|
+
date = serializers.DateTimeField()
|
|
54
|
+
last_updated = serializers.DateTimeField()
|
|
55
|
+
|
|
56
|
+
class Meta:
|
|
57
|
+
model = IPFabricSnapshot
|
|
58
|
+
fields = [
|
|
59
|
+
"id",
|
|
60
|
+
"name",
|
|
61
|
+
"source",
|
|
62
|
+
"snapshot_id",
|
|
63
|
+
"status",
|
|
64
|
+
"date",
|
|
65
|
+
"display",
|
|
66
|
+
"sites",
|
|
67
|
+
"data",
|
|
68
|
+
"created",
|
|
69
|
+
"last_updated",
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
extra_kwargs = {
|
|
73
|
+
"raw_data": {"write_only": True},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
class IPFabricRelationshipFieldSerializer(NetBoxModelSerializer):
|
|
78
|
+
transform_map = NestedIPFabricTransformMapSerializer(read_only=True)
|
|
79
|
+
source_model = ContentTypeField(read_only=True)
|
|
80
|
+
|
|
81
|
+
class Meta:
|
|
82
|
+
model = IPFabricRelationshipField
|
|
83
|
+
fields = [
|
|
84
|
+
"id",
|
|
85
|
+
"transform_map",
|
|
86
|
+
"source_model",
|
|
87
|
+
"target_field",
|
|
88
|
+
"coalesce",
|
|
89
|
+
"template",
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class IPFabricTransformMapSerializer(NetBoxModelSerializer):
|
|
94
|
+
target_model = ContentTypeField(read_only=True)
|
|
95
|
+
|
|
96
|
+
class Meta:
|
|
97
|
+
model = IPFabricTransformMap
|
|
98
|
+
fields = [
|
|
99
|
+
"id",
|
|
100
|
+
"source_model",
|
|
101
|
+
"target_model",
|
|
102
|
+
"status",
|
|
103
|
+
"created",
|
|
104
|
+
"last_updated",
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
class IPFabricTransformFieldSerializer(NetBoxModelSerializer):
|
|
109
|
+
transform_map = NestedIPFabricTransformMapSerializer(read_only=True)
|
|
110
|
+
|
|
111
|
+
class Meta:
|
|
112
|
+
model = IPFabricTransformField
|
|
113
|
+
fields = [
|
|
114
|
+
"id",
|
|
115
|
+
"transform_map",
|
|
116
|
+
"source_field",
|
|
117
|
+
"target_field",
|
|
118
|
+
"coalesce",
|
|
119
|
+
"template",
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class IPFabricBranchSerializer(NetBoxModelSerializer):
|
|
124
|
+
user = NestedUserSerializer(read_only=True)
|
|
125
|
+
sync = IPFabricSyncSerializer(read_only=True)
|
|
126
|
+
|
|
127
|
+
class Meta:
|
|
128
|
+
model = IPFabricBranch
|
|
129
|
+
fields = [
|
|
130
|
+
"id",
|
|
131
|
+
"name",
|
|
132
|
+
"display",
|
|
133
|
+
"sync",
|
|
134
|
+
"description",
|
|
135
|
+
"user",
|
|
136
|
+
"created",
|
|
137
|
+
"last_updated",
|
|
138
|
+
]
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
class IPFabricSourceSerializer(NetBoxModelSerializer):
|
|
142
|
+
status = ChoiceField(choices=DataSourceStatusChoices)
|
|
143
|
+
url = serializers.URLField()
|
|
144
|
+
|
|
145
|
+
class Meta:
|
|
146
|
+
model = IPFabricSource
|
|
147
|
+
fields = [
|
|
148
|
+
"id",
|
|
149
|
+
"url",
|
|
150
|
+
"display",
|
|
151
|
+
"name",
|
|
152
|
+
"type",
|
|
153
|
+
"status",
|
|
154
|
+
"last_synced",
|
|
155
|
+
"description",
|
|
156
|
+
"comments",
|
|
157
|
+
"parameters",
|
|
158
|
+
"created",
|
|
159
|
+
"last_updated",
|
|
160
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# api/urls.py
|
|
2
|
+
from netbox.api.routers import NetBoxRouter
|
|
3
|
+
|
|
4
|
+
from ipfabric_netbox.api.views import IPFabricBranchViewSet
|
|
5
|
+
from ipfabric_netbox.api.views import IPFabricRelationshipFieldiewSet
|
|
6
|
+
from ipfabric_netbox.api.views import IPFabricSnapshotViewSet
|
|
7
|
+
from ipfabric_netbox.api.views import IPFabricSourceViewSet
|
|
8
|
+
from ipfabric_netbox.api.views import IPFabricSyncViewSet
|
|
9
|
+
from ipfabric_netbox.api.views import IPFabricTransformFieldiewSet
|
|
10
|
+
from ipfabric_netbox.api.views import IPFabricTransformMapViewSet
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
router = NetBoxRouter()
|
|
14
|
+
router.register("source", IPFabricSourceViewSet)
|
|
15
|
+
router.register("snapshot", IPFabricSnapshotViewSet)
|
|
16
|
+
router.register("transform-map", IPFabricTransformMapViewSet)
|
|
17
|
+
router.register("sync", IPFabricSyncViewSet)
|
|
18
|
+
router.register("branch", IPFabricBranchViewSet)
|
|
19
|
+
router.register("transform-field", IPFabricTransformFieldiewSet)
|
|
20
|
+
router.register("relationship-field", IPFabricRelationshipFieldiewSet)
|
|
21
|
+
urlpatterns = router.urls
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from django.db import transaction
|
|
2
|
+
from netbox.api.viewsets import NetBoxModelViewSet
|
|
3
|
+
from netbox.api.viewsets import NetBoxReadOnlyModelViewSet
|
|
4
|
+
from rest_framework.decorators import action
|
|
5
|
+
from rest_framework.response import Response
|
|
6
|
+
from utilities.query import count_related
|
|
7
|
+
|
|
8
|
+
from .serializers import IPFabricBranchSerializer
|
|
9
|
+
from .serializers import IPFabricRelationshipFieldSerializer
|
|
10
|
+
from .serializers import IPFabricSnapshotSerializer
|
|
11
|
+
from .serializers import IPFabricSourceSerializer
|
|
12
|
+
from .serializers import IPFabricSyncSerializer
|
|
13
|
+
from .serializers import IPFabricTransformFieldSerializer
|
|
14
|
+
from .serializers import IPFabricTransformMapSerializer
|
|
15
|
+
from ipfabric_netbox.filtersets import IPFabricSnapshotFilterSet
|
|
16
|
+
from ipfabric_netbox.filtersets import IPFabricSourceFilterSet
|
|
17
|
+
from ipfabric_netbox.filtersets import IPFabricTransformFieldFilterSet
|
|
18
|
+
from ipfabric_netbox.models import IPFabricBranch
|
|
19
|
+
from ipfabric_netbox.models import IPFabricData
|
|
20
|
+
from ipfabric_netbox.models import IPFabricRelationshipField
|
|
21
|
+
from ipfabric_netbox.models import IPFabricSnapshot
|
|
22
|
+
from ipfabric_netbox.models import IPFabricSource
|
|
23
|
+
from ipfabric_netbox.models import IPFabricSync
|
|
24
|
+
from ipfabric_netbox.models import IPFabricTransformField
|
|
25
|
+
from ipfabric_netbox.models import IPFabricTransformMap
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class IPFabricTransformMapViewSet(NetBoxReadOnlyModelViewSet):
|
|
29
|
+
queryset = IPFabricTransformMap.objects.all()
|
|
30
|
+
serializer_class = IPFabricTransformMapSerializer
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class IPFabricTransformFieldiewSet(NetBoxReadOnlyModelViewSet):
|
|
34
|
+
queryset = IPFabricTransformField.objects.all()
|
|
35
|
+
serializer_class = IPFabricTransformFieldSerializer
|
|
36
|
+
filterset_class = IPFabricTransformFieldFilterSet
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class IPFabricRelationshipFieldiewSet(NetBoxReadOnlyModelViewSet):
|
|
40
|
+
queryset = IPFabricRelationshipField.objects.all()
|
|
41
|
+
serializer_class = IPFabricRelationshipFieldSerializer
|
|
42
|
+
filterset_class = IPFabricTransformFieldFilterSet
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class IPFabricSyncViewSet(NetBoxReadOnlyModelViewSet):
|
|
46
|
+
queryset = IPFabricSync.objects.all()
|
|
47
|
+
serializer_class = IPFabricSyncSerializer
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class IPFabricBranchViewSet(NetBoxReadOnlyModelViewSet):
|
|
51
|
+
queryset = IPFabricBranch.objects.all()
|
|
52
|
+
serializer_class = IPFabricBranchSerializer
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class IPFabricSnapshotViewSet(NetBoxModelViewSet):
|
|
56
|
+
queryset = IPFabricSnapshot.objects.all()
|
|
57
|
+
serializer_class = IPFabricSnapshotSerializer
|
|
58
|
+
filterset_class = IPFabricSnapshotFilterSet
|
|
59
|
+
|
|
60
|
+
@action(detail=True, methods=["patch", "delete"], url_path="raw")
|
|
61
|
+
def raw(self, request, pk):
|
|
62
|
+
snapshot = self.get_object()
|
|
63
|
+
if request.method == "DELETE":
|
|
64
|
+
raw_data = IPFabricData.objects.filter(snapshot_data=snapshot)
|
|
65
|
+
raw_data._raw_delete(raw_data.db)
|
|
66
|
+
return Response({"status": "success"})
|
|
67
|
+
elif request.method == "PATCH":
|
|
68
|
+
transaction.set_autocommit(False)
|
|
69
|
+
IPFabricData.objects.bulk_create(
|
|
70
|
+
[
|
|
71
|
+
IPFabricData(
|
|
72
|
+
snapshot_data=snapshot, data=item["data"], type=item["type"]
|
|
73
|
+
)
|
|
74
|
+
for item in request.data["data"]
|
|
75
|
+
],
|
|
76
|
+
batch_size=5000,
|
|
77
|
+
)
|
|
78
|
+
transaction.commit()
|
|
79
|
+
return Response({"status": "success"})
|
|
80
|
+
|
|
81
|
+
@action(detail=True, methods=["get"], url_path="sites")
|
|
82
|
+
def sites(self, request, pk):
|
|
83
|
+
q = request.GET.get("q", None)
|
|
84
|
+
snapshot = IPFabricSnapshot.objects.get(pk=pk)
|
|
85
|
+
new_sites = {"results": []}
|
|
86
|
+
if snapshot.data:
|
|
87
|
+
sites = snapshot.data.get("sites", None)
|
|
88
|
+
num = 0
|
|
89
|
+
if sites:
|
|
90
|
+
for site in sites:
|
|
91
|
+
if q:
|
|
92
|
+
if q.lower() in site.lower():
|
|
93
|
+
new_sites["results"].append(
|
|
94
|
+
{"display": site, "name": site, "id": site}
|
|
95
|
+
)
|
|
96
|
+
else:
|
|
97
|
+
new_sites["results"].append(
|
|
98
|
+
{"display": site, "name": site, "id": site}
|
|
99
|
+
)
|
|
100
|
+
num += 1
|
|
101
|
+
return Response(new_sites)
|
|
102
|
+
else:
|
|
103
|
+
return Response([])
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
class IPFabricSourceViewSet(NetBoxModelViewSet):
|
|
107
|
+
queryset = IPFabricSource.objects.annotate(
|
|
108
|
+
snapshot_count=count_related(IPFabricSnapshot, "source")
|
|
109
|
+
)
|
|
110
|
+
serializer_class = IPFabricSourceSerializer
|
|
111
|
+
filterset_class = IPFabricSourceFilterSet
|