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.

Files changed (59) hide show
  1. ipfabric_netbox/__init__.py +42 -0
  2. ipfabric_netbox/api/__init__.py +2 -0
  3. ipfabric_netbox/api/nested_serializers.py +99 -0
  4. ipfabric_netbox/api/serializers.py +160 -0
  5. ipfabric_netbox/api/urls.py +21 -0
  6. ipfabric_netbox/api/views.py +111 -0
  7. ipfabric_netbox/choices.py +226 -0
  8. ipfabric_netbox/filtersets.py +125 -0
  9. ipfabric_netbox/forms.py +1063 -0
  10. ipfabric_netbox/jobs.py +95 -0
  11. ipfabric_netbox/migrations/0001_initial.py +342 -0
  12. ipfabric_netbox/migrations/0002_ipfabricsnapshot_status.py +17 -0
  13. ipfabric_netbox/migrations/0003_ipfabricsource_type_and_more.py +49 -0
  14. ipfabric_netbox/migrations/0004_ipfabricsync_auto_merge.py +17 -0
  15. ipfabric_netbox/migrations/0005_alter_ipfabricrelationshipfield_source_model_and_more.py +64 -0
  16. ipfabric_netbox/migrations/0006_alter_ipfabrictransformmap_target_model.py +48 -0
  17. ipfabric_netbox/migrations/__init__.py +0 -0
  18. ipfabric_netbox/models.py +874 -0
  19. ipfabric_netbox/navigation.py +62 -0
  20. ipfabric_netbox/signals.py +68 -0
  21. ipfabric_netbox/tables.py +208 -0
  22. ipfabric_netbox/template_content.py +13 -0
  23. ipfabric_netbox/templates/ipfabric_netbox/inc/diff.html +72 -0
  24. ipfabric_netbox/templates/ipfabric_netbox/inc/json.html +20 -0
  25. ipfabric_netbox/templates/ipfabric_netbox/inc/logs_pending.html +6 -0
  26. ipfabric_netbox/templates/ipfabric_netbox/inc/merge_form.html +22 -0
  27. ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_button.html +70 -0
  28. ipfabric_netbox/templates/ipfabric_netbox/inc/site_topology_modal.html +61 -0
  29. ipfabric_netbox/templates/ipfabric_netbox/inc/snapshotdata.html +60 -0
  30. ipfabric_netbox/templates/ipfabric_netbox/inc/sync_delete.html +19 -0
  31. ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_field_map.html +11 -0
  32. ipfabric_netbox/templates/ipfabric_netbox/inc/transform_map_relationship_map.html +11 -0
  33. ipfabric_netbox/templates/ipfabric_netbox/ipfabric_table.html +55 -0
  34. ipfabric_netbox/templates/ipfabric_netbox/ipfabricbranch.html +141 -0
  35. ipfabric_netbox/templates/ipfabric_netbox/ipfabricsnapshot.html +105 -0
  36. ipfabric_netbox/templates/ipfabric_netbox/ipfabricsource.html +111 -0
  37. ipfabric_netbox/templates/ipfabric_netbox/ipfabricsync.html +103 -0
  38. ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap.html +41 -0
  39. ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_list.html +17 -0
  40. ipfabric_netbox/templates/ipfabric_netbox/ipfabrictransformmap_restore.html +59 -0
  41. ipfabric_netbox/templates/ipfabric_netbox/partials/branch_all.html +10 -0
  42. ipfabric_netbox/templates/ipfabric_netbox/partials/branch_progress.html +19 -0
  43. ipfabric_netbox/templates/ipfabric_netbox/partials/branch_status.html +1 -0
  44. ipfabric_netbox/templates/ipfabric_netbox/partials/job_logs.html +53 -0
  45. ipfabric_netbox/templates/ipfabric_netbox/partials/sync_last_branch.html +1 -0
  46. ipfabric_netbox/templates/ipfabric_netbox/sync_list.html +126 -0
  47. ipfabric_netbox/templates/static/ipfabric_netbox/css/rack.css +9 -0
  48. ipfabric_netbox/tests/__init__.py +0 -0
  49. ipfabric_netbox/tests/test_models.py +1340 -0
  50. ipfabric_netbox/urls.py +141 -0
  51. ipfabric_netbox/utilities/__init__.py +0 -0
  52. ipfabric_netbox/utilities/ipfutils.py +591 -0
  53. ipfabric_netbox/utilities/logging.py +93 -0
  54. ipfabric_netbox/utilities/nbutils.py +105 -0
  55. ipfabric_netbox/utilities/transform_map.py +35 -0
  56. ipfabric_netbox/views.py +845 -0
  57. ipfabric_netbox-3.1.2.dist-info/METADATA +88 -0
  58. ipfabric_netbox-3.1.2.dist-info/RECORD +59 -0
  59. ipfabric_netbox-3.1.2.dist-info/WHEEL +4 -0
