This project is influenced by the code from the YDK-GEN Repository, which was/is developed and maintained by the YDK Team.
We extend our sincere appreciation to the YDK Team for their exceptional work on the YDK Project.
Please note that the YDK Repository is governed by its own license, which you can find in their repository. We recommend reviewing their licensing terms to ensure compliance with the applicable licenses.
The Yangkit is a software development tool, which provides API for building applications based on YANG models. It generates YANG Model APIs and provides services to apply API Obejcts over various communication protocols.
- Model API Generator : This component generates Python API Package for given Yang Models. The generated package is a PIP Installable tar file. Refer to Steps to Generate Model API Python package
- Codec: This component translates Python API Objects to XML/json and vice-versa.
- Create a Model API Package. Refer to Steps to Generate Model API Python package
- Install yangkit and the generated Model API Package in your python env using pip
pip install git+https://github.com/yang-infra/yangkit
pip install /auto/cafy/yang/models/7_11_1_19I/yangkit-models-cisco-ios-xr-7.11.1.tar.gz
- Refer to examples for code examples
- Clone the yangkit Github
git clone https://github.com/yang-infra/yangkit.git
- Build and source a virtual environment
cd yangkit
## Create and activate your virtual environment
python3 -m venv yangkit_venv
source yangkit_venv/bin/activate
## Install Yangkit
pip install --upgrade pip
pip install git+https://github.com/yang-infra/yangkit
- Add and validate yang models
Copy all the yang models you want to generate APIs for into a folder and compile them using 'pyang' to ensure the validity of the models.
cd <yang-files-dir>
pyang *.yang
Note: Refer Pyang Errors Resolution if you face any pyang related issue.
- Create a bundle file:
Example -
{
"name": "cisco-ios-xr", <Bundle Name>
"version": "7.11.1", <Image Version>
"yang_dir": "/Users/jhanm/Documents/Yang_Folder/yang_files" <Absolute Path to Yang Files Directory>
}
- Generate the Model API python package using below command
To Run the Script : (Set Absolute Path - For Both Bundle File & Output Dir) - Mandatory Parameters
- bundle (Input Bundle File)
- output-directory (User directory where the .tar file are gonna get generated)
cd <yangkit Folder Path>/api_generator
./generate.py --bundle <Abosulte Path of Bundle Json File> --output-directory <Absolute Path of Output Directory>
- Generated .tar file will be present in the output directory. This is a pip installable tar file.
Writing yangkit-models-cisco-ios-xr-7.11.1/setup.cfg
creating dist
Creating tar archive
removing 'yangkit-models-cisco-ios-xr-7.11.1' (and everything under it)
Successfully created source distribution
=================================================
Successfully generated Python Yangkit cisco-ios-xr bundle package at /Users/jhanm/Documents/Yang_Folder/generated_models
Please refer to the README for information on how to install the package in your environment
Code generation completed successfully! Manual installation required!
Total time taken: 7 minutes 23 seconds
(yangkit_venv) bash-3.2$
(yangkit_venv) bash-3.2$ pwd
/Users/jhanm/Documents/Yang_Folder/generated_models
(yangkit_venv) bash-3.2$ ls
README.md yangkit-models-cisco-ios-xr-7.11.1.tar.gz
- Remove such files with this error. This means the yang file is empty.
Cisco-IOS-XR-sysadmin-eobc-iosxrwbd.yang:0: error: premature end of file
- Remove oc-deviation files with pyang error.
rm -rf cisco-xr-openconfig-optical-amplifier-sirius-deviations.yang
rm -rf cisco-xr-openconfig-platform-deviations-spi.yang
rm -rf cisco-xr-openconfig-platform-deviations-spirit.yang
rm -rf cisco-xr-openconfig-terminal-device-deviations-routing.yang
rm -rf cisco-xr-openconfig-platform-transceiver-deviations.yang
- Fix/remove yang files with unresolved references.
Cisco-IOS-XR-sysadmin-controllers-iosxrwbd.yang:20: error: module "Cisco-IOS-XR-sysadmin-eobc-iosxrwbd" not found in search path
rm -rf Cisco-IOS-XR-sysadmin-controllers-iosxrwbd.yang
- Fix/remove yang files with similar errors.
openconfig-optical-attenuator.yang:15: error: module "oc-xr-mapping" not found in search path