PyangBind installation:
$ git clone https://github.com/robshakir/pyangbind.git
$ cd pyangbind/
$ python3 setup.py install
To generate a set of Python classes, Pyang needs to be provided a pointer to where PyangBind's plugin is installed. This location can be found by running:
$ export PYBINDPLUGIN=`/usr/bin/env python3 -c \
'import pyangbind; import os; print ("{}/plugin".format(os.path.dirname(pyangbind.__file__)))'`
Once this path is known, it can be provided to the --plugin-dir
argument to Pyang.
$ pyang --plugindir $PYBINDPLUGIN -f pybind -o binding.py node-topology.yang
where:
$PYBINDPLUGIN
is the location that was exported from the above command.binding.py
is the desired output file.node-topology.yang
is the YANG file that bindings are to be generated for.
The simplest class generated using a PyangBind looks like:
from Netconf.bindingTopology import node_topology
nt = node_topology()
At this point, the nt
object can be used to manipulate the YANG data tree that is expressed by the module.
A subset of node-topology
looks like the following tree:
module: node-topology
+--rw node* [node-id]
+--rw node-id string
+--rw port* [port-id]
+--rw port-id string
+--rw layer-protocol-name? string
+--rw available-core* [core-id]
To add an entry to the node
list the add
method is used:
from Netconf.bindingTopology import node_topology
nt = node_topology()
new_node = nt.node.add("10.0.2.15")
The node
list is addressed exactly as per the path that it has within the YANG module.
You can find more information and examples about the generic methods used to manipulate data at: http://pynms.io/pyangbind/generic_methods/
Any PyangBind class can be serialised into any of the supported formats: XML, OpenConfig and JSON.
from pyangbind.lib.serialise import pybindIETFXMLEncoder
# Dump the entire instance as XML
print(pybindIETFXMLEncoder.serialise(nt))
This outputs the following XML structured text:
#TODO
Instances can be deserialised from any of the supported serialisation formats (see above) into the classes.
# Load XML into an existing class structure
import Netconf.bindingTopology as binding
from pyangbind.lib.serialise import pybindIETFXMLDecoder
print(pybindIETFXMLDecoder.decode(nt, binding, 'node-topology'))
This outputs the following XML structured text:
#TODO
Netconf installation:
$ pip3 install netconf
Running Netconf server:
$ python3 server.py -file dataset/test.xml
Running Netconf client:
$ python3 client.py
This worked example can be found in the Netconf
directory.