Statistics
| Branch: | Tag: | Revision:

root / examples / test2.py @ abfee8f0

History | View | Annotate | Download (816 Bytes)

1
from ncclient.transport import SSHSession
2
from ncclient.operations import CloseSession
3
from ncclient.capabilities import CAPABILITIES
4
from ncclient import operations
5

    
6
import logging
7
logging.basicConfig(level=logging.DEBUG)
8

    
9
from ncclient.operations.rpc import RPC
10
class FakeOp(RPC):
11
    def request(self):
12
        return self._request({'tag': 'fake-operation'})
13

    
14
s = SSHSession(CAPABILITIES)
15
#s.add_listener(PrintListener())
16
s.load_known_hosts()
17
s.connect('broccoli', 22, username='sbhushan')
18

    
19
fo = FakeOp(s)
20
fo_reply = fo.request()
21
if not fo_reply.ok:
22
    print 'error dictionary: %r' % fo_reply.error
23
else:
24
    print 'fake op went ok?!'
25
    print fo_reply
26

    
27
go = operations.Get(s)
28
go.request()
29
print 'GET_REPLY', go.reply.data_xml
30

    
31
cs = CloseSession(s)
32
cs_reply = cs.request()
33
print 'closesession ok:', cs_reply.ok