4747 Python 3.8
4848 Python 3.9
4949 Python 3.10
50+ Python 3.11
5051
5152.. note :: Old pythons: For Python 2.7 and PyPy use versions 1.x.x, python 3.4 use versions 2.x.x, python 3.5 and PyPy 3.5 use versions 3.x.x
5253
@@ -97,7 +98,7 @@ Basic initialization of `SSHClient` can be done without construction of specific
9798 client = exec_helpers.SSHClient(host, username = " username" , password = " password" )
9899
99100 If ssh agent is running - keys will be collected by paramiko automatically,
100- but if keys are in specific location - it should be loaded manually and provided as iterable object of `paramiko.RSAKey `.
101+ but if keys are in specific location - it should be loaded manually and provided as iterable object of `paramiko.PKey `.
101102
102103For advanced cases or re-use of credentials, `SSHAuth ` object should be used.
103104It can be collected from connection object via property `auth `.
@@ -107,12 +108,12 @@ Creation from scratch:
107108.. code-block :: python
108109
109110 auth = exec_helpers.SSHAuth(
110- username = ' username' , # type: Optional [ str ]
111- password = ' password' , # type: Optional [ str ]
112- key = None , # type: Optional [ paramiko . RSAKey ]
113- keys = None , # type: Optional [ Iterable [ paramiko . RSAKey ]],
114- key_filename = None , # type: Union [ List [ str ], None ]
115- passphrase = None , # type: Optional [ str ]
111+ username = ' username' , # str | None
112+ password = ' password' , # str | None
113+ key = None , # type: paramiko . PKey | None
114+ keys = None , # type: Iterable [ paramiko . PKey ] | None
115+ key_filename = None , # type: List [ str ] | None
116+ passphrase = None , # str | None
116117 )
117118
118119 Key is a main connection key (always tried first) and keys are alternate keys.
@@ -141,12 +142,12 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
141142.. code-block :: python
142143
143144 result: ExecResult = helper.execute(
144- command, # type: Union [ str , Iterable [ str ] ]
145+ command, # type: str | Iterable [ str ]
145146 verbose = False , # type: bool
146- timeout = 1 * 60 * 60 , # type: Union [ int , float , None ]
147+ timeout = 1 * 60 * 60 , # type: int | float | None
147148 # Keyword only:
148- log_mask_re = None , # type: Optional [ str ]
149- stdin = None , # type: Union [ bytes , str , bytearray , None ]
149+ log_mask_re = None , # str | None
150+ stdin = None , # type: bytes | str | bytearray | None
150151 open_stdout = True , # type: bool
151152 log_stdout = True , # type: bool
152153 open_stderr = True , # type: bool
@@ -158,51 +159,51 @@ This methods are almost the same for `SSHClient` and `Subprocess`, except specif
158159 .. code-block :: python
159160
160161 result: ExecResult = helper.check_call(
161- command, # type: Union [ str , Iterable [ str ] ]
162+ command, # type: str | Iterable [ str ]
162163 verbose = False , # type: bool
163- timeout = 1 * 60 * 60 , # type: type : Union [ int , float , None ]
164- error_info = None , # type: Optional [ str ]
165- expected = (0 ,), # type: Iterable [ Union [ int , ExitCodes ] ]
164+ timeout = 1 * 60 * 60 , # type: type : int | float | None
165+ error_info = None , # str | None
166+ expected = (0 ,), # type: Iterable [ int | ExitCodes ]
166167 raise_on_err = True , # type: bool
167168 # Keyword only:
168- log_mask_re = None , # type: Optional [ str ]
169- stdin = None , # type: Union [ bytes , str , bytearray , None ]
169+ log_mask_re = None , # str | None
170+ stdin = None , # type: bytes | str | bytearray | None
170171 open_stdout = True , # type: bool
171172 log_stdout = True , # type: bool
172173 open_stderr = True , # type: bool
173174 log_stderr = True , # type: bool
174- exception_class = CalledProcessError, # Type [CalledProcessError]
175+ exception_class = CalledProcessError, # type [CalledProcessError]
175176 ** kwargs
176177 )
177178
178179 .. code-block :: python
179180
180181 result: ExecResult = helper.check_stderr(
181- command, # type: Union [ str , Iterable [ str ] ]
182+ command, # type: str | Iterable [ str ]
182183 verbose = False , # type: bool
183- timeout = 1 * 60 * 60 , # type: type : Union [ int , float , None ]
184- error_info = None , # type: Optional [ str ]
184+ timeout = 1 * 60 * 60 , # type: type : int | float | None
185+ error_info = None , # str | None
185186 raise_on_err = True , # type: bool
186187 # Keyword only:
187- expected = (0 ,), # Iterable[Union[ int, ExitCodes] ]
188- log_mask_re = None , # type: Optional [ str ]
189- stdin = None , # type: Union [ bytes , str , bytearray , None ]
188+ expected = (0 ,), # Iterable[int | ExitCodes]
189+ log_mask_re = None , # str | None
190+ stdin = None , # type: bytes | str | bytearray | None
190191 open_stdout = True , # type: bool
191192 log_stdout = True , # type: bool
192193 open_stderr = True , # type: bool
193194 log_stderr = True , # type: bool
194- exception_class = CalledProcessError, # Type [CalledProcessError]
195+ exception_class = CalledProcessError, # type [CalledProcessError]
195196 )
196197
197198 .. code-block :: python
198199
199200 result: ExecResult = helper( # Lazy way: instances are callable and uses `execute`.
200- command, # type: Union [ str , Iterable [ str ] ]
201+ command, # type: str | Iterable [ str ]
201202 verbose = False , # type: bool
202- timeout = 1 * 60 * 60 , # type: Union [ int , float , None ]
203+ timeout = 1 * 60 * 60 , # type: int | float | None
203204 # Keyword only:
204- log_mask_re = None , # type: Optional [ str ]
205- stdin = None , # type: Union [ bytes , str , bytearray , None ]
205+ log_mask_re = None , # str | None
206+ stdin = None , # type: bytes | str | bytearray | None
206207 open_stdout = True , # type: bool
207208 log_stdout = True , # type: bool
208209 open_stderr = True , # type: bool
@@ -226,10 +227,10 @@ All regex matched groups will be replaced by `'<*masked*>'`.
226227.. code-block :: python
227228
228229 result: ExecResult = helper.execute(
229- command = " AUTH='top_secret_key'; run command" , # type: Union [ str , Iterable [ str ] ]
230+ command = " AUTH='top_secret_key'; run command" , # type: str | Iterable [ str ]
230231 verbose = False , # type: bool
231232 timeout = 1 * 60 * 60 , # type: Optional [ int ]
232- log_mask_re = r " AUTH\s * =\s * '( \w + ) '" # type: Optional [ str ]
233+ log_mask_re = r " AUTH\s * =\s * '( \w + ) '" # str | None
233234 )
234235
235236 `result.cmd ` will be equal to `AUTH='<*masked*>'; run command `
@@ -276,18 +277,18 @@ Possible to call commands in parallel on multiple hosts if it's not produce huge
276277
277278 results: Dict[Tuple[str , int ], ExecResult] = SSHClient.execute_together(
278279 remotes, # type: Iterable [ SSHClient ]
279- command, # type: Union [ str , Iterable [ str ] ]
280- timeout = 1 * 60 * 60 , # type: type : Union [ int , float , None ]
281- expected = (0 ,), # type: Iterable [ Union [ int , ExitCodes ] ]
280+ command, # type: str | Iterable [ str ]
281+ timeout = 1 * 60 * 60 , # type: type : int | float | None
282+ expected = (0 ,), # type: Iterable [ int | ExitCodes ]
282283 raise_on_err = True , # type: bool
283284 # Keyword only:
284- stdin = None , # type: Union [ bytes , str , bytearray , None ]
285+ stdin = None , # type: bytes | str | bytearray | None
285286 open_stdout = True , # type: bool
286287 open_stderr = True , # type: bool
287- log_mask_re = None , # type: Optional [ str ]
288- exception_class = ParallelCallProcessError # Type [ParallelCallProcessError]
288+ log_mask_re = None , # str | None
289+ exception_class = ParallelCallProcessError # type [ParallelCallProcessError]
289290 )
290- results # type: Dict [ Tuple [ str , int ], exec_result . ExecResult ]
291+ results # type: dict [ Tuple [ str , int ], exec_result . ExecResult ]
291292
292293 Results is a dict with keys = (hostname, port) and and results in values.
293294By default execute_together raises exception if unexpected return code on any remote.
@@ -306,18 +307,18 @@ For execute through SSH host can be used `execute_through_host` method:
306307
307308 result: ExecResult = client.execute_through_host(
308309 hostname, # type: str
309- command, # type: Union [ str , Iterable [ str ] ]
310+ command, # type: str | Iterable [ str ]
310311 # Keyword only:
311- auth = None , # type: Optional [ SSHAuth ]
312+ auth = None , # type: SSHAuth | None
312313 port = 22 , # type: int
313- timeout = 1 * 60 * 60 , # type: type : Union [ int , float , None ]
314+ timeout = 1 * 60 * 60 , # type: type : int | float | None
314315 verbose = False , # type: bool
315- stdin = None , # type: Union [ bytes , str , bytearray , None ]
316+ stdin = None , # type: bytes | str | bytearray | None
316317 open_stdout = True , # type: bool
317318 log_stdout = True , # type: bool
318319 open_stderr = True , # type: bool
319320 log_stderr = True , # type: bool
320- log_mask_re = None , # type: Optional [ str ]
321+ log_mask_re = None , # str | None
321322 get_pty = False , # type: bool
322323 width = 80 , # type: int
323324 height = 24 # type: int
@@ -416,9 +417,9 @@ Example:
416417
417418 async with helper:
418419 result: ExecResult = await helper.execute(
419- command, # type: Union [ str , Iterable [ str ] ]
420+ command, # type: str | Iterable [ str ]
420421 verbose = False , # type: bool
421- timeout = 1 * 60 * 60 , # type: Union [ int , float , None ]
422+ timeout = 1 * 60 * 60 , # type: int | float | None
422423 ** kwargs
423424 )
424425
0 commit comments