nornir-collection 0.0.2__py3-none-any.whl → 0.0.4__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.
- nornir_collection/batfish/assert_config.py +1 -5
- nornir_collection/batfish/utils.py +0 -2
- nornir_collection/cisco/configuration_management/cli/config_tasks.py +0 -8
- nornir_collection/cisco/configuration_management/cli/config_workflow.py +0 -1
- nornir_collection/cisco/configuration_management/cli/show_tasks.py +3 -7
- nornir_collection/cisco/configuration_management/netconf/config_tasks.py +3 -14
- nornir_collection/cisco/configuration_management/netconf/config_workflow.py +1 -6
- nornir_collection/cisco/configuration_management/netconf/nr_cfg_iosxe_netconf.py +0 -2
- nornir_collection/cisco/configuration_management/netconf/ops_tasks.py +2 -7
- nornir_collection/cisco/configuration_management/processor.py +2 -3
- nornir_collection/cisco/configuration_management/pyats.py +0 -2
- nornir_collection/cisco/configuration_management/restconf/cisco_rpc.py +1 -9
- nornir_collection/cisco/configuration_management/restconf/config_workflow.py +1 -3
- nornir_collection/cisco/configuration_management/restconf/tasks.py +2 -5
- nornir_collection/cisco/configuration_management/utils.py +1 -4
- nornir_collection/cisco/software_upgrade/cisco_software_upgrade.py +0 -3
- nornir_collection/cisco/software_upgrade/utils.py +5 -16
- nornir_collection/cisco/support_api/api_calls.py +1 -7
- nornir_collection/cisco/support_api/cisco_maintenance_report.py +0 -2
- nornir_collection/cisco/support_api/cisco_support.py +0 -9
- nornir_collection/cisco/support_api/reports.py +1 -9
- nornir_collection/cisco/support_api/utils.py +0 -4
- nornir_collection/fortinet/utils.py +0 -1
- nornir_collection/git.py +3 -4
- nornir_collection/netbox/custom_script.py +1 -4
- nornir_collection/netbox/inventory.py +1 -4
- nornir_collection/netbox/scan_prefixes_and_update_ip_addresses.py +3 -8
- nornir_collection/netbox/set_device_status.py +0 -1
- nornir_collection/netbox/sync_datasource.py +0 -1
- nornir_collection/netbox/update_cisco_inventory_data.py +1 -3
- nornir_collection/netbox/update_cisco_support_plugin_data.py +0 -4
- nornir_collection/netbox/update_fortinet_inventory_data.py +1 -3
- nornir_collection/netbox/update_purestorage_inventory_data.py +1 -3
- nornir_collection/netbox/utils.py +1 -4
- nornir_collection/netbox/verify_device_primary_ip.py +1 -4
- nornir_collection/nornir_plugins/inventory/netbox.py +4 -9
- nornir_collection/nornir_plugins/inventory/staggered_yaml.py +0 -2
- nornir_collection/nornir_plugins/inventory/utils.py +1 -3
- nornir_collection/purestorage/utils.py +1 -2
- nornir_collection/utils.py +8 -14
- {nornir_collection-0.0.2.dist-info → nornir_collection-0.0.4.dist-info}/METADATA +3 -4
- nornir_collection-0.0.4.dist-info/RECORD +59 -0
- nornir_collection-0.0.2.dist-info/RECORD +0 -59
- {nornir_collection-0.0.2.dist-info → nornir_collection-0.0.4.dist-info}/LICENSE +0 -0
- {nornir_collection-0.0.2.dist-info → nornir_collection-0.0.4.dist-info}/WHEEL +0 -0
- {nornir_collection-0.0.2.dist-info → nornir_collection-0.0.4.dist-info}/top_level.txt +0 -0
@@ -178,8 +178,6 @@ def verify_issu_requirements(nr: Nornir) -> bool:
|
|
178
178
|
"""
|
179
179
|
TBD
|
180
180
|
"""
|
181
|
-
# pylint: disable=invalid-name
|
182
|
-
|
183
181
|
# Run the custom Nornir task verify_issu_requirements
|
184
182
|
task_result = nr.run(
|
185
183
|
task=verify_issu_requirements_task,
|
@@ -203,8 +201,6 @@ def cli_track_issu_upgrade_process(nr: Nornir, max_time: int) -> None:
|
|
203
201
|
the result to std-out. In case the software upgrade is not successful after the range loop is finish, an
|
204
202
|
info message will be printed and exit the script.
|
205
203
|
"""
|
206
|
-
# pylint: disable=invalid-name,too-many-branches
|
207
|
-
|
208
204
|
# Printout sleep and refresh values
|
209
205
|
std_out_print = []
|
210
206
|
refresh_timer = 10
|
@@ -219,9 +215,9 @@ def cli_track_issu_upgrade_process(nr: Nornir, max_time: int) -> None:
|
|
219
215
|
# Dict to track the host software upgrade status
|
220
216
|
update_status = {}
|
221
217
|
for host in nr.inventory.hosts:
|
222
|
-
update_status[
|
223
|
-
|
224
|
-
|
218
|
+
update_status[host] = (
|
219
|
+
f"{Fore.YELLOW}No ISSU operation is in progress (Installing software){Fore.RESET}"
|
220
|
+
)
|
225
221
|
|
226
222
|
print(task_name("Track ISSU software upgrade process"))
|
227
223
|
|
@@ -342,7 +338,6 @@ def fping_track_upgrade_process(nr: Nornir, max_time: int) -> None:
|
|
342
338
|
std-out. In case the software upgrade is not successful after the range loop is finish, an info message
|
343
339
|
will be printed and exit the script.
|
344
340
|
"""
|
345
|
-
# pylint: disable=invalid-name
|
346
341
|
|
347
342
|
# Printout sleep and refresh values
|
348
343
|
std_out_print = []
|
@@ -439,7 +434,6 @@ def cli_verify_switch_state(nr: Nornir, max_time: int) -> None:
|
|
439
434
|
This function runs the custom Nornir Scrapli task cli_verify_switch_state to get the switch stack state
|
440
435
|
of each host.
|
441
436
|
"""
|
442
|
-
# pylint: disable=invalid-name
|
443
437
|
|
444
438
|
# Printout sleep and refresh values
|
445
439
|
std_out_print = []
|
@@ -562,7 +556,6 @@ def prepare_upgrade_data_task(task: Task, upgrade_type: Literal["http", "scp"])
|
|
562
556
|
if http_url.lower().startswith("http"):
|
563
557
|
response = urllib.request.Request(http_url, method="HEAD")
|
564
558
|
with urllib.request.urlopen(response) as response: # nosec
|
565
|
-
# pylint: disable=consider-using-f-string
|
566
559
|
file_size = "%.2f" % (int(response.headers["Content-Length"]) / (1024 * 1024 * 1024))
|
567
560
|
else:
|
568
561
|
raise ValueError from None
|
@@ -582,7 +575,6 @@ def prepare_upgrade_data_task(task: Task, upgrade_type: Literal["http", "scp"])
|
|
582
575
|
return Result(host=task.host, result=result, failed=True)
|
583
576
|
|
584
577
|
# Get the filesize and format to GB
|
585
|
-
# pylint: disable=consider-using-f-string
|
586
578
|
file_size = "%.2f" % (os.path.getsize(source_file) / (1024 * 1024 * 1024))
|
587
579
|
|
588
580
|
result = (
|
@@ -686,11 +678,11 @@ def verify_issu_requirements_task(task: Task) -> Result:
|
|
686
678
|
|
687
679
|
# Verify that the desired version is greater or equal than the current version
|
688
680
|
if int(desired_version) >= int(current_version):
|
689
|
-
result = f"'{task.name}' -> NornirResponse <Success: True>\n
|
681
|
+
result = f"'{task.name}' -> NornirResponse <Success: True>\n-> ISSU upgrade is supported"
|
690
682
|
# Return the Nornir result as success
|
691
683
|
return Result(host=task.host, result=result)
|
692
684
|
|
693
|
-
result = f"'{task.name}' -> NornirResponse <Success: False>\n
|
685
|
+
result = f"'{task.name}' -> NornirResponse <Success: False>\n-> ISSU downgrade is not supported"
|
694
686
|
# Return the Nornir result as failed
|
695
687
|
return Result(host=task.host, result=result, failed=True)
|
696
688
|
|
@@ -706,7 +698,6 @@ def prepare_upgrade_data(nr: Nornir, upgrade_type: Literal["http", "scp"]) -> bo
|
|
706
698
|
printed with print_result. In case of a source verification error a error message will be printed and the
|
707
699
|
script terminates. The function return False if the task failed or True if the task was successful.
|
708
700
|
"""
|
709
|
-
# pylint: disable=invalid-name
|
710
701
|
|
711
702
|
# Run the custom Nornir task prepare_upgrade_data_task
|
712
703
|
task_result = nr.run(
|
@@ -727,7 +718,6 @@ def scp_upload_software_file(nr: Nornir) -> None:
|
|
727
718
|
"""
|
728
719
|
TBD
|
729
720
|
"""
|
730
|
-
# pylint: disable=invalid-name
|
731
721
|
|
732
722
|
print_task_name("NETMIKO prepare software file upload with SCP")
|
733
723
|
# Print some info for each host
|
@@ -760,7 +750,6 @@ def cli_http_download_software_file(nr: Nornir, verbose: bool = False) -> bool:
|
|
760
750
|
"""
|
761
751
|
TBD
|
762
752
|
"""
|
763
|
-
# pylint: disable=invalid-name
|
764
753
|
|
765
754
|
print_task_name("NETMIKO prepare software file download with HTTP")
|
766
755
|
# Print some info for each host
|
@@ -14,12 +14,8 @@ The classes are ordered as followed:
|
|
14
14
|
- RMA (Service Order Return)
|
15
15
|
"""
|
16
16
|
|
17
|
-
|
18
17
|
import requests
|
19
18
|
|
20
|
-
|
21
|
-
# pylint: disable=invalid-name,too-many-arguments,too-many-lines
|
22
|
-
|
23
19
|
#### Constants ##############################################################################################
|
24
20
|
|
25
21
|
|
@@ -197,9 +193,7 @@ class EOX:
|
|
197
193
|
|
198
194
|
self.__headers = {"Authorization": f"Bearer {token}", "Accept": "application/json"}
|
199
195
|
|
200
|
-
def getByDates(
|
201
|
-
self, startDate: str, endDate: str, pageIndex: int = 1, eoxAttrib: list = []
|
202
|
-
) -> dict:
|
196
|
+
def getByDates(self, startDate: str, endDate: str, pageIndex: int = 1, eoxAttrib: list = []) -> dict:
|
203
197
|
"""
|
204
198
|
Get EoX by Dates
|
205
199
|
|
@@ -47,7 +47,6 @@ def _create_report_config(args: argparse.Namespace, nr: Nornir = False) -> dict:
|
|
47
47
|
"""
|
48
48
|
TBD
|
49
49
|
"""
|
50
|
-
# pylint: disable=invalid-name
|
51
50
|
|
52
51
|
# Create a dict for the report configuration specifications
|
53
52
|
report_cfg = {}
|
@@ -112,7 +111,6 @@ def _load_report_yaml_config(report_cfg, args):
|
|
112
111
|
|
113
112
|
def main(nr_config: str = "inventory/nr_config.yaml") -> None:
|
114
113
|
"""Main function is executed when the file is directly executed."""
|
115
|
-
# pylint: disable=invalid-name
|
116
114
|
|
117
115
|
#### Initialize Script and Nornir #######################################################################
|
118
116
|
|
@@ -7,7 +7,6 @@ The functions are ordered as followed:
|
|
7
7
|
- Print functions for Cisco Support API call functions in Nornir style
|
8
8
|
"""
|
9
9
|
|
10
|
-
|
11
10
|
import json
|
12
11
|
import time
|
13
12
|
from typing import Any, Literal, Union
|
@@ -113,8 +112,6 @@ def _get_data_all_pages(**kwargs) -> list[dict]:
|
|
113
112
|
"""
|
114
113
|
TBD
|
115
114
|
"""
|
116
|
-
# pylint: disable=cell-var-from-loop
|
117
|
-
|
118
115
|
# Cisco Support API Object and API name as string
|
119
116
|
api_obj = kwargs["api_obj"]
|
120
117
|
api = kwargs["api_string"]
|
@@ -210,8 +207,6 @@ def verify_cisco_support_api_data(
|
|
210
207
|
there are no invalid serial numbers. In case of invalid serial numbers, the script quits with an error
|
211
208
|
message.
|
212
209
|
"""
|
213
|
-
# pylint: disable=too-many-branches
|
214
|
-
|
215
210
|
if not force_failed:
|
216
211
|
# Check if any value of the iterable is inside the API error lists
|
217
212
|
no_error = True
|
@@ -337,7 +332,6 @@ def get_sni_owner_coverage_by_serial_number(serial_dict: dict, api_creds: tuple)
|
|
337
332
|
...
|
338
333
|
},
|
339
334
|
"""
|
340
|
-
# pylint: disable=invalid-name
|
341
335
|
|
342
336
|
# Maximum serial number API parameter value
|
343
337
|
MAX_SR_NO = 75
|
@@ -384,7 +378,6 @@ def get_sni_coverage_summary_by_serial_numbers(serial_dict: dict, api_creds: tup
|
|
384
378
|
...
|
385
379
|
},
|
386
380
|
"""
|
387
|
-
# pylint: disable=invalid-name
|
388
381
|
|
389
382
|
# Maximum serial number API parameter value
|
390
383
|
MAX_SR_NO = 75
|
@@ -432,7 +425,6 @@ def get_eox_by_serial_numbers(serial_dict: dict, api_creds: tuple) -> dict:
|
|
432
425
|
...
|
433
426
|
},
|
434
427
|
"""
|
435
|
-
# pylint: disable=invalid-name
|
436
428
|
|
437
429
|
# Maximum serial number API parameter value
|
438
430
|
MAX_SR_NO = 20
|
@@ -480,7 +472,6 @@ def get_ss_suggested_release_by_pid(serial_dict: dict, api_creds: tuple, pid_lis
|
|
480
472
|
...
|
481
473
|
},
|
482
474
|
"""
|
483
|
-
# pylint: disable=invalid-name
|
484
475
|
|
485
476
|
# Maximum PID API parameter value
|
486
477
|
MAX_PID = 10
|
@@ -144,8 +144,6 @@ def prepare_report_data_eox_by_sn(serials_dict: dict) -> dict:
|
|
144
144
|
dictionary with key-value pairs. The key will be the pandas dataframe column name and the value which is
|
145
145
|
a list will be the colums cell content. The host dict will be returned.
|
146
146
|
"""
|
147
|
-
# pylint: disable=too-many-nested-blocks
|
148
|
-
|
149
147
|
# Define dict keys for EOXgetBySerialNumbers
|
150
148
|
# fmt: off
|
151
149
|
columns = [
|
@@ -282,8 +280,6 @@ def prepare_report_data_tss(serials_dict: dict, file: str) -> dict:
|
|
282
280
|
named tss_info will be returned which contains the key value pairs "coverage_action_needed",
|
283
281
|
"api_action_needed" and all TSS data to create a Pandas dataframe later.
|
284
282
|
"""
|
285
|
-
# pylint: disable=invalid-name,too-many-branches
|
286
|
-
|
287
283
|
# Define the tss_info dict and its key value pairs to return as the end of the function
|
288
284
|
columns = ["coverage_action_needed", "api_action_needed"]
|
289
285
|
|
@@ -402,7 +398,6 @@ def create_pandas_dataframe_for_report(
|
|
402
398
|
"""
|
403
399
|
Prepare the report data and create a pandas dataframe. The pandas dataframe will be returned
|
404
400
|
"""
|
405
|
-
# pylint: disable=invalid-name
|
406
401
|
|
407
402
|
print_task_name(text="PYTHON prepare report data")
|
408
403
|
|
@@ -533,7 +528,6 @@ def _worksheet_add_table(df, workbook, worksheet, config):
|
|
533
528
|
"""
|
534
529
|
TBD
|
535
530
|
"""
|
536
|
-
# pylint: disable=invalid-name
|
537
531
|
|
538
532
|
# Create a list of column headers, to use in add_table().
|
539
533
|
columns = [{"header": column} for column in df.columns]
|
@@ -569,7 +563,6 @@ def _worksheet_add_conditional_formatting(df, workbook, worksheet, config):
|
|
569
563
|
"""
|
570
564
|
TBD
|
571
565
|
"""
|
572
|
-
# pylint: disable=invalid-name
|
573
566
|
|
574
567
|
# Specify the table start row where conditional formatting should start
|
575
568
|
startrow = 3
|
@@ -678,7 +671,6 @@ def generate_cisco_maintenance_report(df: pd.DataFrame, report_cfg: dict) -> Non
|
|
678
671
|
Generate the Cisco Maintenance report Excel file specified by the report_file with the pandas dataframe.
|
679
672
|
The function returns None, but saves the Excel file to the local disk.
|
680
673
|
"""
|
681
|
-
# pylint: disable=invalid-name
|
682
674
|
|
683
675
|
# Disable Pandas SettingWithCopyWarning for "chained" assignments
|
684
676
|
# -> Error-Message: A value is trying to be set on a copy of a slice from a DataFrame
|
@@ -697,7 +689,7 @@ def generate_cisco_maintenance_report(df: pd.DataFrame, report_cfg: dict) -> Non
|
|
697
689
|
report_cfg["max_col"] = max_col - 1
|
698
690
|
|
699
691
|
# Create a Pandas excel writer using XlsxWriter as the engine.
|
700
|
-
writer = pd.ExcelWriter(
|
692
|
+
writer = pd.ExcelWriter(
|
701
693
|
path=report_cfg["excel_file"],
|
702
694
|
engine="xlsxwriter",
|
703
695
|
date_format="yyyy-mm-dd",
|
@@ -7,7 +7,6 @@ The functions are ordered as followed:
|
|
7
7
|
- Static or Dynamic Nornir Serial Numbers Gathering
|
8
8
|
"""
|
9
9
|
|
10
|
-
|
11
10
|
import os
|
12
11
|
import json
|
13
12
|
import argparse
|
@@ -121,7 +120,6 @@ def _prepare_nornir_data_static_serials(serials: dict, nr: Nornir) -> dict:
|
|
121
120
|
"""
|
122
121
|
TBD
|
123
122
|
"""
|
124
|
-
# pylint: disable=invalid-name
|
125
123
|
|
126
124
|
if isinstance(nr.inventory.defaults.data["cisco_maintenance_report"]["static_serials"], str):
|
127
125
|
# If static_serials is a str of a file path, then load the YAML file from that string path
|
@@ -175,7 +173,6 @@ def prepare_nornir_data(nr: Nornir, verbose: bool = False) -> dict:
|
|
175
173
|
This function use Nornir to gather and prepare the serial numbers and more data and returns the
|
176
174
|
serials dictionary.
|
177
175
|
"""
|
178
|
-
# pylint: disable=invalid-name
|
179
176
|
|
180
177
|
# Create a dict to fill with the serial numbers and other data from all hosts
|
181
178
|
serials = {}
|
@@ -239,7 +236,6 @@ def prepare_static_serials(args: argparse.Namespace) -> tuple[dict, str, tuple]:
|
|
239
236
|
This function prepare all static serial numbers which can be applied with the serials ArgParse argument
|
240
237
|
or within an Excel document. It returns the serials dictionary.
|
241
238
|
"""
|
242
|
-
# pylint: disable=invalid-name
|
243
239
|
|
244
240
|
task_text = "ARGPARSE verify static provided data"
|
245
241
|
print_task_name(text=task_text)
|
nornir_collection/git.py
CHANGED
@@ -35,7 +35,7 @@ def git_init(repo_path: str) -> tuple:
|
|
35
35
|
|
36
36
|
return (repo, repo_cmd)
|
37
37
|
|
38
|
-
except git.exc.NoSuchPathError as error:
|
38
|
+
except git.exc.NoSuchPathError as error:
|
39
39
|
# If no Git repo exists terminate the script
|
40
40
|
print(task_error(text="Initialize local Git repo", changed=False))
|
41
41
|
print(f"Git repo not found: {error}")
|
@@ -112,9 +112,8 @@ def git_cmd_pull(repo_cmd) -> None:
|
|
112
112
|
# Print the git pull result
|
113
113
|
print(git_pull_result)
|
114
114
|
|
115
|
-
except git.exc.GitCommandError as error:
|
115
|
+
except git.exc.GitCommandError as error:
|
116
116
|
print(task_error(text=task_text, changed=False))
|
117
|
-
# pylint: disable=protected-access
|
118
117
|
print(f"Command '{error._cmdline}' failed\n")
|
119
118
|
print(error.stdout.lstrip())
|
120
119
|
print(error.stderr.lstrip())
|
@@ -143,7 +142,7 @@ def git_cmd_add_commit(repo_cmd, commit_msg: str) -> None:
|
|
143
142
|
print(task_info(text=task_text, changed=False))
|
144
143
|
print(commit_cmd)
|
145
144
|
|
146
|
-
except git.exc.GitCommandError as error:
|
145
|
+
except git.exc.GitCommandError as error:
|
147
146
|
print(task_info(text=task_text, changed=False))
|
148
147
|
message = error.stdout.replace("stdout:", "").lstrip()
|
149
148
|
message = message.replace("'", "").lstrip()
|
@@ -6,7 +6,6 @@ The functions are ordered as followed:
|
|
6
6
|
- Regular functions
|
7
7
|
"""
|
8
8
|
|
9
|
-
|
10
9
|
import os
|
11
10
|
import time
|
12
11
|
import json
|
@@ -17,9 +16,7 @@ from nornir_collection.utils import task_name, task_error, task_info, exit_error
|
|
17
16
|
#### Regular functions ######################################################################################
|
18
17
|
|
19
18
|
|
20
|
-
def run_nb_custom_script(
|
21
|
-
name: str, url: str, payload: dict = {}, verbose: bool = False
|
22
|
-
) -> bool:
|
19
|
+
def run_nb_custom_script(name: str, url: str, payload: dict = {}, verbose: bool = False) -> bool:
|
23
20
|
"""
|
24
21
|
Runs a custom script in NetBox.
|
25
22
|
Args:
|
@@ -8,7 +8,6 @@ The functions are ordered as followed:
|
|
8
8
|
- Nornir Tasks in regular Function
|
9
9
|
"""
|
10
10
|
|
11
|
-
|
12
11
|
from typing import Dict, List
|
13
12
|
from nornir.core import Nornir
|
14
13
|
from nornir.core.task import Task, Result
|
@@ -71,8 +70,6 @@ def _load_interface_data(task: Task, all_interfaces: List[Dict], enrich_vlan_dat
|
|
71
70
|
Returns:
|
72
71
|
Result: Nornir result object.
|
73
72
|
"""
|
74
|
-
# pylint: disable=too-many-locals
|
75
|
-
|
76
73
|
# Set the failed flag to False
|
77
74
|
failed = False
|
78
75
|
|
@@ -254,7 +251,7 @@ def load_additional_netbox_data(nr: Nornir, add_netbox_data: dict[str:bool]) ->
|
|
254
251
|
"""
|
255
252
|
Load additional data from NetBox into Nornir inventory based on 'add_netbox_data' options.
|
256
253
|
"""
|
257
|
-
|
254
|
+
|
258
255
|
result_msg = []
|
259
256
|
task_text = "NORNIR load NetBox additional inventory data"
|
260
257
|
|
@@ -5,7 +5,6 @@ IP address, and vlan information.
|
|
5
5
|
The Main function is intended to import and execute by other scripts.
|
6
6
|
"""
|
7
7
|
|
8
|
-
|
9
8
|
import sys
|
10
9
|
import ipaddress
|
11
10
|
import urllib.parse
|
@@ -27,8 +26,6 @@ from nornir_collection.utils import (
|
|
27
26
|
task_result,
|
28
27
|
)
|
29
28
|
|
30
|
-
# pylint: disable=invalid-name
|
31
|
-
|
32
29
|
|
33
30
|
__author__ = "Willi Kubny"
|
34
31
|
__maintainer__ = "Willi Kubny"
|
@@ -103,7 +100,7 @@ def make_markdown_table(array: list[list[str]]) -> str:
|
|
103
100
|
nl = "\n"
|
104
101
|
markdown = f"| {' | '.join(array[0])} |"
|
105
102
|
markdown += nl
|
106
|
-
markdown += f"| {' | '.join(['---']*len(array[0]))} |"
|
103
|
+
markdown += f"| {' | '.join(['---'] * len(array[0]))} |"
|
107
104
|
markdown += nl
|
108
105
|
for entry in array[1:]:
|
109
106
|
markdown += f"| {' | '.join(entry)} |{nl}"
|
@@ -166,7 +163,7 @@ def create_nb_response_result(
|
|
166
163
|
[
|
167
164
|
f"- Tenant: {data['tenant']['name'] if data['tenant'] else 'None'}",
|
168
165
|
f"- Tags: {(', '.join([i['name'] for i in data['tags']])) or 'None'}",
|
169
|
-
f"- Location: {', '.join(list(data['custom_fields']['ipam_location'])).upper() or 'None'}", #
|
166
|
+
f"- Location: {', '.join(list(data['custom_fields']['ipam_location'])).upper() or 'None'}", # noqa: E501
|
170
167
|
]
|
171
168
|
)
|
172
169
|
# If the type is 'vlan' and data is empty
|
@@ -279,7 +276,7 @@ def get_netbox_ip_addresses_and_scan_prefix(nb_url: str, prefix: dict) -> tuple:
|
|
279
276
|
network_addr = ipaddress.ip_network(prefix["prefix"]).network_address
|
280
277
|
broadcast_addr = ipaddress.ip_network(prefix["prefix"]).broadcast_address
|
281
278
|
# Set the nmap scan arguments
|
282
|
-
arguments = f"-PE -PP -PA21 -PS80,443,3389 -PU161,40125 --source-port 53 --exclude {network_addr},{broadcast_addr}" #
|
279
|
+
arguments = f"-PE -PP -PA21 -PS80,443,3389 -PU161,40125 --source-port 53 --exclude {network_addr},{broadcast_addr}" # noqa E501
|
283
280
|
|
284
281
|
# Nmap ARP scan for the prefix and add a list of active ip-addresses and other details to prefix
|
285
282
|
nm = nmap.PortScanner()
|
@@ -778,8 +775,6 @@ def update_all_netbox_vlans(vlan: dict) -> tuple:
|
|
778
775
|
tuple: A tuple containing the results of the update and the overall failed status.
|
779
776
|
|
780
777
|
"""
|
781
|
-
# pylint: disable=unsubscriptable-object
|
782
|
-
|
783
778
|
# Create a list to collect the task results
|
784
779
|
results = []
|
785
780
|
# Boolian to check if any ip-addresses have been changed and the overall failed status
|
@@ -4,7 +4,6 @@ This module sets the device status in NetBox by running a custom script.
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
import sys
|
9
8
|
from nornir_collection.utils import exit_error, load_yaml_file
|
10
9
|
from nornir_collection.netbox.custom_script import run_nb_custom_script
|
@@ -4,7 +4,6 @@ This module updates the serial numbers of Cisco devices in NetBox using Nornir.
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
from nornir.core import Nornir
|
9
8
|
from nornir.core.filter import F
|
10
9
|
from nornir.core.task import Task, Result
|
@@ -85,7 +84,7 @@ def update_cisco_inventory_data(nr: Nornir) -> bool:
|
|
85
84
|
Returns:
|
86
85
|
bool: True if any of the tasks failed, False otherwise.
|
87
86
|
"""
|
88
|
-
|
87
|
+
|
89
88
|
# Track if one of the tasks has failed
|
90
89
|
failed = False
|
91
90
|
|
@@ -134,7 +133,6 @@ def main(nr_config: str) -> None:
|
|
134
133
|
* Exit:
|
135
134
|
* Exits with code 1 if the Nornir configuration file is empty or if any task fails.
|
136
135
|
"""
|
137
|
-
# pylint: disable=invalid-name
|
138
136
|
|
139
137
|
#### Initialize Nornir ##################################################################################
|
140
138
|
|
@@ -4,7 +4,6 @@ This module updates Cisco support plugin data in NetBox using Nornir.
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
import sys
|
9
8
|
from nornir.core.filter import F
|
10
9
|
from nornir.core import Nornir
|
@@ -227,7 +226,6 @@ def update_cisco_support_plugin_data(nr: Nornir, partner_inv: str = None) -> boo
|
|
227
226
|
bool: True if any of the tasks failed, False otherwise.
|
228
227
|
"""
|
229
228
|
|
230
|
-
# pylint: disable=invalid-name
|
231
229
|
# Track if one of the tasks has failed
|
232
230
|
failed = False
|
233
231
|
|
@@ -315,8 +313,6 @@ def main(nr_config: str, partner_inv: str = None) -> None:
|
|
315
313
|
* Exits with code 1 if the Nornir configuration file is empty or if any task fails.
|
316
314
|
"""
|
317
315
|
|
318
|
-
# pylint: disable=invalid-name
|
319
|
-
|
320
316
|
#### Initialize Nornir ##################################################################################
|
321
317
|
|
322
318
|
# Initialize and transform the Nornir inventory object
|
@@ -4,7 +4,6 @@ This module updates the serial numbers of Fortinet devices in NetBox using Norni
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
from nornir.core import Nornir
|
9
8
|
from nornir.core.filter import F
|
10
9
|
from nornir.core.task import Task, Result
|
@@ -91,7 +90,7 @@ def update_fortinet_inventory_data(nr: Nornir) -> bool:
|
|
91
90
|
Returns:
|
92
91
|
bool: True if any of the tasks failed, False otherwise.
|
93
92
|
"""
|
94
|
-
|
93
|
+
|
95
94
|
# Track if one of the tasks has failed
|
96
95
|
failed = False
|
97
96
|
|
@@ -137,7 +136,6 @@ def main(nr_config: str) -> None:
|
|
137
136
|
* Exits:
|
138
137
|
* Exits with code 1 if the Nornir configuration file is empty or if any task fails.
|
139
138
|
"""
|
140
|
-
# pylint: disable=invalid-name
|
141
139
|
|
142
140
|
#### Initialize Nornir ##################################################################################
|
143
141
|
|
@@ -4,7 +4,6 @@ This module updates the serial number of Pure Storage devices in NetBox using No
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
from nornir.core import Nornir
|
9
8
|
from nornir.core.filter import F
|
10
9
|
from nornir.core.task import Task, Result
|
@@ -75,7 +74,7 @@ def update_purestorage_inventory_data(nr: Nornir) -> bool:
|
|
75
74
|
Returns:
|
76
75
|
bool: True if any of the tasks failed, False otherwise.
|
77
76
|
"""
|
78
|
-
|
77
|
+
|
79
78
|
# Track if one of the tasks has failed
|
80
79
|
failed = False
|
81
80
|
|
@@ -120,7 +119,6 @@ def main(nr_config: str) -> None:
|
|
120
119
|
* Exits:
|
121
120
|
* Exits with code 1 if the Nornir configuration file is empty or if any task fails.
|
122
121
|
"""
|
123
|
-
# pylint: disable=invalid-name
|
124
122
|
|
125
123
|
#### Initialize Nornir ##################################################################################
|
126
124
|
|
@@ -9,7 +9,6 @@ The functions are ordered as followed:
|
|
9
9
|
- Nornir tasks in regular function
|
10
10
|
"""
|
11
11
|
|
12
|
-
|
13
12
|
import os
|
14
13
|
import argparse
|
15
14
|
import json
|
@@ -105,9 +104,7 @@ def init_args_for_nornir_config_filepath() -> str:
|
|
105
104
|
return nr_config
|
106
105
|
|
107
106
|
|
108
|
-
def get_nb_resources(
|
109
|
-
url: str, params: Dict[str, Any] = {}
|
110
|
-
) -> List[Dict[str, Any]]:
|
107
|
+
def get_nb_resources(url: str, params: Dict[str, Any] = {}) -> List[Dict[str, Any]]:
|
111
108
|
"""
|
112
109
|
TBD
|
113
110
|
"""
|
@@ -4,7 +4,6 @@ This module load the NetBox device inventory, find active management IP addresse
|
|
4
4
|
The Main function is intended to import and execute by other scripts.
|
5
5
|
"""
|
6
6
|
|
7
|
-
|
8
7
|
import sys
|
9
8
|
import subprocess # nosec
|
10
9
|
from nornir_collection.netbox.utils import get_nb_resources
|
@@ -25,7 +24,7 @@ __email__ = "willi.kubny@dreyfusbank.ch"
|
|
25
24
|
__status__ = "Production"
|
26
25
|
|
27
26
|
|
28
|
-
def main(
|
27
|
+
def main(
|
29
28
|
nr_config: str,
|
30
29
|
mgmt_subnets: list[str],
|
31
30
|
add_addresses: list[str] = [],
|
@@ -52,8 +51,6 @@ def main( # pylint: disable=dangerous-default-value,too-many-arguments,too-many
|
|
52
51
|
* Exits:
|
53
52
|
* Exits with code 1 if the Nornir configuration file is empty or if any task fails.
|
54
53
|
"""
|
55
|
-
# pylint: disable=invalid-name,too-many-locals
|
56
|
-
|
57
54
|
#### Load NetBox Device Inventory ########################################################################
|
58
55
|
|
59
56
|
task_title = "Load NetBox Device Inventory"
|
@@ -35,7 +35,7 @@ def _get_connection_options(data: Dict[str, Any]) -> Dict[str, ConnectionOptions
|
|
35
35
|
"""
|
36
36
|
TBD
|
37
37
|
"""
|
38
|
-
|
38
|
+
|
39
39
|
cp = {}
|
40
40
|
for cn, c in data.items():
|
41
41
|
cp[cn] = ConnectionOptions(
|
@@ -106,9 +106,7 @@ class DSCNetBoxInventory:
|
|
106
106
|
(defaults to True)
|
107
107
|
"""
|
108
108
|
|
109
|
-
|
110
|
-
|
111
|
-
def __init__( # pylint: disable=unused-argument,too-many-arguments
|
109
|
+
def __init__(
|
112
110
|
self,
|
113
111
|
nb_url: Optional[str] = None,
|
114
112
|
nb_token: Optional[str] = None,
|
@@ -127,9 +125,7 @@ class DSCNetBoxInventory:
|
|
127
125
|
self.session.headers.update({"Authorization": f"Token {nb_token}"})
|
128
126
|
self.session.verify = ssl_verify
|
129
127
|
|
130
|
-
def _get_resources(
|
131
|
-
self, url: str, params: Dict[str, Any] = {}
|
132
|
-
) -> List[Dict[str, Any]]:
|
128
|
+
def _get_resources(self, url: str, params: Dict[str, Any] = {}) -> List[Dict[str, Any]]:
|
133
129
|
"""
|
134
130
|
TBD
|
135
131
|
"""
|
@@ -156,7 +152,6 @@ class DSCNetBoxInventory:
|
|
156
152
|
"""
|
157
153
|
TBD
|
158
154
|
"""
|
159
|
-
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
160
155
|
yml = ruamel.yaml.YAML(typ="safe")
|
161
156
|
|
162
157
|
print_task_name(text=self.task_text)
|
@@ -214,7 +209,7 @@ class DSCNetBoxInventory:
|
|
214
209
|
serialized_device["data"]["virtual_chassis"]["master"]["serial"] = master_serial
|
215
210
|
|
216
211
|
# Flatten the list of Tags which contains only the slug of each NetBox tag
|
217
|
-
device["tags"] = [tag["
|
212
|
+
device["tags"] = [tag["name"] for tag in device["tags"]]
|
218
213
|
|
219
214
|
# Extract the device connection options
|
220
215
|
# Add Nornir connection options from the device context data
|
@@ -39,7 +39,6 @@ def nr_transform_host_creds_from_env(nr: Nornir) -> None:
|
|
39
39
|
This function loads the host login credentials from environment variables and stores them directly under
|
40
40
|
the host inventory level. This function can be extended to to more host transformation.
|
41
41
|
"""
|
42
|
-
# pylint: disable=invalid-name
|
43
42
|
|
44
43
|
task_text = "NORNIR transform host credentials env variable"
|
45
44
|
print(task_name(text=task_text))
|
@@ -222,7 +221,6 @@ def init_nornir(
|
|
222
221
|
are defined in the inventory. The function returns a filtered Nornir object or quits with an error message
|
223
222
|
in case of issues during the function.
|
224
223
|
"""
|
225
|
-
# pylint: disable=invalid-name
|
226
224
|
|
227
225
|
print_task_title("Initialize Nornir Inventory")
|
228
226
|
|
@@ -272,6 +270,6 @@ def init_nornir(
|
|
272
270
|
print(f"{task_name(text=task_text)}")
|
273
271
|
print(task_info(text=task_text, changed=False))
|
274
272
|
print(f"'{task_text}' -> NornirResponse <Success: True>")
|
275
|
-
print(f"-> Initialize Nornir finished in: {round(time.time()-timer_start, 1)}s")
|
273
|
+
print(f"-> Initialize Nornir finished in: {round(time.time() - timer_start, 1)}s")
|
276
274
|
|
277
275
|
return nr
|