root / examples / test2.py @ bf394ae4
History | View | Annotate | Download (856 Bytes)
1 |
from ncclient.transport import SSHSession |
---|---|
2 |
from ncclient.operations import CloseSession |
3 |
from ncclient.util import PrintListener |
4 |
from ncclient.capabilities import CAPABILITIES |
5 |
from ncclient import operations |
6 |
|
7 |
import logging |
8 |
logging.basicConfig(level=logging.DEBUG) |
9 |
|
10 |
from ncclient.operations.rpc import RPC |
11 |
class FakeOp(RPC): |
12 |
def request(self): |
13 |
return self._request({'tag': 'fake-operation'}) |
14 |
|
15 |
s = SSHSession(CAPABILITIES) |
16 |
#s.add_listener(PrintListener())
|
17 |
s.load_known_hosts() |
18 |
s.connect('broccoli', 22, username='sbhushan') |
19 |
|
20 |
fo = FakeOp(s) |
21 |
fo_reply = fo.request() |
22 |
if not fo_reply.ok: |
23 |
print 'error dictionary: %r' % fo_reply.error |
24 |
else:
|
25 |
print 'fake op went ok?!' |
26 |
print fo_reply
|
27 |
|
28 |
go = operations.Get(s) |
29 |
go.request() |
30 |
print 'GET_REPLY', go.reply.data_xml |
31 |
|
32 |
cs = CloseSession(s) |
33 |
cs_reply = cs.request() |
34 |
print 'closesession ok:', cs_reply.ok |