问题
I managed to generate Pojos from yang files, using OpenDayLight YangTools.
Next stage i managed to import netconf client to my application (using gradle), how do i use the generated pojos with netconfClient in my application to configure a device?
回答1:
Would be good if you explain what you want to achieve so I can help you more accurately, but if you want to configure your box programmatically using yang, you need to follow the steps below:
- From yang models generate your runtime configuration classes (this is what you have now)
- Write some logic to call those generated classes and create an object which defines your configuration. For instance, setting up a BGP config, you need to start from the router, bgp, address family, neighbour, and so on. The object will follow your device Yang model, or the 'openconfig' one like here: https://github.com/openconfig/public/blob/master/release/models/bgp/openconfig-bgp.yang
- After you have generated your 'configuration instance', then you need to serialise it (convert to XML)
- Use a netconf client (look for ncclient) to send it to the box.
If you are not much fussed about the language, I would suggest you use
https://github.com/CiscoDevNet/ydk-py
which has examples already.
A more Opendaylighty approach is,
- Start a maven project and yangtools in it, https://wiki.opendaylight.org/view/OpenDaylight_Controller:MD-SAL:Startup_Project_Archetype#Starting_your_.27example.27_project_for_the_first_time
- Load netconf southbound application
- Add your yang models you want (optional)
- Do a maven build so it generates the API for you (you will have access to the device API directly).
- Then what extra you can do is to implement the logic where the provider classes are and provide your own API.
Hope this helps
来源:https://stackoverflow.com/questions/51627804/use-pojos-generated-from-yang-to-configure-device-using-odl-netconf-client