Network Automation using YANG Models across XE, XR, & NX

YDK-Gen Download & Installation


The ydk-gen package is distributed as a cloneable Git repository (as opposed to a pip installable). In this module we will clone ydk-gen from GitHub and verify its installation.

Preliminary Tooling

Before we can use ydk-gen to install and run ydk packages, CentOS requires us to have some additional gcc toolsets installed.

Note: The YDK / YDK-Gen installation steps have already been done for you as part of the docker container you pulled; this is just provided for reference.

    
        $ sudo yum install epel-release
        $ sudo yum install libssh-devel gcc-c++ python-devel
        $ sudo yum install https://devhub.cisco.com/artifactory/rpm-ydk/0.7.1/libydk-0.7.1-1.x86_64.rpm

        # Upgrade compiler to gcc 5.*
        $ yum install centos-release-scl -y > /dev/null
        $ yum install devtoolset-4-gcc* -y > /dev/null
        $ ln -sf /opt/rh/devtoolset-4/root/usr/bin/gcc /usr/bin/cc
        $ ln -sf /opt/rh/devtoolset-4/root/usr/bin/g++ /usr/bin/c++
    

These steps have already been completed for you as part of your pod development environment setup. If you need to stand-up YDK-Gen on your own from scratch, you will need to ensure that the above tooling is installed before attempting to install any of your generated packages, otherwise you will see CMake errors during pip installation of your generated packages.

Clone ydk-gen from GitHub


Clone the Cisco ydk-gen repository from GitHub into your workspace as follows

    
         git clone https://github.com/CiscoDevNet/ydk-gen.git
    

The output should look as follows:

    
        [root@8d776fccfe83 workspace]# git clone https://github.com/CiscoDevNet/ydk-gen.git
        Cloning into 'ydk-gen'...
        remote: Counting objects: 14670, done.
        remote: Compressing objects: 100% (221/221), done.
        remote: Total 14670 (delta 166), reused 243 (delta 125), pack-reused 14320
        Receiving objects: 100% (14670/14670), 6.31 MiB | 328.00 KiB/s, done.
        Resolving deltas: 100% (10209/10209), done.
        Checking out files: 100% (971/971), done.
        [root@8d776fccfe83 workspace]#
    

Install ydk-gen Requirements


Change directories into the newly cloned ydk-gen directory and run an ls -l to see what's in the root of the repo.
    
        cd ydk-gen
        ls -l
    

You should see contents very similar to the below file list. Feel free to explore these files in your IDE before moving to the next step.

    
        [root@8d776fccfe83 workspace]# cd ydk-gen
        [root@8d776fccfe83 ydk-gen]# ls -l
        total 112
        -rw-r--r--  1 root root 32459 Apr 13 20:59 CHANGES.md
        -rw-r--r--  1 root root  1103 Apr 13 20:59 CODINGSTYLE.md
        -rw-r--r--  1 root root   486 Apr 13 20:59 CONTRIBUTIONS.md
        -rw-r--r--  1 root root   713 Apr 13 20:59 Copyright
        -rw-r--r--  1 root root   368 Apr 13 20:59 Dockerfile
        -rw-r--r--  1 root root 11357 Apr 13 20:59 LICENSE
        -rw-r--r--  1 root root 20178 Apr 13 20:59 README.md
        -rwxr-xr-x  1 root root  5693 Apr 13 20:59 create_ydk_sdk_for_github.sh
        -rwxr-xr-x  1 root root 15484 Apr 13 20:59 generate.py
        -rw-r--r--  1 root root   564 Apr 13 20:59 issue_template.md
        drwxr-xr-x  5 root root   170 Apr 13 20:59 profiles
        -rw-r--r--  1 root root    79 Apr 13 20:59 requirements.txt
        drwxr-xr-x  7 root root   238 Apr 13 20:59 sdk
        drwxr-xr-x 17 root root   578 Apr 13 20:59 test
        drwxr-xr-x  6 root root   204 Apr 13 20:59 yang
        drwxr-xr-x  8 root root   272 Apr 13 20:59 ydkgen
        [root@8d776fccfe83 ydk-gen]#
    
Specifically, we are interested in requirements.txt. This contains the Python requirements needed by ydk-gen.

Here are the contents of the requirements file:
    
        [root@8d776fccfe83 ydk-gen]# cat requirements.txt
        pyang==1.6
        Sphinx==1.4a1
        sphinx-rtd-theme==0.1.9
        GitPython==1.0.1
        rstr==2.2.6
    

