Revision 13120135 src/session/ssh.py

b/src/session/ssh.py
1 1
import paramiko
2 2

  
3
from select import select as select
4

  
3 5
from session import Session
4 6

  
5 7
class SSH(Session):
6 8
    
9
    BUFSIZE = 4096
10
    
7 11
    def __init__(self, loadKnownHosts=True, hostname=None, port=22, authType=None, authInfo=None):
8 12
        Session.__init__(self)
9 13
        self._client = paramiko.SSHClient()
......
14 18
    def _connect(self):
15 19
        pass
16 20
    
21
    def _remote_closed(self):
22
        pass
23
    
24
    def _this_just_in(self, data):
25
        pass
26
    
17 27
    def connect(self):
18 28
        self._connect()
19
        self._channel = self._client.get_transport().get_channel()
29
        self._channel = self._client.get_transport().open_session()
20 30
        self._channel.invoke_subsystem('netconf')
21 31
        Session.connect(self)
22 32
    
23 33
    def run(self):
24 34
        item = None
25 35
        sock = self._channel
36
        sock.setblocking(0)
26 37
        inQ, outQ = self._inQ, self._outQ
27
        to_send = ''
28 38
        while True:
29
            if not outQ.empty():
30
                to_send += outQ.get()
31
            if to_send:
32
                to_send = to_send[sock.send(to_send):]
33
            
34
    
39
            (r, w, e) = select([sock], [sock], [], 60)
40
            if w:
41
                if not outQ.empty():
42
                    to_send += outQ.get()
43
                if to_send:
44
                    to_send = to_send[sock.send(to_send):]
45
            if r:
46
                data = sock.recv(BUFSIZE)
47
                if data:
48
                    self._this_just_in(data)
49
                else:
50
                    self._remote_closed()                    
51
                    
35 52
class MissingHostKeyPolicy(paramiko.MissingHostKeyPolicy):
36 53
    pass

Also available in: Unified diff