You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pan_os_upgrade/components/device.py
+19-34Lines changed: 19 additions & 34 deletions
Original file line number
Diff line number
Diff line change
@@ -35,42 +35,34 @@
35
35
36
36
# Common setup for all subcommands
37
37
defcommon_setup(
38
-
hostname: str,
39
-
username: str,
40
-
password: str,
41
38
settings_file: LazySettings,
42
39
settings_file_path: Path,
43
-
) ->PanDevice:
40
+
) ->None:
44
41
"""
45
-
Initializes the environment for interacting with a Palo Alto Networks device, including directory setup, logging configuration, and establishing a device connection.
42
+
Initializes the environment for interacting with a Palo Alto Networks device, including directory setupand logging configuration.
46
43
47
-
This function consolidates essential preparatory steps required before performing operations on a Palo Alto Networks device. It ensures the creation of necessary directories for organized data storage and logs, sets up logging with a configurable verbosity level, and establishes a secure connection to the device using the provided API credentials. The function is designed to return a `PanDevice` object, which could be a `Firewall` or `Panorama` instance, ready for subsequent API interactions.
44
+
This function consolidates essential preparatory steps required before performing operations on a Palo Alto Networks device. It ensures the creation of necessary directories for organized data storage and logs, and sets up logging with a configurable verbosity level.
48
45
49
46
Parameters
50
47
----------
51
-
hostname : str
52
-
The network address or DNS name of the Palo Alto Networks device to connect to.
53
-
username : str
54
-
The API username for authenticating with the device.
55
-
password : str
56
-
The API password for authenticating with the device.
57
-
58
-
Returns
59
-
-------
60
-
PanDevice
61
-
A connected `PanDevice` instance, representing the target Palo Alto Networks device, fully initialized and ready for further API operations.
48
+
settings_file : LazySettings
49
+
The LazySettings object containing configurations loaded from the settings file.
50
+
settings_file_path : Path
51
+
The filesystem path to the settings.yaml file, which contains custom configuration settings.
# Ensures necessary directories exist, and logging is configured.
68
61
69
62
Notes
70
63
-----
71
64
- Directory setup is performed only once; existing directories are not modified.
72
65
- Logging configuration affects the entire application's logging behavior; the log level can be overridden by `settings.yaml` if `SETTINGS_FILE_PATH` is detected in the function.
73
-
- A successful device connection is critical for the function to return; otherwise, it may raise exceptions based on connection issues.
74
66
75
67
The ability to override default settings with `settings.yaml` is supported for the log level configuration in this function if `SETTINGS_FILE_PATH` is utilized within `configure_logging`.
76
68
"""
@@ -93,14 +85,6 @@ def common_setup(
93
85
settings_file_path=settings_file_path,
94
86
)
95
87
96
-
# Connect to the device
97
-
device=connect_to_host(
98
-
hostname=hostname,
99
-
username=username,
100
-
password=password,
101
-
)
102
-
returndevice
103
-
104
88
105
89
defconnect_to_host(
106
90
hostname: str,
@@ -115,16 +99,16 @@ def connect_to_host(
115
99
Parameters
116
100
----------
117
101
hostname : str
118
-
The hostname or IP address of the target Palo Alto Networks device.
119
-
api_username : str
120
-
The API username for authentication.
121
-
api_password : str
122
-
The password corresponding to the API username.
102
+
The network address or DNS name of the Palo Alto Networks device to connect to.
103
+
username : str
104
+
The API username for authenticating with the device.
105
+
password : str
106
+
The API password for authenticating with the device.
123
107
124
108
Returns
125
109
-------
126
110
PanDevice
127
-
A PanDevice object representing the connected device, which may be a Firewall or Panorama instance.
111
+
A PanDevice object representing the connected device, which may be a Firewall or Panorama instance, ready for further API operations.
128
112
129
113
Raises
130
114
------
@@ -146,6 +130,7 @@ def connect_to_host(
146
130
- Initiating a connection to a device is a prerequisite for performing any operational or configuration tasks via the API.
147
131
- The function's error handling provides clear diagnostics, aiding in troubleshooting connection issues.
148
132
- Configuration settings for the connection, such as timeout periods and retry attempts, can be customized through the `settings.yaml` file, if `settings_file_path` is utilized within the function.
133
+
- A successful device connection is critical for the function to return; otherwise, it may raise exceptions based on connection issues.
- The function's utility extends beyond mere validation, contributing to the tool's overall resilience and user-friendliness by preventing erroneous network operations.
826
826
- Default settings can be overridden by configurations specified in a `settings.yaml` file if `SETTINGS_FILE_PATH` is used within the script, allowing for customized validation logic based on the application's needs.
0 commit comments