nornir-collection 0.0.23__py3-none-any.whl → 0.0.25__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.
@@ -360,6 +360,71 @@ def nc_edit_cleanup_svi(task: Task, verbose: bool = False) -> Result:
360
360
  return Result(host=task.host, custom_result=custom_result, failed=task_failed)
361
361
 
362
362
 
363
+ def nc_edit_cleanup_vlan(task: Task, verbose: bool = False) -> Result:
364
+ """
365
+ TBD
366
+ """
367
+ # The custom_result list will be filled with the results
368
+ custom_result = []
369
+
370
+ #### Get all current configured VLANs with RESTCONF #####################################################
371
+
372
+ task_text = "RESTCONF GET VLANs"
373
+
374
+ # Set the RESTCONF port, yang query and url to get all configured SVIs
375
+ yang_query = "Cisco-IOS-XE-native:native/vlan/Cisco-IOS-XE-vlan:vlan-list"
376
+ url = f"https://{task.host.hostname}:443/restconf/data/{yang_query}"
377
+
378
+ # RESTCONF HTTP Get for all SVIs
379
+ response = rc_cisco_get(url=url, auth=(task.host.username, task.host.password), verify=False)
380
+
381
+ # Set the RESTCONF result and return the Nornir result if the RESTCONF response status_code is not 200
382
+ custom_result = set_restconf_result(
383
+ task=Task,
384
+ task_text=task_text,
385
+ yang_query=yang_query,
386
+ response=response,
387
+ custom_result=custom_result,
388
+ verbose=verbose,
389
+ )
390
+
391
+ # Create a list with all current configured VLANs except the default VLAN 1
392
+ current_vlans = [x for x in response["json"]["Cisco-IOS-XE-vlan:vlan-list"] if x["id"] != 1]
393
+
394
+ #### Render NETCONF payload to remove VLANs with Jinja2 #################################################
395
+
396
+ task_text = "Render Jinja2 NETCONF payload"
397
+ # Create a list with all configured VLANs which are not part of the inventory
398
+ remove_vlans = [x for x in current_vlans if x["id"] not in [x["vid"] for x in task.host["cfg_vlans"]]]
399
+
400
+ # If there are no VLANs to remove, return the Nornir result
401
+ if not remove_vlans:
402
+ custom_result.append(
403
+ f"{task_result(text=task_text, changed=False, level_name='INFO', failed=False)}\n"
404
+ + f"'{task_text}' -> NornirResponse <Success: True>\n"
405
+ + "-> No VLANs to remove"
406
+ )
407
+ return Result(host=task.host, custom_result=custom_result, failed=False)
408
+
409
+ # Set the info message for the Nornir result
410
+ info_msg = f"VLANs to remove: {len(remove_vlans)}"
411
+
412
+ # Render the Jinja2 payload template and configure the NETCONF candidate datastore
413
+ custom_result, task_failed = netconf_configure_jinja2_rendered_payload_template(
414
+ task=task,
415
+ j2_task_text=task_text,
416
+ j2_tpl_path="iosxe_netconf/tpl_sys/cleanup/cleanup_vlan.j2",
417
+ custom_result=custom_result,
418
+ task_failed=False,
419
+ info_msg=info_msg,
420
+ verbose=verbose,
421
+ j2_kwargs={"remove_vlans": remove_vlans},
422
+ )
423
+
424
+ # Return the Nornir NETCONF result
425
+ return Result(host=task.host, custom_result=custom_result, failed=task_failed)
426
+
427
+
363
428
  def nc_edit_tpl_config(task: Task, tpl_startswith: str, verbose: bool = False) -> Result:
364
429
  """
365
430
  TBD
@@ -477,7 +542,6 @@ def nc_cfg_cleanup(nr: Nornir, cfg_status: bool = True, verbose: bool = False) -
477
542
  """
478
543
  TBD