@@ -0,0 +1,1340 @@
1
+ import copy
2
+ import json
3
+ import uuid
4
+
5
+ from dcim.models import Device
6
+ from django.contrib.contenttypes.models import ContentType
7
+ from django.core import serializers
8
+ from django.test import TestCase
9
+ from django.utils import timezone
10
+
11
+ from ipfabric_netbox.models import IPFabricSnapshot
12
+ from ipfabric_netbox.models import IPFabricSource
13
+ from ipfabric_netbox.models import IPFabricSync
14
+ from ipfabric_netbox.models import IPFabricTransformField
15
+ from ipfabric_netbox.models import IPFabricTransformMap
16
+ from ipfabric_netbox.utilities.ipfutils import IPFabricSyncRunner
17
+
18
+ transform_maps = [
19
+ {
20
+ "model": "ipfabric_netbox.ipfabrictransformmap",
21
+ "pk": 4,
22
+ "fields": {
23
+ "created": "2023-06-22T09:12:03.018Z",
24
+ "last_updated": "2023-06-22T09:12:03.018Z",
25
+ "custom_field_data": {},
26
+ "name": "Platform Transform Map",
27
+ "source_model": "device",
28
+ "target_model": 43,
29
+ "status": "",
30
+ },
31
+ },
32
+ {
33
+ "model": "ipfabric_netbox.ipfabrictransformmap",
34
+ "pk": 1,
35
+ "fields": {
36
+ "created": "2023-06-22T09:12:02.886Z",
37
+ "last_updated": "2023-06-22T09:53:32.100Z",
38
+ "custom_field_data": {},
39
+ "name": "Site Transform Map",
40
+ "source_model": "site",
41
+ "target_model": 56,
42
+ "status": "active",
43
+ },
44
+ },
45
+ {
46
+ "model": "ipfabric_netbox.ipfabrictransformmap",
47
+ "pk": 2,
48
+ "fields": {
49
+ "created": "2023-06-22T09:12:02.924Z",
50
+ "last_updated": "2023-06-22T15:02:20.038Z",
51
+ "custom_field_data": {},
52
+ "name": "Manufacturer Transform Map",
53
+ "source_model": "device",
54
+ "target_model": 42,
55
+ "status": "",
56
+ },
57
+ },
58
+ {
59
+ "model": "ipfabric_netbox.ipfabrictransformmap",
60
+ "pk": 5,
61
+ "fields": {
62
+ "created": "2023-06-22T09:12:03.087Z",
63
+ "last_updated": "2023-06-22T15:51:28.987Z",
64
+ "custom_field_data": {},
65
+ "name": "Device Transform Map",
66
+ "source_model": "device",
67
+ "target_model": 31,
68
+ "status": "active",
69
+ },
70
+ },
71
+ {
72
+ "model": "ipfabric_netbox.ipfabrictransformmap",
73
+ "pk": 6,
74
+ "fields": {
75
+ "created": "2023-06-22T09:12:03.134Z",
76
+ "last_updated": "2023-06-22T16:24:22.879Z",
77
+ "custom_field_data": {},
78
+ "name": "Device Role Transform Map",
79
+ "source_model": "device",
80
+ "target_model": 34,
81
+ "status": "",
82
+ },
83
+ },
84
+ {
85
+ "model": "ipfabric_netbox.ipfabrictransformmap",
86
+ "pk": 3,
87
+ "fields": {
88
+ "created": "2023-06-22T09:12:02.971Z",
89
+ "last_updated": "2023-06-23T13:23:50.445Z",
90
+ "custom_field_data": {},
91
+ "name": "Device Type Transform Map",
92
+ "source_model": "device",
93
+ "target_model": 35,
94
+ "status": "",
95
+ },
96
+ },
97
+ {
98
+ "model": "ipfabric_netbox.ipfabrictransformmap",
99
+ "pk": 10,
100
+ "fields": {
101
+ "created": "2023-06-23T14:42:40.118Z",
102
+ "last_updated": "2023-06-23T14:42:40.118Z",
103
+ "custom_field_data": {},
104
+ "name": "Interface Transform Map",
105
+ "source_model": "interface",
106
+ "target_model": 38,
107
+ "status": "",
108
+ },
109
+ },
110
+ {
111
+ "model": "ipfabric_netbox.ipfabrictransformmap",
112
+ "pk": 11,
113
+ "fields": {
114
+ "created": "2023-06-28T15:13:56.033Z",
115
+ "last_updated": "2023-06-28T15:18:37.423Z",
116
+ "custom_field_data": {},
117
+ "name": "Inventory Transform Map",
118
+ "source_model": "part_number",
119
+ "target_model": 40,
120
+ "status": "",
121
+ },
122
+ },
123
+ {
124
+ "model": "ipfabric_netbox.ipfabrictransformmap",
125
+ "pk": 12,
126
+ "fields": {
127
+ "created": "2023-07-14T15:37:25.428Z",
128
+ "last_updated": "2023-07-14T15:37:25.428Z",
129
+ "custom_field_data": {},
130
+ "name": "VLAN Transform Map",
131
+ "source_model": "vlan",
132
+ "target_model": 75,
133
+ "status": "active",
134
+ },
135
+ },
136
+ {
137
+ "model": "ipfabric_netbox.ipfabrictransformmap",
138
+ "pk": 13,
139
+ "fields": {
140
+ "created": "2023-07-14T16:39:14.674Z",
141
+ "last_updated": "2023-07-14T16:39:14.675Z",
142
+ "custom_field_data": {},
143
+ "name": "VRF Transform Map",
144
+ "source_model": "vrf",
145
+ "target_model": 73,
146
+ "status": "",
147
+ },
148
+ },
149
+ {
150
+ "model": "ipfabric_netbox.ipfabrictransformmap",
151
+ "pk": 14,
152
+ "fields": {
153
+ "created": "2023-07-18T09:36:57.588Z",
154
+ "last_updated": "2023-07-18T09:36:57.588Z",
155
+ "custom_field_data": {},
156
+ "name": "Prefix Transform Map",
157
+ "source_model": "prefix",
158
+ "target_model": 69,
159
+ "status": "active",
160
+ },
161
+ },
162
+ {
163
+ "model": "ipfabric_netbox.ipfabrictransformmap",
164
+ "pk": 15,
165
+ "fields": {
166
+ "created": "2023-07-31T10:54:29.792Z",
167
+ "last_updated": "2023-07-31T10:54:29.792Z",
168
+ "custom_field_data": {},
169
+ "name": "Virtual Chassis Transform Map",
170
+ "source_model": "virtualchassis",
171
+ "target_model": 58,
172
+ "status": "",
173
+ },
174
+ },
175
+ {
176
+ "model": "ipfabric_netbox.ipfabrictransformmap",
177
+ "pk": 16,
178
+ "fields": {
179
+ "created": "2023-08-15T14:34:00.334Z",
180
+ "last_updated": "2023-08-15T14:34:00.334Z",
181
+ "custom_field_data": {},
182
+ "name": "IP Address Transform Map",
183
+ "source_model": "ipaddress",
184
+ "target_model": 68,
185
+ "status": "active",
186
+ },
187
+ },
188
+ ]
189
+
190
+ transform_fields = [
191
+ {
192
+ "model": "ipfabric_netbox.ipfabrictransformfield",
193
+ "pk": 19,
194
+ "fields": {
195
+ "created": "2023-06-23T15:01:13.459Z",
196
+ "last_updated": "2023-06-23T15:01:13.459Z",
197
+ "custom_field_data": {},
198
+ "description": "",
199
+ "comments": "",
200
+ "transform_map": 10,
201
+ "source_field": "dscr",
202
+ "target_field": "description",
203
+ "coalesce": False,
204
+ "template": '{{ object.dscr or ""}}',
205
+ },
206
+ },
207
+ {
208
+ "model": "ipfabric_netbox.ipfabrictransformfield",
209
+ "pk": 20,
210
+ "fields": {
211
+ "created": "2023-06-28T10:39:24.588Z",
212
+ "last_updated": "2023-06-28T10:39:24.588Z",
213
+ "custom_field_data": {},
214
+ "description": "",
215
+ "comments": "",
216
+ "transform_map": 10,
217
+ "source_field": "media",
218
+ "target_field": "type",
219
+ "coalesce": False,
220
+ "template": "1000base-t",
221
+ },
222
+ },
223
+ {
224
+ "model": "ipfabric_netbox.ipfabrictransformfield",
225
+ "pk": 2,
226
+ "fields": {
227
+ "created": "2023-06-22T09:12:02.900Z",
228
+ "last_updated": "2023-06-22T09:12:02.900Z",
229
+ "custom_field_data": {},
230
+ "description": "",
231
+ "comments": "",
232
+ "transform_map": 1,
233
+ "source_field": "siteName",
234
+ "target_field": "slug",
235
+ "coalesce": True,
236
+ "template": "{{ object.siteName | slugify }}",
237
+ },
238
+ },
239
+ {
240
+ "model": "ipfabric_netbox.ipfabrictransformfield",
241
+ "pk": 3,
242
+ "fields": {
243
+ "created": "2023-06-22T09:12:02.933Z",
244
+ "last_updated": "2023-06-22T09:12:02.933Z",
245
+ "custom_field_data": {},
246
+ "description": "",
247
+ "comments": "",
248
+ "transform_map": 2,
249
+ "source_field": "vendor",
250
+ "target_field": "name",
251
+ "coalesce": False,
252
+ "template": None,
253
+ },
254
+ },
255
+ {
256
+ "model": "ipfabric_netbox.ipfabrictransformfield",
257
+ "pk": 25,
258
+ "fields": {
259
+ "created": "2023-06-28T10:46:04.153Z",
260
+ "last_updated": "2023-06-28T10:46:04.153Z",
261
+ "custom_field_data": {},
262
+ "description": "",
263
+ "comments": "",
264
+ "transform_map": 10,
265
+ "source_field": "l1",
266
+ "target_field": "enabled",
267
+ "coalesce": False,
268
+ "template": '{% if object.l1 == "up" %}True{% else %}False{% endif %}',
269
+ },
270
+ },
271
+ {
272
+ "model": "ipfabric_netbox.ipfabrictransformfield",
273
+ "pk": 34,
274
+ "fields": {
275
+ "created": "2023-07-14T15:38:30.728Z",
276
+ "last_updated": "2023-07-31T10:37:21.182Z",
277
+ "custom_field_data": {},
278
+ "description": "",
279
+ "comments": "",
280
+ "transform_map": 12,
281
+ "source_field": "vlanName",
282
+ "target_field": "name",
283
+ "coalesce": False,
284
+ "template": '{{ object.vlanName or ""}}',
285
+ },
286
+ },
287
+ {
288
+ "model": "ipfabric_netbox.ipfabrictransformfield",
289
+ "pk": 40,
290
+ "fields": {
291
+ "created": "2023-07-31T15:07:09.911Z",
292
+ "last_updated": "2023-07-31T15:07:09.911Z",
293
+ "custom_field_data": {},
294
+ "description": "",
295
+ "comments": "",
296
+ "transform_map": 15,
297
+ "source_field": "master",
298
+ "target_field": "name",
299
+ "coalesce": True,
300
+ "template": "",
301
+ },
302
+ },
303
+ {
304
+ "model": "ipfabric_netbox.ipfabrictransformfield",
305
+ "pk": 22,
306
+ "fields": {
307
+ "created": "2023-06-28T10:41:47.345Z",
308
+ "last_updated": "2023-06-28T12:08:47.704Z",
309
+ "custom_field_data": {},
310
+ "description": "",
311
+ "comments": "",
312
+ "transform_map": 10,
313
+ "source_field": "mac",
314
+ "target_field": "mac_address",
315
+ "coalesce": False,
316
+ "template": '{% if object.mac %}{{ object.mac | mac_to_format(frmt="MAC_COLON_TWO") | upper }}{% else %}{{ "00:00:00:00:00:01" | mac_to_format(frmt="MAC_COLON_TWO") | upper }}{% endif %}',
317
+ },
318
+ },
319
+ {
320
+ "model": "ipfabric_netbox.ipfabrictransformfield",
321
+ "pk": 4,
322
+ "fields": {
323
+ "created": "2023-06-22T09:12:02.948Z",
324
+ "last_updated": "2023-06-22T09:12:02.948Z",
325
+ "custom_field_data": {},
326
+ "description": "",
327
+ "comments": "",
328
+ "transform_map": 2,
329
+ "source_field": "vendor",
330
+ "target_field": "slug",
331
+ "coalesce": True,
332
+ "template": "{{ object.vendor | slugify }}",
333
+ },
334
+ },
335
+ {
336
+ "model": "ipfabric_netbox.ipfabrictransformfield",
337
+ "pk": 8,
338
+ "fields": {
339
+ "created": "2023-06-22T09:12:03.043Z",
340
+ "last_updated": "2023-07-14T10:54:57.940Z",
341
+ "custom_field_data": {},
342
+ "description": "",
343
+ "comments": "",
344
+ "transform_map": 4,
345
+ "source_field": "vendor",
346
+ "target_field": "slug",
347
+ "coalesce": True,
348
+ "template": "{{ object.vendor | slugify }}{%if object.family %}_{{ object.family | slugify }}{% endif %}",
349
+ },
350
+ },
351
+ {
352
+ "model": "ipfabric_netbox.ipfabrictransformfield",
353
+ "pk": 6,
354
+ "fields": {
355
+ "created": "2023-06-22T09:12:02.995Z",
356
+ "last_updated": "2023-06-22T09:12:02.995Z",
357
+ "custom_field_data": {},
358
+ "description": "",
359
+ "comments": "",
360
+ "transform_map": 3,
361
+ "source_field": "vendor",
362
+ "target_field": "slug",
363
+ "coalesce": True,
364
+ "template": "{{ object.vendor | slugify }}",
365
+ },
366
+ },
367
+ {
368
+ "model": "ipfabric_netbox.ipfabrictransformfield",
369
+ "pk": 26,
370
+ "fields": {
371
+ "created": "2023-06-28T10:49:23.845Z",
372
+ "last_updated": "2023-06-28T14:50:04.953Z",
373
+ "custom_field_data": {},
374
+ "description": "",
375
+ "comments": "",
376
+ "transform_map": 10,
377
+ "source_field": "intName",
378
+ "target_field": "name",
379
+ "coalesce": True,
380
+ "template": "",
381
+ },
382
+ },
383
+ {
384
+ "model": "ipfabric_netbox.ipfabrictransformfield",
385
+ "pk": 28,
386
+ "fields": {
387
+ "created": "2023-06-28T15:20:02.726Z",
388
+ "last_updated": "2023-06-28T15:20:08.343Z",
389
+ "custom_field_data": {},
390
+ "description": "",
391
+ "comments": "",
392
+ "transform_map": 11,
393
+ "source_field": "sn",
394
+ "target_field": "serial",
395
+ "coalesce": True,
396
+ "template": "",
397
+ },
398
+ },
399
+ {
400
+ "model": "ipfabric_netbox.ipfabrictransformfield",
401
+ "pk": 29,
402
+ "fields": {
403
+ "created": "2023-06-28T15:20:22.262Z",
404
+ "last_updated": "2023-06-28T15:20:22.262Z",
405
+ "custom_field_data": {},
406
+ "description": "",
407
+ "comments": "",
408
+ "transform_map": 11,
409
+ "source_field": "pid",
410
+ "target_field": "part_id",
411
+ "coalesce": False,
412
+ "template": "",
413
+ },
414
+ },
415
+ {
416
+ "model": "ipfabric_netbox.ipfabrictransformfield",
417
+ "pk": 7,
418
+ "fields": {
419
+ "created": "2023-06-22T09:12:03.027Z",
420
+ "last_updated": "2023-07-14T10:56:34.746Z",
421
+ "custom_field_data": {},
422
+ "description": "",
423
+ "comments": "",
424
+ "transform_map": 4,
425
+ "source_field": "family",
426
+ "target_field": "name",
427
+ "coalesce": False,
428
+ "template": "{%if object.family %}{{ object.family | slugify }}{% else %}{{ object.vendor }}{% endif %}",
429
+ },
430
+ },
431
+ {
432
+ "model": "ipfabric_netbox.ipfabrictransformfield",
433
+ "pk": 35,
434
+ "fields": {
435
+ "created": "2023-07-14T15:38:43.642Z",
436
+ "last_updated": "2023-07-14T15:39:37.833Z",
437
+ "custom_field_data": {},
438
+ "description": "",
439
+ "comments": "",
440
+ "transform_map": 12,
441
+ "source_field": "vlanId",
442
+ "target_field": "vid",
443
+ "coalesce": True,
444
+ "template": "",
445
+ },
446
+ },
447
+ {
448
+ "model": "ipfabric_netbox.ipfabrictransformfield",
449
+ "pk": 36,
450
+ "fields": {
451
+ "created": "2023-07-14T15:39:00.515Z",
452
+ "last_updated": "2023-07-14T15:57:48.819Z",
453
+ "custom_field_data": {},
454
+ "description": "",
455
+ "comments": "",
456
+ "transform_map": 12,
457
+ "source_field": "dscr",
458
+ "target_field": "description",
459
+ "coalesce": False,
460
+ "template": '{{ object.dscr or ""}}',
461
+ },
462
+ },
463
+ {
464
+ "model": "ipfabric_netbox.ipfabrictransformfield",
465
+ "pk": 11,
466
+ "fields": {
467
+ "created": "2023-06-22T09:12:03.112Z",
468
+ "last_updated": "2023-06-22T09:12:03.112Z",
469
+ "custom_field_data": {},
470
+ "description": "",
471
+ "comments": "",
472
+ "transform_map": 5,
473
+ "source_field": "sn",
474
+ "target_field": "serial",
475
+ "coalesce": True,
476
+ "template": "{{ object | serial }}",
477
+ },
478
+ },
479
+ {
480
+ "model": "ipfabric_netbox.ipfabrictransformfield",
481
+ "pk": 37,
482
+ "fields": {
483
+ "created": "2023-07-14T16:39:34.015Z",
484
+ "last_updated": "2023-07-14T16:39:34.015Z",
485
+ "custom_field_data": {},
486
+ "description": "",
487
+ "comments": "",
488
+ "transform_map": 13,
489
+ "source_field": "vrf",
490
+ "target_field": "name",
491
+ "coalesce": True,
492
+ "template": "",
493
+ },
494
+ },
495
+ {
496
+ "model": "ipfabric_netbox.ipfabrictransformfield",
497
+ "pk": 21,
498
+ "fields": {
499
+ "created": "2023-06-28T10:41:03.607Z",
500
+ "last_updated": "2023-08-08T14:44:52.118Z",
501
+ "custom_field_data": {},
502
+ "description": "",
503
+ "comments": "",
504
+ "transform_map": 10,
505
+ "source_field": "mtu",
506
+ "target_field": "mtu",
507
+ "coalesce": False,
508
+ "template": "{{ object.mtu or 1500 }}",
509
+ },
510
+ },
511
+ {
512
+ "model": "ipfabric_netbox.ipfabrictransformfield",
513
+ "pk": 38,
514
+ "fields": {
515
+ "created": "2023-07-14T16:39:57.563Z",
516
+ "last_updated": "2023-07-14T16:44:39.864Z",
517
+ "custom_field_data": {},
518
+ "description": "",
519
+ "comments": "",
520
+ "transform_map": 13,
521
+ "source_field": "rd",
522
+ "target_field": "rd",
523
+ "coalesce": True,
524
+ "template": "",
525
+ },
526
+ },
527
+ {
528
+ "model": "ipfabric_netbox.ipfabrictransformfield",
529
+ "pk": 42,
530
+ "fields": {
531
+ "created": "2023-08-09T12:31:17.235Z",
532
+ "last_updated": "2023-08-09T12:31:17.235Z",
533
+ "custom_field_data": {},
534
+ "description": "",
535
+ "comments": "",
536
+ "transform_map": 5,
537
+ "source_field": "hostname",
538
+ "target_field": "vc_position",
539
+ "coalesce": False,
540
+ "template": "{% if object.virtual_chassis is defined %}{{ object.virtual_chassis.member }}{% else %}None{% endif %}",
541
+ },
542
+ },
543
+ {
544
+ "model": "ipfabric_netbox.ipfabrictransformfield",
545
+ "pk": 10,
546
+ "fields": {
547
+ "created": "2023-06-22T09:12:03.095Z",
548
+ "last_updated": "2023-08-14T09:56:03.044Z",
549
+ "custom_field_data": {},
550
+ "description": "",
551
+ "comments": "",
552
+ "transform_map": 5,
553
+ "source_field": "hostname",
554
+ "target_field": "name",
555
+ "coalesce": False,
556
+ "template": "",
557
+ },
558
+ },
559
+ {
560
+ "model": "ipfabric_netbox.ipfabrictransformfield",
561
+ "pk": 1,
562
+ "fields": {
563
+ "created": "2023-06-22T09:12:02.889Z",
564
+ "last_updated": "2023-07-17T10:08:24.194Z",
565
+ "custom_field_data": {},
566
+ "description": "",
567
+ "comments": "",
568
+ "transform_map": 1,
569
+ "source_field": "siteName",
570
+ "target_field": "name",
571
+ "coalesce": False,
572
+ "template": "",
573
+ },
574
+ },
575
+ {
576
+ "model": "ipfabric_netbox.ipfabrictransformfield",
577
+ "pk": 27,
578
+ "fields": {
579
+ "created": "2023-06-28T15:19:45.005Z",
580
+ "last_updated": "2023-06-28T16:18:37.860Z",
581
+ "custom_field_data": {},
582
+ "description": "",
583
+ "comments": "",
584
+ "transform_map": 11,
585
+ "source_field": "name",
586
+ "target_field": "name",
587
+ "coalesce": False,
588
+ "template": "{% if object.name is not none %}{{ object.name }}{% elif object.dscr is not none %}{{ object.dscr}}{% else %}Default Name{% endif %}",
589
+ },
590
+ },
591
+ {
592
+ "model": "ipfabric_netbox.ipfabrictransformfield",
593
+ "pk": 12,
594
+ "fields": {
595
+ "created": "2023-06-22T09:12:03.144Z",
596
+ "last_updated": "2023-06-22T16:24:30.681Z",
597
+ "custom_field_data": {},
598
+ "description": "",
599
+ "comments": "",
600
+ "transform_map": 6,
601
+ "source_field": "devType",
602
+ "target_field": "name",
603
+ "coalesce": False,
604
+ "template": "",
605
+ },
606
+ },
607
+ {
608
+ "model": "ipfabric_netbox.ipfabrictransformfield",
609
+ "pk": 13,
610
+ "fields": {
611
+ "created": "2023-06-22T09:12:03.161Z",
612
+ "last_updated": "2023-06-22T16:24:34.880Z",
613
+ "custom_field_data": {},
614
+ "description": "",
615
+ "comments": "",
616
+ "transform_map": 6,
617
+ "source_field": "devType",
618
+ "target_field": "slug",
619
+ "coalesce": True,
620
+ "template": "{{ object.devType | slugify }}",
621
+ },
622
+ },
623
+ {
624
+ "model": "ipfabric_netbox.ipfabrictransformfield",
625
+ "pk": 39,
626
+ "fields": {
627
+ "created": "2023-07-18T09:40:37.112Z",
628
+ "last_updated": "2023-07-18T09:41:09.238Z",
629
+ "custom_field_data": {},
630
+ "description": "",
631
+ "comments": "",
632
+ "transform_map": 14,
633
+ "source_field": "net",
634
+ "target_field": "prefix",
635
+ "coalesce": True,
636
+ "template": "",
637
+ },
638
+ },
639
+ {
640
+ "model": "ipfabric_netbox.ipfabrictransformfield",
641
+ "pk": 43,
642
+ "fields": {
643
+ "created": "2023-08-15T14:25:31.706Z",
644
+ "last_updated": "2023-08-15T14:25:31.706Z",
645
+ "custom_field_data": {},
646
+ "description": "",
647
+ "comments": "",
648
+ "transform_map": 10,
649
+ "source_field": "primaryIp",
650
+ "target_field": "mgmt_only",
651
+ "coalesce": False,
652
+ "template": "{% if object.primaryIp == object.loginIp %}True{% else %}False{% endif %}",
653
+ },
654
+ },
655
+ {
656
+ "model": "ipfabric_netbox.ipfabrictransformfield",
657
+ "pk": 5,
658
+ "fields": {
659
+ "created": "2023-06-22T09:12:02.979Z",
660
+ "last_updated": "2023-07-14T13:51:37.370Z",
661
+ "custom_field_data": {},
662
+ "description": "",
663
+ "comments": "",
664
+ "transform_map": 3,
665
+ "source_field": "model",
666
+ "target_field": "model",
667
+ "coalesce": False,
668
+ "template": '{% if object.model|string != ""%}{{ object.model | string }}{% else %}{{ object.vendor }} - {{ object.family }} - {{ object.platform }}{% endif %}',
669
+ },
670
+ },
671
+ {
672
+ "model": "ipfabric_netbox.ipfabrictransformfield",
673
+ "pk": 14,
674
+ "fields": {
675
+ "created": "2023-06-22T09:12:03.177Z",
676
+ "last_updated": "2023-06-22T16:24:48.259Z",
677
+ "custom_field_data": {},
678
+ "description": "",
679
+ "comments": "",
680
+ "transform_map": 6,
681
+ "source_field": "devType",
682
+ "target_field": "vm_role",
683
+ "coalesce": True,
684
+ "template": "False",
685
+ },
686
+ },
687
+ {
688
+ "model": "ipfabric_netbox.ipfabrictransformfield",
689
+ "pk": 44,
690
+ "fields": {
691
+ "created": "2023-08-15T14:38:13.622Z",
692
+ "last_updated": "2023-08-15T20:12:45.341Z",
693
+ "custom_field_data": {},
694
+ "description": "",
695
+ "comments": "",
696
+ "transform_map": 16,
697
+ "source_field": "sn",
698
+ "target_field": "assigned_object_id",
699
+ "coalesce": False,
700
+ "template": "{{ dcim.Interface.objects.filter(device__serial=object.sn, name=object.intName).first().pk }}",
701
+ },
702
+ },
703
+ {
704
+ "model": "ipfabric_netbox.ipfabrictransformfield",
705
+ "pk": 45,
706
+ "fields": {
707
+ "created": "2023-08-15T14:59:24.131Z",
708
+ "last_updated": "2023-08-15T20:26:08.071Z",
709
+ "custom_field_data": {},
710
+ "description": "",
711
+ "comments": "",
712
+ "transform_map": 16,
713
+ "source_field": "net",
714
+ "target_field": "address",
715
+ "coalesce": True,
716
+ "template": "{% if object.net %}{% set MASK = object.net.split('/')[1] %}{% else %}{% set MASK = 32 %}{% endif %}{{ object.ip }}/{{MASK}}",
717
+ },
718
+ },
719
+ ]
720
+
721
+ transform_relationship_fields = [
722
+ {
723
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
724
+ "pk": 21,
725
+ "fields": {
726
+ "created": "2023-07-31T19:48:34.485Z",
727
+ "last_updated": "2023-08-09T10:41:49.273Z",
728
+ "custom_field_data": {},
729
+ "transform_map": 15,
730
+ "source_model": 31,
731
+ "target_field": "master",
732
+ "coalesce": False,
733
+ "template": "{{ dcim.Device.objects.filter(serial=object.sn).first().pk }}",
734
+ },
735
+ },
736
+ {
737
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
738
+ "pk": 3,
739
+ "fields": {
740
+ "created": "2023-06-23T11:01:56.160Z",
741
+ "last_updated": "2023-06-23T11:04:55.366Z",
742
+ "custom_field_data": {},
743
+ "transform_map": 5,
744
+ "source_model": 43,
745
+ "target_field": "platform",
746
+ "coalesce": False,
747
+ "template": None,
748
+ },
749
+ },
750
+ {
751
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
752
+ "pk": 4,
753
+ "fields": {
754
+ "created": "2023-06-23T11:05:37.165Z",
755
+ "last_updated": "2023-06-23T11:05:37.165Z",
756
+ "custom_field_data": {},
757
+ "transform_map": 5,
758
+ "source_model": 56,
759
+ "target_field": "site",
760
+ "coalesce": False,
761
+ "template": None,
762
+ },
763
+ },
764
+ {
765
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
766
+ "pk": 5,
767
+ "fields": {
768
+ "created": "2023-06-23T11:07:26.908Z",
769
+ "last_updated": "2023-06-23T11:07:26.908Z",
770
+ "custom_field_data": {},
771
+ "transform_map": 5,
772
+ "source_model": 35,
773
+ "target_field": "device_type",
774
+ "coalesce": False,
775
+ "template": None,
776
+ },
777
+ },
778
+ {
779
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
780
+ "pk": 6,
781
+ "fields": {
782
+ "created": "2023-06-23T11:11:42.914Z",
783
+ "last_updated": "2023-06-23T11:11:42.914Z",
784
+ "custom_field_data": {},
785
+ "transform_map": 5,
786
+ "source_model": 34,
787
+ "target_field": "device_role",
788
+ "coalesce": False,
789
+ "template": None,
790
+ },
791
+ },
792
+ {
793
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
794
+ "pk": 7,
795
+ "fields": {
796
+ "created": "2023-06-23T13:42:05.285Z",
797
+ "last_updated": "2023-06-23T13:42:05.285Z",
798
+ "custom_field_data": {},
799
+ "transform_map": 3,
800
+ "source_model": 42,
801
+ "target_field": "manufacturer",
802
+ "coalesce": False,
803
+ "template": None,
804
+ },
805
+ },
806
+ {
807
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
808
+ "pk": 9,
809
+ "fields": {
810
+ "created": "2023-06-23T14:17:57.664Z",
811
+ "last_updated": "2023-06-23T14:17:57.664Z",
812
+ "custom_field_data": {},
813
+ "transform_map": 4,
814
+ "source_model": 42,
815
+ "target_field": "manufacturer",
816
+ "coalesce": False,
817
+ "template": None,
818
+ },
819
+ },
820
+ {
821
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
822
+ "pk": 22,
823
+ "fields": {
824
+ "created": "2023-08-09T12:39:35.028Z",
825
+ "last_updated": "2023-08-09T12:39:35.028Z",
826
+ "custom_field_data": {},
827
+ "transform_map": 5,
828
+ "source_model": 58,
829
+ "target_field": "virtual_chassis",
830
+ "coalesce": False,
831
+ "template": "{% if object.virtual_chassis is defined %}{{ dcim.VirtualChassis.objects.filter(name=object.virtual_chassis.master).first().pk }}{% endif %}",
832
+ },
833
+ },
834
+ {
835
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
836
+ "pk": 11,
837
+ "fields": {
838
+ "created": "2023-06-28T11:00:44.494Z",
839
+ "last_updated": "2023-06-28T14:37:54.113Z",
840
+ "custom_field_data": {},
841
+ "transform_map": 10,
842
+ "source_model": 31,
843
+ "target_field": "device",
844
+ "coalesce": True,
845
+ "template": None,
846
+ },
847
+ },
848
+ {
849
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
850
+ "pk": 12,
851
+ "fields": {
852
+ "created": "2023-06-28T15:19:18.237Z",
853
+ "last_updated": "2023-06-28T15:19:18.237Z",
854
+ "custom_field_data": {},
855
+ "transform_map": 11,
856
+ "source_model": 42,
857
+ "target_field": "manufacturer",
858
+ "coalesce": False,
859
+ "template": None,
860
+ },
861
+ },
862
+ {
863
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
864
+ "pk": 13,
865
+ "fields": {
866
+ "created": "2023-06-28T15:19:35.397Z",
867
+ "last_updated": "2023-07-14T14:15:42.974Z",
868
+ "custom_field_data": {},
869
+ "transform_map": 11,
870
+ "source_model": 31,
871
+ "target_field": "device",
872
+ "coalesce": False,
873
+ "template": None,
874
+ },
875
+ },
876
+ {
877
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
878
+ "pk": 14,
879
+ "fields": {
880
+ "created": "2023-07-14T15:39:27.858Z",
881
+ "last_updated": "2023-07-14T15:39:27.858Z",
882
+ "custom_field_data": {},
883
+ "transform_map": 12,
884
+ "source_model": 56,
885
+ "target_field": "site",
886
+ "coalesce": True,
887
+ "template": None,
888
+ },
889
+ },
890
+ {
891
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
892
+ "pk": 23,
893
+ "fields": {
894
+ "created": "2023-08-15T14:48:42.409Z",
895
+ "last_updated": "2023-08-15T20:24:33.161Z",
896
+ "custom_field_data": {},
897
+ "transform_map": 16,
898
+ "source_model": 5,
899
+ "target_field": "assigned_object_type",
900
+ "coalesce": False,
901
+ "template": '{{ contenttypes.ContentType.objects.get(app_label="dcim", model="interface").pk }}',
902
+ },
903
+ },
904
+ {
905
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
906
+ "pk": 24,
907
+ "fields": {
908
+ "created": "2023-08-15T21:44:41.058Z",
909
+ "last_updated": "2023-08-15T21:47:26.684Z",
910
+ "custom_field_data": {},
911
+ "transform_map": 16,
912
+ "source_model": 73,
913
+ "target_field": "vrf",
914
+ "coalesce": False,
915
+ "template": "{{ ipam.VRF.objects.filter(name=object.vrf).first().pk }}",
916
+ },
917
+ },
918
+ {
919
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
920
+ "pk": 15,
921
+ "fields": {
922
+ "created": "2023-07-18T09:40:50.275Z",
923
+ "last_updated": "2023-08-15T21:53:36.179Z",
924
+ "custom_field_data": {},
925
+ "transform_map": 14,
926
+ "source_model": 56,
927
+ "target_field": "site",
928
+ "coalesce": True,
929
+ "template": "{% set SLUG = object.siteName | slugify %}\r\n{{ dcim.Site.objects.filter(slug=SLUG).first().pk }}",
930
+ },
931
+ },
932
+ {
933
+ "model": "ipfabric_netbox.ipfabricrelationshipfield",
934
+ "pk": 17,
935
+ "fields": {
936
+ "created": "2023-07-18T21:19:36.757Z",
937
+ "last_updated": "2023-07-18T21:19:44.148Z",
938
+ "custom_field_data": {},
939
+ "transform_map": 14,
940
+ "source_model": 73,
941
+ "target_field": "vrf",
942
+ "coalesce": True,
943
+ "template": "{{ ipam.VRF.objects.filter(name=object.vrf).first().pk }}",
944
+ },
945
+ },
946
+ ]
947
+
948
+
949
+ class IPFabricTransformMapModelTestCase(TestCase):
950
+ def setUp(self):
951
+ deserialized_tm = serializers.deserialize("json", json.dumps(transform_maps))
952
+ for deserialized_object in deserialized_tm:
953
+ deserialized_object.save()
954
+
955
+ deserialized_tf = serializers.deserialize("json", json.dumps(transform_fields))
956
+ for deserialized_object in deserialized_tf:
957
+ deserialized_object.save()
958
+
959
+ deserialized_trf = serializers.deserialize(
960
+ "json", json.dumps(transform_relationship_fields)
961
+ )
962
+ for deserialized_object in deserialized_trf:
963
+ deserialized_object.save()
964
+
965
+ source = IPFabricSource.objects.create(
966
+ name="test",
967
+ url="https://localhost",
968
+ status="new",
969
+ parameters={"auth": "token123", "verify": True},
970
+ )
971
+ snapshot = IPFabricSnapshot.objects.create(
972
+ name="S01 - Day 2 - IPF Lab - 02-Jul-21 06:29:16 - 12dd8c61-129c-431a-b98b-4c9211571f89",
973
+ source=source,
974
+ snapshot_id="12dd8c61-129c-431a-b98b-4c9211571f89",
975
+ data={
976
+ "end": "2021-07-02T06:29:16.311000Z",
977
+ "name": "S01 - Day 2 - IPF Lab",
978
+ "note": "Multi-Environment containing:\\nAWS, Azure, ACI, NSX-T, Viptela, Versa, SilverPeak, Meraki\\n\\nSite 48 - devices added, NTP issue\\nSite 68 &38 - NTP update\\nSite 38 - resiliency affected (no ospfx2 - no L1 link x1) + passive interfaces FIXED / NTP partial update\\n?E2E: 38 - 66 - migration HTTP to HTTPS\\n?Site 66 - FW bypass E2E\\nVRRP improvements (LAB1 / L52)",
979
+ "sites": [
980
+ "35COLO",
981
+ "35HEADOFFICE",
982
+ "35PRODUCTION",
983
+ "35SALES",
984
+ "38 Pilsen DR",
985
+ "66 Ostrava DC",
986
+ "68 Pardubice Distribution",
987
+ "ACI",
988
+ "AWS_SITE",
989
+ "AZURE",
990
+ "HWLAB",
991
+ "L31",
992
+ "L33",
993
+ "L34",
994
+ "L35",
995
+ "L36",
996
+ "L37",
997
+ "L39",
998
+ "L43",
999
+ "L45",
1000
+ "L46",
1001
+ "L47",
1002
+ "L48",
1003
+ "L49",
1004
+ "L51",
1005
+ "L52",
1006
+ "L62",
1007
+ "L63",
1008
+ "L64",
1009
+ "L65",
1010
+ "L67",
1011
+ "L71",
1012
+ "L72",
1013
+ "L77",
1014
+ "L81",
1015
+ "LAB01",
1016
+ "MERAKI_SITE",
1017
+ "MPLS",
1018
+ "NSX-T",
1019
+ "SILVERPEAK",
1020
+ "VERSA_SITE",
1021
+ "VIPTELA",
1022
+ ],
1023
+ "start": "2021-07-02T06:00:00.930000Z",
1024
+ "change": "2022-03-25T14:35:48.277000Z",
1025
+ "errors": [
1026
+ {"count": 2, "error_type": "ABMapResultError"},
1027
+ {"count": 5, "error_type": "ABParseError"},
1028
+ {"count": 3, "error_type": "ABTaskMapResultError"},
1029
+ {"count": 1, "error_type": "ABAmbiguousCommand"},
1030
+ {"count": 7, "error_type": "ABCmdAuthFail"},
1031
+ {"count": 6, "error_type": "ABCommandTimeout"},
1032
+ {"count": 1, "error_type": "ABNoConfig"},
1033
+ {"count": 1, "error_type": "ABParseBadConfigError"},
1034
+ {"count": 1, "error_type": "ABTaskMapResultBadConfigError"},
1035
+ {"count": 1, "error_type": "ABWorkerAuthError"},
1036
+ ],
1037
+ "locked": False,
1038
+ "status": "done",
1039
+ "loading": False,
1040
+ "version": "6.3.0-13",
1041
+ "user_count": 2324,
1042
+ "loaded_size": 170856074,
1043
+ "snapshot_id": "12dd8c61-129c-431a-b98b-4c9211571f89",
1044
+ "from_archive": True,
1045
+ "finish_status": "done",
1046
+ "unloaded_size": 26914884,
1047
+ "initial_version": "4.4.3+2",
1048
+ "interface_count": 9608,
1049
+ "total_dev_count": 729,
1050
+ "creator_username": None,
1051
+ "device_added_count": 0,
1052
+ "licensed_dev_count": 720,
1053
+ "device_removed_count": 0,
1054
+ "disabled_graph_cache": False,
1055
+ "interface_edge_count": 534,
1056
+ "interface_active_count": 6379,
1057
+ "disabled_historical_data": False,
1058
+ "disabled_intent_verification": False,
1059
+ },
1060
+ last_updated=timezone.now(),
1061
+ )
1062
+ sync = IPFabricSync.objects.create(
1063
+ name="ingest",
1064
+ type="dcim",
1065
+ status="new",
1066
+ snapshot_data=snapshot,
1067
+ parameters={
1068
+ "vrf": False,
1069
+ "site": True,
1070
+ "vlan": False,
1071
+ "sites": [],
1072
+ "device": True,
1073
+ "prefix": False,
1074
+ "platform": True,
1075
+ "interface": False,
1076
+ "ipaddress": False,
1077
+ "devicerole": True,
1078
+ "devicetype": True,
1079
+ "manufacturer": True,
1080
+ "virtualchassis": False,
1081
+ },
1082
+ )
1083
+
1084
+ runner = IPFabricSyncRunner(
1085
+ transform_map=IPFabricTransformMap,
1086
+ settings={
1087
+ "site": True,
1088
+ "sites": [],
1089
+ "device": True,
1090
+ "platform": True,
1091
+ "interface": False,
1092
+ "devicerole": True,
1093
+ "devicetype": True,
1094
+ "manufacturer": True,
1095
+ "virtualchassis": True,
1096
+ "snapshot_id": "12dd8c61-129c-431a-b98b-4c9211571f89",
1097
+ },
1098
+ sync=sync,
1099
+ )
1100
+ device_uuid = str(uuid.uuid4())
1101
+
1102
+ site_data = {
1103
+ "siteName": "Site 1",
1104
+ "devicesCount": 1,
1105
+ "usersCount": 2,
1106
+ "stpDCount": 0,
1107
+ "switchesCount": 0,
1108
+ "vlanCount": 1,
1109
+ "rDCount": 0,
1110
+ "routersCount": 0,
1111
+ "networksCount": 6,
1112
+ }
1113
+
1114
+ self.site = runner.get_model_or_update(
1115
+ "dcim", "site", site_data, uuid=device_uuid
1116
+ )
1117
+
1118
+ device_data = {
1119
+ "id": "961251111",
1120
+ "configReg": "0x0",
1121
+ "devType": "router",
1122
+ "family": "ios",
1123
+ "hostname": "L21PE152",
1124
+ "hostnameOriginal": None,
1125
+ "hostnameProcessed": None,
1126
+ "domain": None,
1127
+ "fqdn": None,
1128
+ "icon": None,
1129
+ "image": "unix:/opt/unetlab/addons/iol/bin/i86bi-linux-l3-adventerprisek9-15.2",
1130
+ "objectId": None,
1131
+ "taskKey": "fb67e3b4-5e48-4e52-b000-56cb187f2852",
1132
+ "loginIp": "10.21.254.152",
1133
+ "loginType": "telnet",
1134
+ "loginPort": None,
1135
+ "mac": None,
1136
+ "memoryTotalBytes": 396008048,
1137
+ "memoryUsedBytes": 72264172,
1138
+ "memoryUtilization": 18.25,
1139
+ "model": "",
1140
+ "platform": "i86bi_linux",
1141
+ "processor": "Intel-x86",
1142
+ "rd": "3",
1143
+ "reload": "reload at 0",
1144
+ "siteName": "MPLS",
1145
+ "sn": "a15ff98",
1146
+ "snHw": "a15ff98",
1147
+ "stpDomain": None,
1148
+ "uptime": 7254180,
1149
+ "vendor": "cisco",
1150
+ "version": "15.2(4)M1",
1151
+ "slug": None,
1152
+ }
1153
+
1154
+ self.mf_obj = runner.get_model_or_update(
1155
+ "dcim", "manufacturer", device_data, uuid=device_uuid
1156
+ )
1157
+ self.dt_obj = runner.get_model_or_update(
1158
+ "dcim", "devicetype", device_data, uuid=device_uuid
1159
+ )
1160
+
1161
+ self.platform = runner.get_model_or_update(
1162
+ "dcim", "platform", device_data, uuid=device_uuid
1163
+ )
1164
+
1165
+ self.device_role = runner.get_model_or_update(
1166
+ "dcim", "devicerole", device_data, uuid=device_uuid
1167
+ )
1168
+
1169
+ self.device_object = runner.get_model_or_update(
1170
+ "dcim", "device", device_data, uuid=device_uuid
1171
+ )
1172
+
1173
+ def test_transform_map(self):
1174
+ site_transform_map = IPFabricTransformMap.objects.get(name="Site Transform Map")
1175
+ self.assertEqual(site_transform_map.name, "Site Transform Map")
1176
+ self.assertEqual(site_transform_map.source_model, "site")
1177
+ self.assertEqual(site_transform_map.status, "active")
1178
+ self.assertEqual(
1179
+ site_transform_map.target_model,
1180
+ ContentType.objects.filter(app_label="dcim", model="site")[0],
1181
+ )
1182
+
1183
+ def test_transform_field(self):
1184
+ site_transform_map = IPFabricTransformMap.objects.get(name="Site Transform Map")
1185
+ site_slug_field = IPFabricTransformField.objects.get(
1186
+ source_field="siteName",
1187
+ target_field="slug",
1188
+ transform_map=site_transform_map,
1189
+ )
1190
+ self.assertEqual(site_slug_field.source_field, "siteName")
1191
+ self.assertEqual(site_slug_field.target_field, "slug")
1192
+ self.assertEqual(site_slug_field.template, "{{ object.siteName | slugify }}")
1193
+ self.assertEqual(site_slug_field.transform_map, site_transform_map)
1194
+ site_name_field = IPFabricTransformField.objects.get(
1195
+ source_field="siteName",
1196
+ target_field="name",
1197
+ transform_map=site_transform_map,
1198
+ )
1199
+ self.assertEqual(site_name_field.source_field, "siteName")
1200
+ self.assertEqual(site_name_field.target_field, "name")
1201
+ self.assertEqual(site_name_field.template, "")
1202
+ self.assertEqual(site_name_field.transform_map, site_transform_map)
1203
+
1204
+ def test_transform_map_serialization(self):
1205
+ site_transform_map = IPFabricTransformMap.objects.get(name="Site Transform Map")
1206
+ data = serializers.serialize("json", [site_transform_map])
1207
+ data = json.loads(data)[0]
1208
+ test_data = {
1209
+ "model": "ipfabric_netbox.ipfabrictransformmap",
1210
+ "pk": site_transform_map.pk,
1211
+ "fields": {
1212
+ "name": "Site Transform Map",
1213
+ "source_model": "site",
1214
+ "target_model": 56,
1215
+ "status": "active",
1216
+ },
1217
+ }
1218
+ new_data = copy.deepcopy(data)
1219
+ new_data.pop("fields")
1220
+ new_fields = {}
1221
+ for k in test_data["fields"]:
1222
+ new_fields[k] = data["fields"][k]
1223
+ new_data["fields"] = new_fields
1224
+ self.assertDictEqual(test_data, new_data)
1225
+
1226
+ def test_transform_field_serialization(self):
1227
+ site_transform_map = IPFabricTransformMap.objects.get(name="Site Transform Map")
1228
+ site_slug_field = IPFabricTransformField.objects.get(
1229
+ source_field="siteName", target_field="slug"
1230
+ )
1231
+ data = serializers.serialize("json", [site_slug_field])
1232
+ data = json.loads(data)[0]
1233
+ test_data = {
1234
+ "model": "ipfabric_netbox.ipfabrictransformfield",
1235
+ "pk": site_slug_field.pk,
1236
+ "fields": {
1237
+ "source_field": "siteName",
1238
+ "target_field": "slug",
1239
+ "template": "{{ object.siteName | slugify }}",
1240
+ "transform_map": site_transform_map.pk,
1241
+ },
1242
+ }
1243
+ new_data = copy.deepcopy(data)
1244
+ new_data.pop("fields")
1245
+ new_data["fields"] = {k: data["fields"][k] for k in test_data["fields"]}
1246
+ self.assertDictEqual(test_data, new_data)
1247
+
1248
+ def test_update_or_create_instance_site(self):
1249
+ site_transform_map = IPFabricTransformMap.objects.get(name="Site Transform Map")
1250
+ data = {
1251
+ "siteName": "Site 1",
1252
+ "devicesCount": 1,
1253
+ "usersCount": 2,
1254
+ "stpDCount": 0,
1255
+ "switchesCount": 0,
1256
+ "vlanCount": 1,
1257
+ "rDCount": 0,
1258
+ "routersCount": 0,
1259
+ "networksCount": 6,
1260
+ }
1261
+ object = site_transform_map.update_or_create_instance(data=data)
1262
+ self.assertEqual(object.name, "Site 1")
1263
+ self.assertEqual(object.slug, "site-1")
1264
+
1265
+ def test_update_or_create_instance_device(self):
1266
+ device_object = Device.objects.first()
1267
+
1268
+ self.assertEqual(device_object.name, "L21PE152")
1269
+ self.assertEqual(device_object.serial, "a15ff98")
1270
+ self.assertEqual(device_object.platform, self.platform)
1271
+ self.assertEqual(device_object.device_role, self.device_role)
1272
+ self.assertEqual(device_object.device_type, self.dt_obj)
1273
+ self.assertEqual(device_object.device_type.manufacturer, self.mf_obj)
1274
+ self.assertEqual(device_object.site, self.site)
1275
+ self.assertEqual(device_object.status, "active")
1276
+
1277
+ def test_alter_transform_field_template(self):
1278
+ sync = IPFabricSync.objects.get(name="ingest")
1279
+
1280
+ runner = IPFabricSyncRunner(
1281
+ transform_map=IPFabricTransformMap,
1282
+ settings={
1283
+ "site": True,
1284
+ "sites": [],
1285
+ "device": True,
1286
+ "platform": True,
1287
+ "interface": False,
1288
+ "devicerole": True,
1289
+ "devicetype": True,
1290
+ "manufacturer": True,
1291
+ "virtualchassis": True,
1292
+ "snapshot_id": "12dd8c61-129c-431a-b98b-4c9211571f89",
1293
+ },
1294
+ sync=sync,
1295
+ )
1296
+ device_uuid = str(uuid.uuid4())
1297
+
1298
+ device_data = {
1299
+ "id": "961251111",
1300
+ "configReg": "0x0",
1301
+ "devType": "router",
1302
+ "family": "ios",
1303
+ "hostname": "L21PE152",
1304
+ "hostnameOriginal": None,
1305
+ "hostnameProcessed": None,
1306
+ "domain": None,
1307
+ "fqdn": None,
1308
+ "icon": None,
1309
+ "image": "unix:/opt/unetlab/addons/iol/bin/i86bi-linux-l3-adventerprisek9-15.2",
1310
+ "objectId": None,
1311
+ "taskKey": "fb67e3b4-5e48-4e52-b000-56cb187f2852",
1312
+ "loginIp": "10.21.254.152",
1313
+ "loginType": "telnet",
1314
+ "loginPort": None,
1315
+ "mac": None,
1316
+ "memoryTotalBytes": 396008048,
1317
+ "memoryUsedBytes": 72264172,
1318
+ "memoryUtilization": 18.25,
1319
+ "model": "",
1320
+ "platform": "i86bi_linux",
1321
+ "processor": "Intel-x86",
1322
+ "rd": "3",
1323
+ "reload": "reload at 0",
1324
+ "siteName": "MPLS",
1325
+ "sn": "a15ff98",
1326
+ "snHw": "a15ff98",
1327
+ "stpDomain": None,
1328
+ "uptime": 7254180,
1329
+ "vendor": "cisco",
1330
+ "version": "15.2(4)M1",
1331
+ "slug": None,
1332
+ }
1333
+
1334
+ transform_field = IPFabricTransformField.objects.get(pk=10)
1335
+ transform_field.template = "{{ object.hostname }} - test"
1336
+ transform_field.save()
1337
+ device_object = runner.get_model_or_update(
1338
+ "dcim", "device", device_data, uuid=device_uuid
1339
+ )
1340
+ self.assertEqual(device_object.name, "L21PE152 - test")