@@ -6,22 +6,24 @@ API: SSHClient and SSHAuth.
6
6
.. py :module :: exec_helpers
7
7
.. py :currentmodule :: exec_helpers
8
8
9
- .. py :class :: SSHClient(host, port = 22 , username = None , password = None , private_keys = None , auth = None , )
9
+ .. py :class :: SSHClient
10
10
11
11
SSHClient helper.
12
12
13
- :param host: remote hostname
14
- :type host: ``str ``
15
- :param port: remote ssh port
16
- :type port: ``int ``
17
- :param username: remote username.
18
- :type username: ``typing.Optional[str] ``
19
- :param password: remote password
20
- :type password: ``typing.Optional[str] ``
21
- :param private_keys: private keys for connection
22
- :type private_keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]] ``
23
- :param auth: credentials for connection
24
- :type auth: ``typing.Optional[SSHAuth] ``
13
+ .. py :method :: __init__ (host, port = 22 , username = None , password = None , private_keys = None , auth = None , )
14
+
15
+ :param host: remote hostname
16
+ :type host: ``str ``
17
+ :param port: remote ssh port
18
+ :type port: ``int ``
19
+ :param username: remote username.
20
+ :type username: ``typing.Optional[str] ``
21
+ :param password: remote password
22
+ :type password: ``typing.Optional[str] ``
23
+ :param private_keys: private keys for connection
24
+ :type private_keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]] ``
25
+ :param auth: credentials for connection
26
+ :type auth: typing.Optional[SSHAuth]
25
27
26
28
.. note :: auth has priority over username/password/private_keys
27
29
@@ -37,9 +39,10 @@ API: SSHClient and SSHAuth.
37
39
38
40
.. py :attribute :: auth
39
41
40
- ``SSHAuth ``
41
42
Internal authorisation object
42
43
44
+ :rtype: SSHAuth
45
+
43
46
.. py :attribute :: hostname
44
47
45
48
``str ``
@@ -72,6 +75,16 @@ API: SSHClient and SSHAuth.
72
75
73
76
Reconnect SSH session
74
77
78
+ .. py :method :: __enter__ ()
79
+
80
+ Open context manager
81
+
82
+ .. py :method :: __exit__ (self , exc_type, exc_val, exc_tb)
83
+
84
+ Close context manager and disconnect
85
+
86
+ .. versionchanged :: 1.0 - disconnect enforced on close
87
+
75
88
.. py :method :: sudo(enforce = None )
76
89
77
90
Context manager getter for sudo operation
@@ -99,7 +112,7 @@ API: SSHClient and SSHAuth.
99
112
:type verbose: ``bool ``
100
113
:param timeout: Timeout for command execution.
101
114
:type timeout: ``typing.Optional[int] ``
102
- :rtype: `` ExecResult ``
115
+ :rtype: ExecResult
103
116
:raises: ExecHelperTimeoutError
104
117
105
118
.. py :method :: check_call(command, verbose = False , timeout = None , error_info = None , expected = None , raise_on_err = True , ** kwargs)
@@ -118,7 +131,7 @@ API: SSHClient and SSHAuth.
118
131
:type expected: ``typing.Optional[typing.Iterable[int]] ``
119
132
:param raise_on_err: Raise exception on unexpected return code
120
133
:type raise_on_err: ``bool ``
121
- :rtype: `` ExecResult ``
134
+ :rtype: ExecResult
122
135
:raises: CalledProcessError
123
136
124
137
.. py :method :: check_stderr(command, verbose = False , timeout = None , error_info = None , raise_on_err = True , ** kwargs)
@@ -135,7 +148,7 @@ API: SSHClient and SSHAuth.
135
148
:type error_info: ``typing.Optional[str] ``
136
149
:param raise_on_err: Raise exception on unexpected return code
137
150
:type raise_on_err: ``bool ``
138
- :rtype: `` ExecResult ``
151
+ :rtype: ExecResult
139
152
:raises: CalledProcessError
140
153
141
154
.. note :: expected return codes can be overridden via kwargs.
@@ -149,7 +162,7 @@ API: SSHClient and SSHAuth.
149
162
:param command: Command for execution
150
163
:type command: ``str ``
151
164
:param auth: credentials for target machine
152
- :type auth: `` typing.Optional[SSHAuth] ``
165
+ :type auth: typing.Optional[SSHAuth]
153
166
:param target_port: target port
154
167
:type target_port: ``int ``
155
168
:param verbose: Produce log.info records for command call and output
@@ -158,7 +171,7 @@ API: SSHClient and SSHAuth.
158
171
:type timeout: ``typing.Optional[int] ``
159
172
:param get_pty: open PTY on target machine
160
173
:type get_pty: ``bool ``
161
- :rtype: `` ExecResult ``
174
+ :rtype: ExecResult
162
175
:raises: ExecHelperTimeoutError
163
176
164
177
.. py :classmethod :: execute_together(remotes, command, timeout = None , expected = None , raise_on_err = True , ** kwargs)
@@ -176,7 +189,7 @@ API: SSHClient and SSHAuth.
176
189
:param raise_on_err: Raise exception on unexpected return code
177
190
:type raise_on_err: ``bool ``
178
191
:return: dictionary {(hostname, port): result}
179
- :rtype: `` typing.Dict[typing.Tuple[str, int], exec_result. ExecResult] ``
192
+ :rtype: typing.Dict[typing.Tuple[str, int], ExecResult]
180
193
:raises: ParallelCallProcessError
181
194
:raises: ParallelCallExceptions
182
195
@@ -201,6 +214,17 @@ API: SSHClient and SSHAuth.
201
214
:type path: ``str ``
202
215
:rtype: ``paramiko.sftp_attr.SFTPAttributes ``
203
216
217
+ .. py :method :: utime(path, times = None ):
218
+
219
+ Set atime, mtime.
220
+
221
+ :param path: filesystem object path
222
+ :type path: str
223
+ :param times: (atime, mtime)
224
+ :type times: typing.Optional[typing.Tuple[int, int]]
225
+
226
+ .. versionadded :: 1.0.0
227
+
204
228
.. py :method :: isfile(path)
205
229
206
230
Check, that path is file using SFTP session.
@@ -215,6 +239,8 @@ API: SSHClient and SSHAuth.
215
239
:type path: ``str ``
216
240
:rtype: ``bool ``
217
241
242
+ **Non standard methods: **
243
+
218
244
.. py :method :: mkdir(path)
219
245
220
246
run 'mkdir -p path' on remote.
@@ -244,22 +270,31 @@ API: SSHClient and SSHAuth.
244
270
:rtype: ``bool ``
245
271
246
272
247
- .. py :class :: SSHAuth(username = None , password = None , key = None , keys = None , )
273
+ .. py :class :: SSHAuth(object )
248
274
249
275
SSH credentials object.
250
276
251
277
Used to authorize SSHClient.
252
278
Single SSHAuth object is associated with single host:port.
253
279
Password and key is private, other data is read-only.
254
280
255
- :param username: remote username.
256
- :type username: ``typing.Optional[str] ``
257
- :param password: remote password
258
- :type password: ``typing.Optional[str] ``
259
- :param key: Main connection key
260
- :type key: ``typing.Optional[paramiko.RSAKey] ``
261
- :param keys: Alternate connection keys
262
- :type keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]] ``
281
+ .. py :method :: __init__ (username = None , password = None , key = None , keys = None , )
282
+
283
+ :param username: remote username.
284
+ :type username: ``typing.Optional[str] ``
285
+ :param password: remote password
286
+ :type password: ``typing.Optional[str] ``
287
+ :param key: Main connection key
288
+ :type key: ``typing.Optional[paramiko.RSAKey] ``
289
+ :param keys: Alternate connection keys
290
+ :type keys: ``typing.Optional[typing.Iterable[paramiko.RSAKey]] ``
291
+ :param key_filename: filename(s) for additional key files
292
+ :type key_filename: ``typing.Union[typing.List[str], str, None] ``
293
+ :param passphrase: passphrase for keys. Need, if differs from password
294
+ :type passphrase: ``typing.Optional[str] ``
295
+
296
+ .. versionchanged :: 1.0
297
+ added: key_filename, passphrase arguments
263
298
264
299
.. py :attribute :: username
265
300
@@ -270,6 +305,13 @@ API: SSHClient and SSHAuth.
270
305
``typing.Optional[str] ``
271
306
public key for stored private key if presents else None
272
307
308
+ .. py :attribute :: key_filename
309
+
310
+ ``typing.Union[typing.List[str], str, None] ``
311
+ Key filename(s).
312
+
313
+ .. versionadded :: 1.0
314
+
273
315
.. py :method :: enter_password(self , tgt)
274
316
Enter password to STDIN.
275
317
0 commit comments