nornir-collection 0.0.1__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.
Files changed (59) hide show
  1. nornir_collection/__init__.py +0 -0
  2. nornir_collection/batfish/__init__.py +0 -0
  3. nornir_collection/batfish/assert_config.py +358 -0
  4. nornir_collection/batfish/utils.py +129 -0
  5. nornir_collection/cisco/__init__.py +0 -0
  6. nornir_collection/cisco/configuration_management/__init__.py +0 -0
  7. nornir_collection/cisco/configuration_management/cli/__init__.py +0 -0
  8. nornir_collection/cisco/configuration_management/cli/config_tasks.py +569 -0
  9. nornir_collection/cisco/configuration_management/cli/config_workflow.py +107 -0
  10. nornir_collection/cisco/configuration_management/cli/show_tasks.py +677 -0
  11. nornir_collection/cisco/configuration_management/netconf/__init__.py +0 -0
  12. nornir_collection/cisco/configuration_management/netconf/config_tasks.py +564 -0
  13. nornir_collection/cisco/configuration_management/netconf/config_workflow.py +298 -0
  14. nornir_collection/cisco/configuration_management/netconf/nr_cfg_iosxe_netconf.py +186 -0
  15. nornir_collection/cisco/configuration_management/netconf/ops_tasks.py +307 -0
  16. nornir_collection/cisco/configuration_management/processor.py +151 -0
  17. nornir_collection/cisco/configuration_management/pyats.py +236 -0
  18. nornir_collection/cisco/configuration_management/restconf/__init__.py +0 -0
  19. nornir_collection/cisco/configuration_management/restconf/cisco_rpc.py +514 -0
  20. nornir_collection/cisco/configuration_management/restconf/config_workflow.py +95 -0
  21. nornir_collection/cisco/configuration_management/restconf/tasks.py +325 -0
  22. nornir_collection/cisco/configuration_management/utils.py +511 -0
  23. nornir_collection/cisco/software_upgrade/__init__.py +0 -0
  24. nornir_collection/cisco/software_upgrade/cisco_software_upgrade.py +283 -0
  25. nornir_collection/cisco/software_upgrade/utils.py +794 -0
  26. nornir_collection/cisco/support_api/__init__.py +0 -0
  27. nornir_collection/cisco/support_api/api_calls.py +1173 -0
  28. nornir_collection/cisco/support_api/cisco_maintenance_report.py +221 -0
  29. nornir_collection/cisco/support_api/cisco_support.py +727 -0
  30. nornir_collection/cisco/support_api/reports.py +747 -0
  31. nornir_collection/cisco/support_api/utils.py +316 -0
  32. nornir_collection/fortinet/__init__.py +0 -0
  33. nornir_collection/fortinet/utils.py +36 -0
  34. nornir_collection/git.py +224 -0
  35. nornir_collection/netbox/__init__.py +0 -0
  36. nornir_collection/netbox/custom_script.py +107 -0
  37. nornir_collection/netbox/inventory.py +360 -0
  38. nornir_collection/netbox/scan_prefixes_and_update_ip_addresses.py +989 -0
  39. nornir_collection/netbox/set_device_status.py +67 -0
  40. nornir_collection/netbox/sync_datasource.py +111 -0
  41. nornir_collection/netbox/update_cisco_inventory_data.py +158 -0
  42. nornir_collection/netbox/update_cisco_support_plugin_data.py +339 -0
  43. nornir_collection/netbox/update_fortinet_inventory_data.py +161 -0
  44. nornir_collection/netbox/update_purestorage_inventory_data.py +144 -0
  45. nornir_collection/netbox/utils.py +261 -0
  46. nornir_collection/netbox/verify_device_primary_ip.py +202 -0
  47. nornir_collection/nornir_plugins/__init__.py +0 -0
  48. nornir_collection/nornir_plugins/inventory/__init__.py +0 -0
  49. nornir_collection/nornir_plugins/inventory/netbox.py +250 -0
  50. nornir_collection/nornir_plugins/inventory/staggered_yaml.py +143 -0
  51. nornir_collection/nornir_plugins/inventory/utils.py +277 -0
  52. nornir_collection/purestorage/__init__.py +0 -0
  53. nornir_collection/purestorage/utils.py +53 -0
  54. nornir_collection/utils.py +741 -0
  55. nornir_collection-0.0.1.dist-info/LICENSE +21 -0
  56. nornir_collection-0.0.1.dist-info/METADATA +136 -0
  57. nornir_collection-0.0.1.dist-info/RECORD +59 -0
  58. nornir_collection-0.0.1.dist-info/WHEEL +5 -0
  59. nornir_collection-0.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,221 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ The main function will gather device serial numbers over different input options (argument list, Excel or
4
+ dynamically with Nornir) as well as the hostname. With the serial numbers the Cisco support APIs will be
5
+ called and the received information will be printed to stdout and optional processed into an Excel report.
6
+ Optionally a IBM TSS Maintenance Report can be added with an argument to compare and analyze the IBM TSS
7
+ information against the received data from the Cisco support APIs. Also these additional data will be
8
+ processed into an Excel report and saved to the local disk.
9
+ """
10
+
11
+ import argparse
12
+ from nornir.core import Nornir
13
+ from nornir_collection.nornir_plugins.inventory.utils import init_nornir
14
+ from nornir_collection.cisco.support_api.utils import (
15
+ init_args_for_cisco_maintenance,
16
+ prepare_nornir_data,
17
+ prepare_static_serials,
18
+ )
19
+ from nornir_collection.cisco.support_api.reports import (
20
+ create_pandas_dataframe_for_report,
21
+ generate_cisco_maintenance_report,
22
+ )
23
+ from nornir_collection.cisco.support_api.cisco_support import (
24
+ cisco_support_check_authentication,
25
+ get_sni_owner_coverage_by_serial_number,
26
+ get_sni_coverage_summary_by_serial_numbers,
27
+ get_eox_by_serial_numbers,
28
+ get_ss_suggested_release_by_pid,
29
+ print_sni_owner_coverage_by_serial_number,
30
+ print_sni_coverage_summary_by_serial_numbers,
31
+ print_eox_by_serial_numbers,
32
+ print_get_ss_suggested_release_by_pid,
33
+ )
34
+ from nornir_collection.utils import (
35
+ print_task_title,
36
+ exit_info,
37
+ exit_error,
38
+ construct_filename_with_current_date,
39
+ load_yaml_file,
40
+ )
41
+
42
+
43
+ #### Internal Use Functions #################################################################################
44
+
45
+
46
+ def _create_report_config(args: argparse.Namespace, nr: Nornir = False) -> dict:
47
+ """
48
+ TBD
49
+ """
50
+ # pylint: disable=invalid-name
51
+
52
+ # Create a dict for the report configuration specifications
53
+ report_cfg = {}
54
+
55
+ # Create the report configuration if Nornir is used for dynamically data gathering
56
+ if nr:
57
+ # Get the report_config string from the Nornir inventory for later YAML file load
58
+ # Get the report_file string from the Nornir inventory for later destination file constructing
59
+ if args.report:
60
+ report_cfg["yaml_config"] = nr.inventory.defaults.data["cisco_maintenance_report"]["yaml_config"]
61
+ report_cfg["yaml_config"] = nr.inventory.defaults.data["cisco_maintenance_report"]["yaml_config"]
62
+ report_cfg["excel_file"] = nr.inventory.defaults.data["cisco_maintenance_report"]["excel_file"]
63
+ # Get the ibm_tss_report file from the Nornir inventory
64
+ if args.tss:
65
+ report_cfg["tss_file"] = nr.inventory.defaults.data["cisco_maintenance_report"]["tss_file"]
66
+
67
+ return report_cfg
68
+
69
+ # Create the report configuration if static provided data with an Excel or the --serials argument is used
70
+ # Create the report_config string for later YAML file load
71
+ report_cfg["yaml_config"] = "reports/src/report_config.yaml"
72
+ # Create the report_file string for later destination file constructing
73
+ report_cfg["excel_file"] = (
74
+ args.excel if hasattr(args, "excel") else "reports/cisco_maintenance_report.xlsx"
75
+ )
76
+ # Set the ibm_tss_report file
77
+ if args.tss:
78
+ report_cfg["tss_file"] = args.tss
79
+
80
+ return report_cfg
81
+
82
+
83
+ def _load_report_yaml_config(report_cfg, args):
84
+ """
85
+ TBD
86
+ """
87
+ # If the report_config file string is available
88
+ if "yaml_config" in report_cfg:
89
+ # Load the report variables from the YAML config file as python dictionary
90
+ config = load_yaml_file(
91
+ file=report_cfg["yaml_config"], text="PYTHON load report yaml config file", verbose=args.verbose
92
+ )
93
+ # Update the report_cfg dict with the loaded yaml config
94
+ report_cfg.update(**config)
95
+
96
+ # Select the correct string order based on the TSS arguments
97
+ if args.nornir:
98
+ df_order = "nornir_column_order_with_tss" if args.tss else "nornir_column_order"
99
+ else:
100
+ df_order = "static_column_order_with_tss" if args.tss else "static_column_order"
101
+
102
+ # Set the df_order to False if the key don't exist
103
+ report_cfg["df_order"] = report_cfg[df_order] if df_order in report_cfg else False
104
+ # Select the correct dataframe order for all dates regarding conditional formatting
105
+ # Set the df_date_columns to False if the key don't exist
106
+ report_cfg["df_date_columns"] = (
107
+ report_cfg["grace_period_cols"] if "grace_period_cols" in report_cfg else False
108
+ )
109
+
110
+ return report_cfg
111
+
112
+
113
+ def main(nr_config: str = "inventory/nr_config.yaml") -> None:
114
+ """Main function is executed when the file is directly executed."""
115
+ # pylint: disable=invalid-name
116
+
117
+ #### Initialize Script and Nornir #######################################################################
118
+
119
+ # Initialize the script arguments with ArgParse to define the further script execution
120
+ args = init_args_for_cisco_maintenance()
121
+
122
+ if args.nornir:
123
+ # Initialize, transform and filter the Nornir inventory are return the filtered Nornir object
124
+ nr = init_nornir(
125
+ config_file=nr_config,
126
+ env_mandatory={
127
+ "env_client_key": "CISCO_SUPPORT_API_KEY",
128
+ "env_client_secret": "CISCO_SUPPORT_API_SECRET",
129
+ },
130
+ args=args,
131
+ add_netbox_data=None,
132
+ )
133
+
134
+ print_task_title("Prepare Nornir Data")
135
+ # Prepare the serials dict for later processing
136
+ serials = prepare_nornir_data(nr=nr, verbose=args.verbose)
137
+
138
+ # Prepare the Cisco support API key and the secret in a tuple
139
+ api_creds = (
140
+ nr.inventory.defaults.data["cisco_support_api_creds"]["env_client_key"],
141
+ nr.inventory.defaults.data["cisco_support_api_creds"]["env_client_secret"],
142
+ )
143
+ # Create a dict for the report configuration specifications
144
+ report_cfg = _create_report_config(nr=nr, args=args)
145
+
146
+ else:
147
+ print_task_title("Prepare Static Data")
148
+ # Prepare the serials dict for later processing
149
+ serials = prepare_static_serials(args=args)
150
+
151
+ # Prepare the Cisco support API key and the secret in a tuple
152
+ api_creds = (args.api_key, args.api_secret)
153
+ # Create a dict for the report configuration specifications
154
+ report_cfg = _create_report_config(args=args)
155
+
156
+ #### Get Cisco Support-API Data ##########################################################################
157
+
158
+ print_task_title("Check Cisco support API OAuth2 client credentials grant flow")
159
+
160
+ # Check the API authentication with the client key and secret to get an access token
161
+ # The script will exit with an error message in case the authentication fails
162
+ if not cisco_support_check_authentication(api_creds=api_creds, verbose=args.verbose, silent=False):
163
+ exit_error(task_text="NORNIR cisco maintenance status", text="Bad news! The script failed!")
164
+
165
+ print_task_title("Gather Cisco support API data for serial numbers")
166
+
167
+ # Cisco Support API Call SNIgetOwnerCoverageStatusBySerialNumbers and update the serials dictionary
168
+ serials = get_sni_owner_coverage_by_serial_number(serial_dict=serials, api_creds=api_creds)
169
+ # Print the results of get_sni_owner_coverage_by_serial_number()
170
+ print_sni_owner_coverage_by_serial_number(serial_dict=serials, verbose=args.verbose)
171
+
172
+ # Cisco Support API Call SNIgetCoverageSummaryBySerialNumbers and update the serials dictionary
173
+ serials = get_sni_coverage_summary_by_serial_numbers(serial_dict=serials, api_creds=api_creds)
174
+ # Print the results of get_sni_coverage_summary_by_serial_numbers()
175
+ print_sni_coverage_summary_by_serial_numbers(serial_dict=serials, verbose=args.verbose)
176
+
177
+ # Cisco Support API Call EOXgetBySerialNumbers and update the serials dictionary
178
+ serials = get_eox_by_serial_numbers(serial_dict=serials, api_creds=api_creds)
179
+ # Print the results of get_eox_by_serial_numbers()
180
+ print_eox_by_serial_numbers(serial_dict=serials, verbose=args.verbose)
181
+
182
+ # Cisco Support API Call getSuggestedReleasesByProductIDs and update the serials dictionary
183
+ serials = get_ss_suggested_release_by_pid(serial_dict=serials, api_creds=api_creds)
184
+ # Print the results of get_ss_suggested_release_by_pid()
185
+ print_get_ss_suggested_release_by_pid(serial_dict=serials, verbose=args.verbose)
186
+
187
+ #### Prepate the Pandas report data ######################################################################
188
+
189
+ # Exit the script if the args.report argument is not set
190
+ if not args.report:
191
+ exit_info(
192
+ task_text="NORNIR cisco maintenance status", text="Good news! The Script successfully finished!"
193
+ )
194
+
195
+ print_task_title("Prepare Cisco maintenance report")
196
+
197
+ # Load the yaml report config file
198
+ report_cfg = _load_report_yaml_config(report_cfg=report_cfg, args=args)
199
+ # Prepare the report data and create a pandas dataframe
200
+ df = create_pandas_dataframe_for_report(serials_dict=serials, report_cfg=report_cfg, args=args)
201
+
202
+ #### Generate Cisco maintenance report Excel #############################################################
203
+
204
+ print_task_title("Generate Cisco maintenance report")
205
+
206
+ # Construct the new destination path and filename from the report_file string variable
207
+ report_cfg["excel_file"] = construct_filename_with_current_date(
208
+ name="PYTHON construct destination file",
209
+ filename=report_cfg["excel_file"],
210
+ silent=False,
211
+ )
212
+ # Generate the Cisco Maintenance report Excel file specified by the report_file with the pandas dataframe
213
+ generate_cisco_maintenance_report(df=df, report_cfg=report_cfg)
214
+
215
+ exit_info(
216
+ task_text="NORNIR cisco maintenance status", text="Good news! The Script successfully finished!"
217
+ )
218
+
219
+
220
+ if __name__ == "__main__":
221
+ main()