Revision 4bc8021f ncclient/transport/ssh.py
b/ncclient/transport/ssh.py | ||
---|---|---|
25 | 25 |
from session import Session |
26 | 26 |
|
27 | 27 |
import logging |
28 |
logger = logging.getLogger('ncclient.transport.ssh')
|
|
28 |
logger = logging.getLogger("ncclient.transport.ssh")
|
|
29 | 29 |
|
30 | 30 |
BUF_SIZE = 4096 |
31 | 31 |
MSG_DELIM = "]]>]]>" |
32 | 32 |
TICK = 0.1 |
33 | 33 |
|
34 | 34 |
def default_unknown_host_cb(host, fingerprint): |
35 |
"""An `unknown host callback` returns :const:`True` if it finds the key |
|
36 |
acceptable, and :const:`False` if not.
|
|
35 |
"""An `unknown host callback` returns :const:`True` if it finds the key acceptable, and
|
|
36 |
:const:`False` if not. |
|
37 | 37 |
|
38 |
This default callback always returns :const:`False`, which would lead to |
|
39 |
:meth:`connect` raising a :exc:`SSHUnknownHost` exception. |
|
40 |
|
|
41 |
Supply another valid callback if you need to verify the host key |
|
42 |
programatically. |
|
38 |
This default callback always returns :const:`False`, which would lead to :meth:`connect` raising |
|
39 |
a :exc:`SSHUnknownHost` exception. |
|
40 |
|
|
41 |
Supply another valid callback if you need to verify the host key programatically. |
|
43 | 42 |
|
44 | 43 |
:arg host: the hostname that needs to be verified |
45 |
:type host: string
|
|
44 |
:type host: `string`
|
|
46 | 45 |
|
47 |
:arg fingerprint: a hex string representing the host key fingerprint |
|
48 |
:type fingerprint: string
|
|
46 |
:arg fingerprint: a hex string representing the host key fingerprint, colon-delimited e.g. *4b:69:6c:72:6f:79:20:77:61:73:20:68:65:72:65:21*
|
|
47 |
:type fingerprint: `string`
|
|
49 | 48 |
""" |
50 | 49 |
return False |
51 | 50 |
|
... | ... | |
71 | 70 |
self._parsing_pos = 0 |
72 | 71 |
|
73 | 72 |
def _parse(self): |
74 |
'''Messages ae delimited by MSG_DELIM. The buffer could have grown by a
|
|
73 |
"""Messages ae delimited by MSG_DELIM. The buffer could have grown by a
|
|
75 | 74 |
maximum of BUF_SIZE bytes everytime this method is called. Retains state |
76 | 75 |
across method calls and if a byte has been read it will not be |
77 |
considered again. ''' |
|
76 |
considered again. |
|
77 |
""" |
|
78 | 78 |
delim = MSG_DELIM |
79 | 79 |
n = len(delim) - 1 |
80 | 80 |
expect = self._parsing_state |
... | ... | |
115 | 115 |
self._parsing_pos = self._buffer.tell() |
116 | 116 |
|
117 | 117 |
def load_known_hosts(self, filename=None): |
118 |
"""Load host keys from a :file:`known_hosts`-style file. Can be called multiple |
|
119 |
times. |
|
118 |
"""Load host keys from a :file:`known_hosts`-style file. Can be called multiple times. |
|
120 | 119 |
|
121 | 120 |
If *filename* is not specified, looks in the default locations i.e. |
122 | 121 |
:file:`~/.ssh/known_hosts` and :file:`~/ssh/known_hosts` for Windows. |
... | ... | |
144 | 143 |
unknown_host_cb=default_unknown_host_cb, |
145 | 144 |
username=None, password=None, |
146 | 145 |
key_filename=None, allow_agent=True, look_for_keys=True): |
147 |
"""Connect via SSH and initialize the NETCONF session. First attempts |
|
148 |
the publickey authentication method and then password authentication.
|
|
146 |
"""Connect via SSH and initialize the NETCONF session. First attempts the publickey
|
|
147 |
authentication method and then password authentication. |
|
149 | 148 |
|
150 |
To disable attemting publickey authentication altogether, call with |
|
151 |
*allow_agent* and *look_for_keys* as :const:`False`.
|
|
149 |
To disable attemting publickey authentication altogether, call with *allow_agent* and
|
|
150 |
*look_for_keys* as :const:`False`. |
|
152 | 151 |
|
153 | 152 |
:arg host: the hostname or IP address to connect to |
154 | 153 |
:type host: `string` |
... | ... | |
156 | 155 |
:arg port: by default 830, but some devices use the default SSH port of 22 so this may need to be specified |
157 | 156 |
:type port: `int` |
158 | 157 |
|
159 |
:arg timeout: an optional timeout for the TCP handshake
|
|
158 |
:arg timeout: an optional timeout for socket connect
|
|
160 | 159 |
:type timeout: `int` |
161 | 160 |
|
162 |
:arg unknown_host_cb: called when a host key is not recognized
|
|
161 |
:arg unknown_host_cb: called when the server host key is not recognized
|
|
163 | 162 |
:type unknown_host_cb: see :meth:`signature <ssh.default_unknown_host_cb>` |
164 | 163 |
|
165 | 164 |
:arg username: the username to use for SSH authentication |
Also available in: Unified diff