479
544
  """
480
-
481
545
  # Return False if cfg_status argument is False
482
546
  if not cfg_status:
483
547
  return False
@@ -485,6 +549,7 @@ def nc_cfg_cleanup(nr: Nornir, cfg_status: bool = True, verbose: bool = False) -
485
549
  tasks = {
486
550
  nc_edit_cleanup_portchannel: "NETCONF portchannel cleanup",
487
551
  nc_edit_cleanup_svi: "NETCONF vlan interface cleanup",
552
+ nc_edit_cleanup_vlan: "NETCONF vlan cleanup",
488
553
  }
489
554
 
490
555
  # Run each task from the Nornir tasks list
@@ -91,8 +91,8 @@ def _load_interface_data(task: Task, all_interfaces: List[Dict], enrich_vlan_dat
91
91
  # Dict keys for comprehension to include only some key-value pairs
92
92
  # fmt: off
93
93
  include_keys = [
94
- "name", "int_template", "description", "type", "lag", "count_ipaddresses",
95
- "count_fhrp_groups", "int_peer_device", "int_config_context", "enabled",
94
+ "name", "int_template", "description", "type", "lag", "mode", "untagged_vlan", "tagged_vlans",
95
+ "count_ipaddresses", "count_fhrp_groups", "int_peer_device", "int_config_context", "enabled",
96
96
  ]
97
97
  # fmt: on
98
98
  # Make some normalization to the device interfaces data with the interface_filter list and others
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: nornir-collection
3
- Version: 0.0.23
3
+ Version: 0.0.25
4
4
  Summary: Nornir-Collection contains network automation functions and complete IaC workflows with Nornir and other python libraries. It contains Nornir tasks and general functions in Nornir style.
5
5
  Author: Willi Kubny
6
6
  Author-email: willi.kubny@gmail.ch
@@ -47,6 +47,7 @@ Dynamic: author-email
47
47
  Dynamic: classifier
48
48
  Dynamic: description
49
49
  Dynamic: description-content-type
50
+ Dynamic: license-file
50
51
  Dynamic: requires-dist
51
52
  Dynamic: requires-python
52
53
  Dynamic: summary
@@ -14,7 +14,7 @@ nornir_collection/cisco/configuration_management/cli/config_tasks.py,sha256=mWXy
14
14
  nornir_collection/cisco/configuration_management/cli/config_workflow.py,sha256=GIka5SPLZ7M2zCFv8Jadl73QC-InnGopzI8xQt36MfM,3459
15
15
  nornir_collection/cisco/configuration_management/cli/show_tasks.py,sha256=w9p2Iks33-pE4-YztH6vj-eI0MuPI7YD6gZhRcpQF7M,27971
16
16
  nornir_collection/cisco/configuration_management/netconf/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
- nornir_collection/cisco/configuration_management/netconf/config_tasks.py,sha256=wcrAuijvMZMe7dbGwtKzRgAlWsbxVJSup65yJda_930,22995
17
+ nornir_collection/cisco/configuration_management/netconf/config_tasks.py,sha256=V1goW79OWxA7kNle4M2NzK47TZLw7TGji-2QaTiviSI,25696
18
18
  nornir_collection/cisco/configuration_management/netconf/config_workflow.py,sha256=qxB4DolQL2WJO9JRATzANhIwYPNuKyuN0hI9-ABzJq8,14557
19
19
  nornir_collection/cisco/configuration_management/netconf/nr_cfg_iosxe_netconf.py,sha256=qKb1EeiYbCO96AE6ETaNxRrM2nCfsbX00nwcPK9ZSkc,8629
20
20
  nornir_collection/cisco/configuration_management/netconf/ops_tasks.py,sha256=cj7cpJNvY2bytv9VOqwg_7qOekL-cIL0EjML2KT4TQM,10659
@@ -35,7 +35,7 @@ nornir_collection/fortinet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJ
35
35
  nornir_collection/fortinet/utils.py,sha256=xkvxdJy3-aD39WK_9Gc0rY9r-OxfHnPVNMspy3KZbcE,1174
36
36
  nornir_collection/netbox/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  nornir_collection/netbox/custom_script.py,sha256=yU1lbv_25b3qAWA6GRsVYpEuh0KUPTVo47U5s_lksjo,4050
38
- nornir_collection/netbox/inventory.py,sha256=2db5GogMsY5bZgc4mXIhlmH9pcvyQ7AE55dL0EiqxDI,15488
38
+ nornir_collection/netbox/inventory.py,sha256=uDA8QOBZdg42hROki41fKYtA1g3Ev4wFhGDo-Y0l9Fo,15529
39
39
  nornir_collection/netbox/set_device_status.py,sha256=vtn0KcR-91Z2aLjbEpZRef1Jip8eM9GWbKRiAJuEjLY,2437
40
40
  nornir_collection/netbox/sync_datasource.py,sha256=eEsgwy_arIPbA-ObqqzTNdU9aiP80s7LCzAKA6hCXYQ,4703
41
41
  nornir_collection/netbox/update_cisco_inventory_data.py,sha256=Aq4VGvAIiBhOCsSOF-wBUrpYtBXR8HwR3NCWEeM4d0g,6426
@@ -52,8 +52,8 @@ nornir_collection/nornir_plugins/inventory/staggered_yaml.py,sha256=nBvUFq7U5zVT
52
52
  nornir_collection/nornir_plugins/inventory/utils.py,sha256=mxIlKK-4PHqCnFKn7Oozu1RW_JB5z1TgEYc-ave70nE,11822
53
53
  nornir_collection/purestorage/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  nornir_collection/purestorage/utils.py,sha256=TqU2sKz0ENnmSDEBcSvXPnVkI1DVHOogI68D7l32g7I,1730
55
- nornir_collection-0.0.23.dist-info/LICENSE,sha256=bOPVh1OVNwz2tCjkLaChWT6AoXdtqye3aua5l0tgYJo,1068
56
- nornir_collection-0.0.23.dist-info/METADATA,sha256=2pKMwHDmdthAjlvEixjw5ZWVqfGfHNS4NE7Nnyk_2DE,7169
57
- nornir_collection-0.0.23.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
58
- nornir_collection-0.0.23.dist-info/top_level.txt,sha256=OyCzPWABf-D0AOHm9ihrwdk5eq200BnKna6gIDspwsE,18
59
- nornir_collection-0.0.23.dist-info/RECORD,,
55
+ nornir_collection-0.0.25.dist-info/licenses/LICENSE,sha256=bOPVh1OVNwz2tCjkLaChWT6AoXdtqye3aua5l0tgYJo,1068
56
+ nornir_collection-0.0.25.dist-info/METADATA,sha256=zoBgfwLBq-6GhxNSle_4AePSBf4Y35vlOMcgu4zShMc,7191
57
+ nornir_collection-0.0.25.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
58
+ nornir_collection-0.0.25.dist-info/top_level.txt,sha256=OyCzPWABf-D0AOHm9ihrwdk5eq200BnKna6gIDspwsE,18
59
+ nornir_collection-0.0.25.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.0.0)
2
+ Generator: setuptools (77.0.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5