1 # importing shows some warning because the Crypto library uses deprecated modules, but that's ok...
2 >>> from ncclient import manager
3 /home/sbhushan/local/lib/python2.6/site-packages/Crypto/Hash/SHA.py:6: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
5 /home/sbhushan/local/lib/python2.6/site-packages/Crypto/Hash/MD5.py:6: DeprecationWarning: the md5 module is deprecated; use hashlib instead
8 # i use agent forwarding from my machine to meat; and SSHSession looks for agent's keys unless told not to -- so i need not specify a password
9 >>> m = manager.connect('broccoli', 22, username='sbhushan')
12 >>> reply = m.copy_config(source='running', target='candidate')
16 # try to make a checkpoint
17 >>> reply = m.copy_config(source='candidate', target='file://checkpoint.conf')
18 Traceback (most recent call last):
19 File "<stdin>", line 1, in <module>
20 File "ncclient/manager.py", line 90, in <lambda>
21 copy_config = lambda self, *args, **kwds: self.do('copy-config', *args, **kwds)
22 File "ncclient/manager.py", line 73, in do
24 ncclient.operations.rpc.RPCError: syntax error in url element
25 # ok, now fixed by putting another "/" after url scheme
26 >>> reply = m.copy_config(source='candidate', target='file:///checkpoint.conf')
31 >>> reply = m.validate(source='<config>not a valid config</config>')
32 Traceback (most recent call last):
33 File "<stdin>", line 1, in <module>
34 File "ncclient/manager.py", line 93, in <lambda>
35 validate = lambda self, *args, **kwds: self.do('validate', *args, **kwds)
36 File "ncclient/manager.py", line 73, in do
38 ncclient.operations.rpc.RPCError: Unexpected content: 'not a valid config'
40 # discard and commit...
41 >>> m.discard_changes()
42 <?xml version="1.0" encoding="UTF-8"?>
43 <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:11b42210-43bc-11de-b876-00e0812e961e"><ok/></rpc-reply>
48 >>> m.lock('candidate')
49 <?xml version="1.0" encoding="UTF-8"?>
50 <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:2caf54cc-43bc-11de-b876-00e0812e961e"><ok/></rpc-reply>
51 >>> m.unlock('candidate')
52 <?xml version="1.0" encoding="UTF-8"?>
53 <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:30146760-43bc-11de-b876-00e0812e961e"><ok/></rpc-reply>
55 # lets try a fake operation, since its a new op we can't use manager
57 >>> from ncclient.operations import RPC
58 >>> class FakeOp(RPC):
59 ... def request(self):
60 ... return self._request({'tag': 'fake-op'})
62 >>> reply = FakeOp(m.session).request()
64 {'error-type': 'rpc', 'error-severity': 'error', 'error-tag': 'unknown-element', 'error-path': '/rpc', 'error-info': '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n<netconf:error-info xmlns:netconf="urn:ietf:params:xml:ns:netconf:base:1.0"><netconf:bad-element>fake-op</netconf:bad-element>\n</netconf:error-info>\n'}
67 >>> reply.error.severity