root / examples / interactive.txt @ bf394ae4
History | View | Annotate | Download (3.1 kB)
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 |
4 |
from sha import * |
5 |
/home/sbhushan/local/lib/python2.6/site-packages/Crypto/Hash/MD5.py:6: DeprecationWarning: the md5 module is deprecated; use hashlib instead |
6 |
from md5 import * |
7 |
|
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') |
10 |
|
11 |
# a copy config |
12 |
>>> reply = m.copy_config(source='running', target='candidate') |
13 |
>>> reply.ok |
14 |
True |
15 |
|
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 |
23 |
raise reply.error |
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') |
27 |
>>> reply.ok |
28 |
True |
29 |
|
30 |
# validation |
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 |
37 |
raise reply.error |
38 |
ncclient.operations.rpc.RPCError: Unexpected content: 'not a valid config' |
39 |
|
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> |
44 |
>>> m.commit().ok |
45 |
True |
46 |
|
47 |
# locking |
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> |
54 |
|
55 |
# lets try a fake operation, since its a new op we can't use manager |
56 |
|
57 |
>>> from ncclient.operations import RPC |
58 |
>>> class FakeOp(RPC): |
59 |
... def request(self): |
60 |
... return self._request({'tag': 'fake-op'}) |
61 |
... |
62 |
>>> reply = FakeOp(m.session).request() |
63 |
>>> reply.error |
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'} |
65 |
>>> reply.error.type |
66 |
'rpc' |
67 |
>>> reply.error.severity |
68 |
'error' |
69 |
>>> reply.error.tag |
70 |
'unknown-element' |
71 |
# and so on.. |