root / ncclient / transport / error.py @ d095a59e
History | View | Annotate | Download (1.5 kB)
1 |
# Copyright 2009 Shikhar Bhushan
|
---|---|
2 |
#
|
3 |
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
# you may not use this file except in compliance with the License.
|
5 |
# You may obtain a copy of the License at
|
6 |
#
|
7 |
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
#
|
9 |
# Unless required by applicable law or agreed to in writing, software
|
10 |
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
# See the License for the specific language governing permissions and
|
13 |
# limitations under the License.
|
14 |
|
15 |
from ncclient import ClientError |
16 |
|
17 |
class SessionError(ClientError): |
18 |
pass
|
19 |
|
20 |
class SSHError(SessionError): |
21 |
pass
|
22 |
|
23 |
class SSHUnknownHostError(SSHError): |
24 |
|
25 |
def __init__(self, hostname, key): |
26 |
self.hostname = hostname
|
27 |
self.key = key
|
28 |
|
29 |
def __str__(self): |
30 |
from binascii import hexlify |
31 |
return ('Unknown host key [%s] for [%s]' % |
32 |
(hexlify(self.key.get_fingerprint()), self.hostname)) |
33 |
|
34 |
class SSHAuthenticationError(SSHError): |
35 |
pass
|
36 |
|
37 |
class SSHSessionClosedError(SSHError): |
38 |
|
39 |
def __init__(self, in_buf, out_buf=None): |
40 |
SessionError.__init__(self, "Unexpected session close.") |
41 |
self._in_buf, self._out_buf = in_buf, out_buf |
42 |
|
43 |
def __str__(self): |
44 |
msg = SessionError(self).__str__()
|
45 |
if self._in_buf: |
46 |
msg += '\nIN_BUFFER: %s' % self._in_buf |
47 |
if self._out_buf: |
48 |
msg += '\nOUT_BUFFER: %s' % self._out_buf |
49 |
return msg
|