ipfabric_netbox 3.1.2__py3-none-any.whl
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/__init__.py +42 -0
- ipfabric_netbox/api/__init__.py +2 -0
- ipfabric_netbox/api/nested_serializers.py +99 -0
- ipfabric_netbox/api/serializers.py +160 -0
- ipfabric_netbox/api/urls.py +21 -0
- ipfabric_netbox/api/views.py +111 -0
- ipfabric_netbox/choices.py +226 -0
- ipfabric_netbox/filtersets.py +125 -0
- ipfabric_netbox/forms.py +1063 -0
- ipfabric_netbox/jobs.py +95 -0
- ipfabric_netbox/migrations/0001_initial.py +342 -0
- ipfabric_netbox/migrations/0002_ipfabricsnapshot_status.py +17 -0
- ipfabric_netbox/migrations/0003_ipfabricsource_type_and_more.py +49 -0
- ipfabric_netbox/migrations/0004_ipfabricsync_auto_merge.py +17 -0
- ipfabric_netbox/migrations/0005_alter_ipfabricrelationshipfield_source_model_and_more.py +64 -0
- ipfabric_netbox/migrations/0006_alter_ipfabrictransformmap_target_model.py +48 -0
- ipfabric_netbox/migrations/__init__.py +0 -0
- ipfabric_netbox/models.py +874 -0
- ipfabric_netbox/navigation.py +62 -0
- ipfabric_netbox/signals.py +68 -0
- ipfabric_netbox/tables.py +208 -0
- ipfabric_netbox/template_content.py +13 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/diff.html +72 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/json.html +20 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/logs_pending.html +6 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/merge_form.html +22 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_button.html +70 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_modal.html +61 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/snapshotdata.html +60 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/sync_delete.html +19 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_field_map.html +11 -0
- ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_relationship_map.html +11 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabric_table.html +55 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabricbranch.html +141 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabricsnapshot.html +105 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabricsource.html +111 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabricsync.html +103 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap.html +41 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_list.html +17 -0
- ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_restore.html +59 -0
- ipfabric_netbox/templates/ipfabric_netbox/partials/branch_all.html +10 -0
- ipfabric_netbox/templates/ipfabric_netbox/partials/branch_progress.html +19 -0
- ipfabric_netbox/templates/ipfabric_netbox/partials/branch_status.html +1 -0
- ipfabric_netbox/templates/ipfabric_netbox/partials/job_logs.html +53 -0
- ipfabric_netbox/templates/ipfabric_netbox/partials/sync_last_branch.html +1 -0
- ipfabric_netbox/templates/ipfabric_netbox/sync_list.html +126 -0
- ipfabric_netbox/templates/static/ipfabric_netbox/css/rack.css +9 -0
- ipfabric_netbox/tests/__init__.py +0 -0
- ipfabric_netbox/tests/test_models.py +1340 -0
- ipfabric_netbox/urls.py +141 -0
- ipfabric_netbox/utilities/__init__.py +0 -0
- ipfabric_netbox/utilities/ipfutils.py +591 -0
- ipfabric_netbox/utilities/logging.py +93 -0
- ipfabric_netbox/utilities/nbutils.py +105 -0
- ipfabric_netbox/utilities/transform_map.py +35 -0
- ipfabric_netbox/views.py +845 -0
- ipfabric_netbox-3.1.2.dist-info/METADATA +88 -0
- ipfabric_netbox-3.1.2.dist-info/RECORD +59 -0
- ipfabric_netbox-3.1.2.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
from collections import Counter
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
|
|
4
|
+
from dcim.models import Device
|
|
5
|
+
from dcim.models import InventoryItem
|
|
6
|
+
from dcim.models import Manufacturer
|
|
7
|
+
|
|
8
|
+
DEFAULT_DEVICE_ROLE = "Network Device"
|
|
9
|
+
device_serial_max_length = Device._meta.get_field("serial").max_length
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def order_members(members):
|
|
13
|
+
devices = {}
|
|
14
|
+
|
|
15
|
+
for member in members:
|
|
16
|
+
master_serial = member.get("sn")
|
|
17
|
+
if master_serial and member.get("memberSn"):
|
|
18
|
+
if master_serial in devices:
|
|
19
|
+
devices[master_serial].append(member)
|
|
20
|
+
else:
|
|
21
|
+
devices[master_serial] = [member]
|
|
22
|
+
|
|
23
|
+
return devices
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def order_devices(devices, members):
|
|
27
|
+
hostnames = [d["hostname"] for d in devices]
|
|
28
|
+
counter = Counter(hostnames)
|
|
29
|
+
|
|
30
|
+
new_devices = []
|
|
31
|
+
|
|
32
|
+
for device in devices:
|
|
33
|
+
if counter[device["hostname"]] > 1:
|
|
34
|
+
device["hostname"] = f"{device['hostname']} - ({device['sn']})"
|
|
35
|
+
if child_members := members.get(device.get("sn")):
|
|
36
|
+
for child_member in child_members:
|
|
37
|
+
if device.get("sn") != child_member.get("memberSn"):
|
|
38
|
+
new_device = deepcopy(device)
|
|
39
|
+
new_device[
|
|
40
|
+
"hostname"
|
|
41
|
+
] = f"{device['hostname']}/{child_member.get('member')}"
|
|
42
|
+
new_device["model"] = child_member.get("pn")
|
|
43
|
+
new_device["sn"] = child_member.get("memberSn")
|
|
44
|
+
new_device["virtual_chassis"] = child_member
|
|
45
|
+
new_devices.append(new_device)
|
|
46
|
+
else:
|
|
47
|
+
device["virtual_chassis"] = child_member
|
|
48
|
+
hostnames = [d["hostname"] for d in devices]
|
|
49
|
+
counter = Counter(hostnames)
|
|
50
|
+
|
|
51
|
+
devices.extend(new_devices)
|
|
52
|
+
|
|
53
|
+
return devices
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def order_vrf(vrfs):
|
|
57
|
+
vrf_dict = {}
|
|
58
|
+
|
|
59
|
+
for vrf in vrfs:
|
|
60
|
+
sn = vrf["sn"]
|
|
61
|
+
if sn in vrf_dict:
|
|
62
|
+
vrf_dict[sn].append(vrf)
|
|
63
|
+
else:
|
|
64
|
+
vrf_dict[sn] = [vrf]
|
|
65
|
+
|
|
66
|
+
return vrf_dict
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def order_pn(part_numbers):
|
|
70
|
+
pn_dict = {}
|
|
71
|
+
|
|
72
|
+
for pn in part_numbers:
|
|
73
|
+
device_sn = pn["deviceSn"]
|
|
74
|
+
if device_sn in pn_dict:
|
|
75
|
+
pn_dict[device_sn].append(pn)
|
|
76
|
+
else:
|
|
77
|
+
pn_dict[device_sn] = [pn]
|
|
78
|
+
|
|
79
|
+
return pn_dict
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def create_inventory_items(device: Device, parts: list, manufacturer: Manufacturer):
|
|
83
|
+
for part in parts:
|
|
84
|
+
name = part.get("name", "")
|
|
85
|
+
if len(name) > InventoryItem._meta.get_field("name").max_length:
|
|
86
|
+
if part.get("dscr"):
|
|
87
|
+
name = part.get("dscr")
|
|
88
|
+
else:
|
|
89
|
+
name = part.get("sn")
|
|
90
|
+
|
|
91
|
+
defaults = {
|
|
92
|
+
"name": name,
|
|
93
|
+
"manufacturer": manufacturer,
|
|
94
|
+
"serial": part.get("sn", ""),
|
|
95
|
+
# "description": part.get('dscr', "123"),
|
|
96
|
+
"part_id": part.get("pid", ""),
|
|
97
|
+
"device": device,
|
|
98
|
+
"lft": device.pk,
|
|
99
|
+
}
|
|
100
|
+
if part.get("dscr"):
|
|
101
|
+
defaults["description"] = part.get("dscr")
|
|
102
|
+
|
|
103
|
+
inventory_object, _ = InventoryItem.objects.update_or_create(
|
|
104
|
+
serial=part.get("sn", ""), defaults=defaults
|
|
105
|
+
)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from django.contrib.contenttypes.models import ContentType
|
|
2
|
+
|
|
3
|
+
from ipfabric_netbox.models import IPFabricRelationshipField
|
|
4
|
+
from ipfabric_netbox.models import IPFabricTransformField
|
|
5
|
+
from ipfabric_netbox.models import IPFabricTransformMap
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def BuildField(data):
|
|
9
|
+
if "target_model" in data:
|
|
10
|
+
ct = ContentType.objects.get(
|
|
11
|
+
app_label=data["target_model"]["app_label"],
|
|
12
|
+
model=data["target_model"]["model"],
|
|
13
|
+
)
|
|
14
|
+
data["target_model"] = ct
|
|
15
|
+
elif "source_model" in data:
|
|
16
|
+
ct = ContentType.objects.get(
|
|
17
|
+
app_label=data["source_model"]["app_label"],
|
|
18
|
+
model=data["source_model"]["model"],
|
|
19
|
+
)
|
|
20
|
+
data["source_model"] = ct
|
|
21
|
+
return data
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def BuildTransformMaps(data):
|
|
25
|
+
for tm in data:
|
|
26
|
+
field_data = BuildField(tm["data"])
|
|
27
|
+
tm_obj = IPFabricTransformMap.objects.create(**field_data)
|
|
28
|
+
for fm in tm["field_maps"]:
|
|
29
|
+
field_data = BuildField(fm)
|
|
30
|
+
IPFabricTransformField.objects.create(transform_map=tm_obj, **field_data)
|
|
31
|
+
for rm in tm["relationship_maps"]:
|
|
32
|
+
relationship_data = BuildField(rm)
|
|
33
|
+
IPFabricRelationshipField.objects.create(
|
|
34
|
+
transform_map=tm_obj, **relationship_data
|
|
35
|
+
)
|