Most of the code has been taken from the Pyang-COP repository and modified to fit our requirements
Pyang is an extensible YANG validator and converter written in python.
It can be used to validate YANG modules for correctness, to transform YANG modules into other formats, and to generate code from the modules. We have written a pyang plugin to obtain the RESTCONF API from a yang model.
The RESTCONF API of the YANG model is interpreted with Swagger, which is a powerful framework for API description. This framework will be used to generate a Stub server for the YANG module.
##Install pyang
Download pyang here (tested with version pyang-1.7.1) Extract the archive to a folder of you choice. Install pyang by running the following command inside that folder:
sudo python setup.py install
sudo cp pyang_plugins/swagger.py /usr/local/lib/python2.7/dist-packages/{pyang_directory}/plugins/
pyang -f swagger -p modules modules/config-bridge.yang -o config-bridge-swagger.json
--use the option '-p' to specify the path of the yang models for import purposes.
According to the RESTCONF protocol, the plugin generates three kinds of endpoints. Considering {base_path}
as our base path and {path}
as the path accessing the data or the operation, the plugin generates:
{base_path}/data/{path}
for all configuration and state data accessible;{base_path}/operations/{path}
for all RPC operations;{base_path}/yang-library-version
storing the revision date of YANG library version.
The methods supported are: OPTIONS, HEAD, GET, POST, PATCH, PUT, DELETE. To enable the generation of the endpoints for OPTIONS and HEAD methods, please enable the generate_all_restconf_methods
flag. Responses are generated according to the definitions contained in the protocol.
Copyright 2017 Politecnico di Torino.
Copyright 2015 CTTC.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.