Statistics
| Branch: | Tag: | Revision:

root / ncclient / session / error.py @ f5c75f88

History | View | Annotate | Download (1.7 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 RemoteClosedError(SessionError):
21
    
22
    def __init__(self, in_buf, out_buf=None):
23
        SessionError.__init__(self)
24
        self._in_buf, self._out_buf = in_buf, out_buf
25
        
26
    def __str__(self):
27
        msg = 'Session closed by remote endpoint.'
28
        if self._in_buf:
29
            msg += '\nIN_BUFFER: %s' % self._in_buf
30
        if self._out_buf:
31
            msg += '\nOUT_BUFFER: %s' % self._out_buf
32
        return msg
33

    
34
class AuthenticationError(SessionError):
35
    pass
36

    
37
class SSHError(SessionError):
38
    pass
39

    
40
class SSHUnknownHostError(SSHError):
41
    
42
    def __init__(self, hostname, key):
43
        self.hostname = hostname
44
        self.key = key
45
    
46
    def __str__(self):
47
        from binascii import hexlify
48
        return ('Unknown host key [%s] for [%s]' %
49
                (hexlify(self.key.get_fingerprint()), self.hostname))
50

    
51
class SSHAuthenticationError(AuthenticationError, SSHError):
52
    'wraps a paramiko exception that occured during auth'
53
    
54
    def __init__(self, ex):
55
        self.ex = ex
56
    
57
    def __repr__(self):
58
        return repr(ex)