nornir-collection 0.0.14__py3-none-any.whl → 0.0.16__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.
@@ -304,32 +304,40 @@ def nmap_scan_prefix(prefix: dict, result: list) -> tuple:
304
304
  return result, prefix
305
305
 
306
306
 
307
- def get_ipfabric_data_for_prefix(prefix: dict, result: list) -> tuple:
307
+ def get_ipfabric_data_for_prefix(ipf: IPFClient, prefix: dict, result: list) -> tuple:
308
308
  """
309
309
  TBD
310
310
  """
311
- # Connect to IP-Fabric
312
- ipf = IPFClient(
313
- base_url=os.environ["IPF_URL"], auth=os.environ["IPF_TOKEN"], snapshot_id="$last", verify=False
314
- )
315
-
316
311
  # Get the prefix length from the prefix
317
312
  prefixlen = ipaddress.ip_network(prefix["prefix"]).prefixlen
318
313
  # Get all ip-addresses of the prefix from the IP-Fabric technology arp table
319
314
  # Remove duplicate ip-addresses as the arp table can contain multiple entries for the same ip-address
320
315
  filters = {"ip": ["cidr", prefix["prefix"]]}
321
- all_ips = list(set([x["ip"] for x in ipf.technology.addressing.arp_table.all(filters=filters)]))
316
+ arp_ip_list = list(set([x["ip"] for x in ipf.technology.addressing.arp_table.all(filters=filters)]))
317
+ # Get all ip-addresses of the prefix from the IP-Fabric inventory managed ipv4 table
318
+ managed_ipv4_ip_list = list(
319
+ set([x["ip"] for x in ipf.technology.addressing.managed_ip_ipv4.all(filters=filters, columns=["ip"])])
320
+ )
321
+ # Get all ip-addresses of the prefix from the IP-Fabric inventory interface table
322
+ filters = {"loginIp": ["cidr", prefix["prefix"]]}
323
+ interface_ip_list = list(
324
+ set([x["loginIp"] for x in ipf.inventory.interfaces.all(filters=filters, columns=["loginIp"])])
325
+ )
322
326
  # Get all ip-addresses of the prefix from the IP-Fabric inventory hosts table
323
327
  # Set the ip-address as key to access the dict easier later
328
+ filters = {"ip": ["cidr", prefix["prefix"]]}
324
329
  columns = ["ip", "dnsName"]
