Sysrepo plugin generator based on main YANG modules used for the specific plugin.
- libyang
- Jinja2
Provide needed arguments for the script and run it to generate plugin directory code and structure.
$ python3 sysrepo-plugin-generator.py -h
usage: sysrepo-plugin-generator.py [-h] -d YANG_DIR -o OUT_DIR -c CONFIG -l LANG
Sysrepo plugin generator.
options:
-h, --help show this help message and exit
-d YANG_DIR, --dir YANG_DIR
Directory containing all the yang modules.
-o OUT_DIR, --outdir OUT_DIR
Output source directory to use.
-c CONFIG, --config CONFIG
Configuration file to use for generation.
-l LANG, --lang LANG Destination language to generate to (C or C++).
The generator will follow the following source directory structure (the example is taken for the ietf-system plugin):
|-- main.c
|-- plugin
| |-- api
| | `-- system
| | |-- authentication
| | | |-- change.c
| | | |-- change.h
| | | |-- check.c
| | | |-- check.h
| | | |-- load.c
| | | |-- load.h
| | | |-- store.c
| | | `-- store.h
| | |-- change.c
| | |-- change.h
| | |-- check.c
| | |-- check.h
| | |-- clock
| | | |-- change.c
| | | |-- change.h
| | | |-- check.c
| | | |-- check.h
| | | |-- load.c
| | | |-- load.h
| | | |-- store.c
| | | `-- store.h
| | |-- dns-resolver
| | | |-- change.c
| | | |-- change.h
| | | |-- check.c
| | | |-- check.h
| | | |-- load.c
| | | |-- load.h
| | | |-- options
| | | | |-- change.c
| | | | |-- change.h
| | | | |-- check.c
| | | | |-- check.h
| | | | |-- load.c
| | | | |-- load.h
| | | | |-- store.c
| | | | `-- store.h
| | | |-- store.c
| | | `-- store.h
| | |-- load.c
| | |-- load.h
| | |-- ntp
| | | |-- change.c
| | | |-- change.h
| | | |-- check.c
| | | |-- check.h
| | | |-- load.c
| | | |-- load.h
| | | |-- store.c
| | | `-- store.h
| | |-- radius
| | | |-- change.c
| | | |-- change.h
| | | |-- check.c
| | | |-- check.h
| | | |-- load.c
| | | |-- load.h
| | | |-- options
| | | | |-- change.c
| | | | |-- change.h
| | | | |-- check.c
| | | | |-- check.h
| | | | |-- load.c
| | | | |-- load.h
| | | | |-- store.c
| | | | `-- store.h
| | | |-- store.c
| | | `-- store.h
| | |-- store.c
| | `-- store.h
| |-- common.h
| |-- context.h
| |-- data
| |-- ly_tree.c
| |-- ly_tree.h
| |-- startup
| | |-- load.c
| | |-- load.h
| | |-- store.c
| | `-- store.h
| `-- subscription
| |-- change.c
| |-- change.h
| |-- operational.c
| |-- operational.h
| |-- rpc.c
| `-- rpc.h
|-- plugin.c
`-- plugin.h
The main files are:
main.c
- plugin independent ofsysrepo-plugind
plugin.h
- init and cleanup plugin callbacksplugin.c
- init and cleanup implementationcommon.h
- YANG paths and other commonly used macroscontext.h
- used context throughout the plugin callbackstypes.h
- used types in the plugin (common structures, enums and unions)ly_tree.(h|c)
- API for creating libyang tree nodes based on the main YANG module, hereietf-system
Other parts of the plugin include:
plugin/api/
- the API for loading, storing and changing data on the systemplugin/data/
- helper functions for types defined intypes.h
- example would be implementinginit()
andfree()
functionalities for a list of types - TODOplugin/startup/
- load and store functionalities for the startup datastore - initial load for startup when the plugin is first started and constant store API for when the plugin starts up again so that the state is left unchangedplugin/subscription/
- change, operational and RPC/action callbacks, used inplugin.c
file which subscribes all callbacks to their respective paths
plugin/data/
and plugin/api/
folders use separation based on the YANG containers - for each container one folder is used which enables easier navigation. In these folders, files can be separated based on more containers or lists etc.