pynetconf
libnetconf wrapper for Python
 All Classes Namespaces Functions Variables Pages
Example Applications

Example applications using the libnetconf Python API are located in the source tree inside the libnetconf/python/examples/ directory.

get.py

Simple client-side application printing the result of the NETCONF <get> operation.

1 $ ./get.py localhost -f "<nacm><rule-list/></nacm>"
2 <nacm xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">
3  <rule-list>
4  <name>permit-all</name>
5  <group>users</group>
6  <rule>
7  <name>permit-all-rule</name>
8  <module-name>*</module-name>
9  <access-operations>*</access-operations>
10  <action>permit</action>
11  </rule>
12  </rule-list>
13 </nacm>

server.py

Very simple (4 LOC) NETCONF server server.py is alternative to the Netopeer's single-layer server.

To see, how the server interacts with a client, you can run it from the command line and communicate with the server interactively (if you don't understand the following lines, and you want to, read RFC 6241 and RFC 6242):

1 $ ./server.py
2 <?xml version="1.0" encoding="UTF-8"?>
3 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
4  <capabilities>
5  <capability>urn:ietf:params:netconf:base:1.0</capability>
6  <capability>urn:ietf:params:netconf:base:1.1</capability>
7  <capability>urn:ietf:params:netconf:capability:writable-running:1.0</capability>
8  ...
9  </capabilities>
10  <session-id>31059</session-id>
11 </hello>
12 ]]>]]><?xml version="1.0" encoding="UTF-8"?>
13 <hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
14  <capabilities>
15  <capability>urn:ietf:params:netconf:base:1.0</capability>
16  </capabilities>
17 </hello>]]>]]>
18 <?xml version="1.0" encoding="UTF-8"?>
19 <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
20  <close-session/>
21 </rpc>]]>]]>
22 <?xml version="1.0" encoding="UTF-8"?>
23 <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
24  <ok/>
25 </rpc-reply>
26 ]]>]]>

However, the more usual way how to use it, is to set your SSH server to run it as its netconf SSH Subsystem. In this case, the server is started automatically when client connects to the host. To configure your SSH server this way, add the following line to the /etc/ssh/sshd_config file.

1 Subsystem netconf /path/to/server.pl

Also remember to correctly set the port where the SSH server listens. By default, it listens on port 22, but NETCONF has assigned port 830 and the most of clients use it by default.

And finally, don't forget to make the SSH server reload the changed configuration.