We will now install all of these requirements as to allow ydk-gen to run with all required dependencies installed. Let's do the pip install.

Installing YDK's Requirements

Execute the following to install YDK's requirements into your Docker container instance.

    
    pip3.6 install -r requirements.txt
    
You should observe an output similar to below once Python 3.6's PIP manager has completed installing the packages specified in the requirements.txt file.
    
    [root@8d776fccfe83 ydk-gen]# pip3.6 install -r requirements.txt
    Collecting pyang==1.6 (from -r requirements.txt (line 1))
    Downloading pyang-1.6-py2.py3-none-any.whl (299kB)
        100% |################################| 307kB 2.0MB/s
    Collecting Sphinx==1.4a1 (from -r requirements.txt (line 2))
    Downloading Sphinx-1.4a1-py2.py3-none-any.whl (1.5MB)
        100% |################################| 1.5MB 835kB/s
    (... truncated for brevity ....)
        100% |################################| 409kB 2.9MB/s
    Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3.6/site-packages (from Jinja2>=2.3->Sphinx==1.4a1->-r requirements.txt (line 2))
    Collecting pytz>=0a (from babel!=2.0,>=1.3->Sphinx==1.4a1->-r requirements.txt (line 2))
    Downloading pytz-2018.4-py2.py3-none-any.whl (510kB)
        100% |################################| 512kB 2.4MB/s
    Collecting smmap>=0.8.5 (from gitdb>=0.6.4->GitPython==1.0.1->-r requirements.txt (line 4))
    Downloading smmap-0.9.0.tar.gz
    Installing collected packages: pyang, Pygments, snowballstemmer, imagesize, pytz, babel, docutils, alabaster, Sphinx, sphinx-rtd-theme, smmap, gitdb, GitPython, rstr
    Found existing installation: pyang 1.7.4
        Uninstalling pyang-1.7.4:
        Successfully uninstalled pyang-1.7.4
    Running setup.py install for smmap ... done
    Running setup.py install for gitdb ... done
    Running setup.py install for GitPython ... done
    Successfully installed GitPython-1.0.1 Pygments-2.2.0 Sphinx-1.4a1 alabaster-0.7.10 babel-2.5.3 docutils-0.14 gitdb-0.6.4 imagesize-1.0.0 pyang-1.6 pytz-2018.4 rstr-2.2.6 smmap-0.9.0 snowballstemmer-1.2.1 sphinx-rtd-theme-0.1.9
    [root@8d776fccfe83 ydk-gen]#
    

Now that the proper packages are installed, let's run ydk-gen's help function to get an idea of what it can do.

    
    python3.6 generate.py --help
    

You should observe an output similar to the following:

    
        [root@8d776fccfe83 ydk-gen]# python3.6 generate.py --help
        usage: generate.py [-h] [--bundle BUNDLE]
                        [--adhoc-bundle-name ADHOC_BUNDLE_NAME]
                        [--adhoc-bundle ADHOC_BUNDLE [ADHOC_BUNDLE ...]] [--core]
                        [--output-directory OUTPUT_DIRECTORY] [-p] [-c] [-g] [-l]
                        [-v] [--generate-doc] [--generate-tests] [-o]

        Generate YDK artefacts:

        optional arguments:
        -h, --help            show this help message and exit
        --bundle BUNDLE       Specify a bundle profile file to generate a bundle
                                from
        --adhoc-bundle-name ADHOC_BUNDLE_NAME
                                Name of the adhoc bundle
        --adhoc-bundle ADHOC_BUNDLE [ADHOC_BUNDLE ...]
                                Generate an SDK from a specified list of files
        --core                Generate and/or install core library
        --output-directory OUTPUT_DIRECTORY
                                The output directory where the sdk will get created.
        -p, --python          Generate Python SDK
        -c, --cpp             Generate C++ SDK
        -g, --go              Generate Go SDK
        -l, --libydk          Generate libydk core package
        -v, --verbose         Verbose mode
        --generate-doc        Generate documentation
        --generate-tests      Generate tests
        -o, --one-class-per-module
                                Generate separate modules for each python class
                                corresponding to yang containers or lists.
        [root@8d776fccfe83 ydk-gen]#
    
We now have ydk-gen installed and all dependencies resolved. Next we will start collecting the YANG models from the devices in preparation for creating the Python bindings using ydk-gen.