325
- host_ips = {
330
+ host_ip_dict = {
326
331
  x["ip"]: x["dnsName"] or "" for x in ipf.inventory.hosts.all(filters=filters, columns=columns)
327
332
  }
333
+ host_ip_list = list(host_ip_dict.keys())
334
+ # Combine all ip-addresses lists and remove duplicates
335
+ all_ips = list(set(arp_ip_list + managed_ipv4_ip_list + interface_ip_list + host_ip_list))
328
336
  # Add a list of all ip-addresses and other details to prefix
329
337
  prefix["datasource_ips"] = [
330
338
  {
331
339
  "address": f"{ip}/{prefixlen}",
332
- "dns_name": host_ips[ip] if ip in host_ips.keys() else "",
340
+ "dns_name": host_ip_dict[ip] if ip in host_ip_dict.keys() else "",
333
341
  "ports": {},
334
342
  }
335
343
  for ip in all_ips
@@ -368,8 +376,12 @@ def get_nb_ips_and_external_datasource(nb_url: str, prefix: dict, ds: Literal["n
368
376
  # Scan the prefix with nmap
369
377
  result, prefix = nmap_scan_prefix(prefix=prefix, result=result)
370
378
  elif ds == "ip-fabric":
379
+ # Connect to IP-Fabric
380
+ ipf = IPFClient(
381
+ base_url=os.environ["IPF_URL"], auth=os.environ["IPF_TOKEN"], snapshot_id="$last", verify=False
382
+ )
371
383
  # Get the ip-addresses from the IP-Fabric
372
- result, prefix = get_ipfabric_data_for_prefix(prefix=prefix, result=result)
384
+ result, prefix = get_ipfabric_data_for_prefix(ipf=ipf, prefix=prefix, result=result)
373
385
  else:
374
386
  # Invalid datasource
375
387
  failed = True
@@ -1050,7 +1062,7 @@ def main(nr_config: str, nmap_scan: bool = False, overwrite_active: list[str] =
1050
1062
 
1051
1063
  if nmap_scan:
1052
1064
  # Set the task title
1053
- title = "Nmap Scan Active OOB/T1/T2 NetBox Prefixes and Update IP-Addresses"
1065
+ title = "Nmap Scan and Update Active OOB/T1/T2 NetBox Prefixes IP-Addresses"
1054
1066
 
1055
1067
  # Run the thread pool to update all NetBox IP-Addresses Status and DNS-Name
1056
1068
  # 1. arg is the input type ('nmap' or 'ip-fabric')
@@ -1068,7 +1080,7 @@ def main(nr_config: str, nmap_scan: bool = False, overwrite_active: list[str] =
1068
1080
  #### IP-Fabric Update Active & Inventory NetBox Prefixes IP-Addresses ###################################
1069
1081
 
1070
1082
  # Set the task title
1071
- title = "IP-Fabric Update Active & Inventory T3/T4 NetBox Prefixes IP-Addresses"
1083
+ title = "IP-Fabric Update Active & Inventory OOB/T1/T2/T3/T4 NetBox Prefixes IP-Addresses"
1072
1084
 
1073
1085
  # Run the thread pool to update all NetBox IP-Addresses Status and DNS-Name
1074
1086
  # 1. arg is the input type ('nmap' or 'ip-fabric')
@@ -1077,7 +1089,7 @@ def main(nr_config: str, nmap_scan: bool = False, overwrite_active: list[str] =
1077
1089
  title=title,
1078
1090
  task=update_netbox_prefix_ip_addresses,
1079
1091
  thread_list=nb_active_inventory_t3_t4_prefixes,
1080
- max_workers=10,
1092
+ max_workers=5,
1081
1093
  args=("ip-fabric", overwrite_active),
1082
1094
  )
1083
1095
  # Print the thread pool results and exit the script if any task has failed
@@ -1092,7 +1104,7 @@ def main(nr_config: str, nmap_scan: bool = False, overwrite_active: list[str] =
1092
1104
  thread_result = run_thread_pool(
1093
1105
  title=title,
1094
1106
  task=update_all_netbox_ip_addresses,
1095
- max_workers=100,
1107
+ max_workers=50,
1096
1108
  thread_list=nb_subnet_prefixes,
1097
1109
  )
1098
1110
  # Print the thread pool results and exit the script if any task has failed
@@ -1107,7 +1119,7 @@ def main(nr_config: str, nmap_scan: bool = False, overwrite_active: list[str] =
1107
1119
  thread_result = run_thread_pool(
1108
1120
  title=title,
1109
1121
  task=update_all_netbox_vlans,
1110
- max_workers=100,
1122
+ max_workers=50,
1111
1123
  thread_list=nb_vlans,
1112
1124
  )
1113
1125
  # Print the thread pool results and exit the script if any task has failed
@@ -159,7 +159,12 @@ def init_args_for_ipam_update() -> str:
159
159
  # If argparser.parse_args() is successful -> no argparse error message
160
160
  print(task_info(text=task_text, changed=False))
161
161
  print(f"'{task_text}' -> ArgparseResponse <Success: True>")
162
- print(f"-> Run on the NetBox '{nb_instance}' instance and Nornir config '{nr_config}'")
162
+ print("-> Arguments:")
163
+ print(f" - Run on the '{nb_instance}' NetBox instance and Nornir config '{nr_config}'")
164
+ if args.nmap:
165
+ print(" - NMAP scan additionally to IP-Fabric is enabled (default: no NMAP scan)")
166
+ else:
167
+ print(" - NMAP scan additionally to IP-Fabric is disabled (default: no NMAP scan)")
163
168
 
164
169
  return nr_config, args
165
170
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nornir-collection
3
- Version: 0.0.14
3
+ Version: 0.0.16
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
@@ -41,9 +41,9 @@ nornir_collection/netbox/sync_datasource.py,sha256=eEsgwy_arIPbA-ObqqzTNdU9aiP80
41
41
  nornir_collection/netbox/update_cisco_inventory_data.py,sha256=Aq4VGvAIiBhOCsSOF-wBUrpYtBXR8HwR3NCWEeM4d0g,6426
42
42
  nornir_collection/netbox/update_cisco_support_plugin_data.py,sha256=H8SfqESad64LrZrsWOaICHKj122sgu96dK9RcbvtzGM,13896
43
43
  nornir_collection/netbox/update_fortinet_inventory_data.py,sha256=ltwkE_bFljRUR4aeOxorChCsHdZciD1TqvoPnWTUIUg,6367
44
- nornir_collection/netbox/update_prefixes_ip_addresses.py,sha256=59Dosd5eSPzam90UQvMwmBXMbMSJ1SulSzZp9rpb4cM,46807
44
+ nornir_collection/netbox/update_prefixes_ip_addresses.py,sha256=RD_57_PnAD3NquIJNYyUQ5ZG1j7b4p4VrSN3LOTadHQ,47637
45
45
  nornir_collection/netbox/update_purestorage_inventory_data.py,sha256=cGZNMTZWJ0wu1BYdE92EVN-C-oLMJHxaKi_-1cMg0Ow,5368
46
- nornir_collection/netbox/utils.py,sha256=P4OivA0v1qocCF08cL3UvKXDcrZ9BdbY141lbsWBpSk,11899
46
+ nornir_collection/netbox/utils.py,sha256=mCV7QfLeR6kKurZVpMrHucIoru759RiwzE4NGEx91kI,12140
47
47
  nornir_collection/netbox/verify_device_primary_ip.py,sha256=6UCdZaZxhV4v8KqpjSpE9c7jaxIAF2krrknrrRj1AvM,8690
48
48
  nornir_collection/nornir_plugins/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
49
49
  nornir_collection/nornir_plugins/inventory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -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.14.dist-info/LICENSE,sha256=bOPVh1OVNwz2tCjkLaChWT6AoXdtqye3aua5l0tgYJo,1068
56
- nornir_collection-0.0.14.dist-info/METADATA,sha256=UooSFg0hkxAaU5W5CzwXr2f2rEwT5flFelQUlYhamvM,7169
57
- nornir_collection-0.0.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
58
- nornir_collection-0.0.14.dist-info/top_level.txt,sha256=OyCzPWABf-D0AOHm9ihrwdk5eq200BnKna6gIDspwsE,18
59
- nornir_collection-0.0.14.dist-info/RECORD,,
55
+ nornir_collection-0.0.16.dist-info/LICENSE,sha256=bOPVh1OVNwz2tCjkLaChWT6AoXdtqye3aua5l0tgYJo,1068
56
+ nornir_collection-0.0.16.dist-info/METADATA,sha256=egvJ2tjPUD23a7USj9Qt9mqQyVKN9EaCURYTu9_44QA,7169
57
+ nornir_collection-0.0.16.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
58
+ nornir_collection-0.0.16.dist-info/top_level.txt,sha256=OyCzPWABf-D0AOHm9ihrwdk5eq200BnKna6gIDspwsE,18
59
+ nornir_collection-0.0.16.dist-info/RECORD,,