Skip to content

jc83419/ydk-py-samples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sample Apps for YDK-Py

This repository provides a collection of sample applications that use YDK-Py for network programmability. YDK-Py is the Python package for the Cisco YANG development kit (YDK) which provides model-driven APIs generated from a variety of YANG models.

A "hello, world" App

The hello-ydk.py script illustrates a minimalistic app that prints the uptime of a device running Cisco IOS XR. The script opens a NETCONF session to a device with address 10.0.0.1, reads the system time and prints the formatted uptime.

# import providers, services and models
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_shellutil_oper \
    as xr_shellutil_oper
from datetime import timedelta


if __name__ == "__main__":
    """Main execution path"""

    # create NETCONF session
    provider = NetconfServiceProvider(address="10.0.0.1",
                                      port=830,
                                      username="admin",
                                      password="admin",
                                      protocol="ssh")
    # create CRUD service
    crud = CRUDService()

    # create system time object
    system_time = xr_shellutil_oper.SystemTime()

    # read system time from device
    system_time = crud.read(provider, system_time)

    # print system uptime
    print("System uptime is " +
          str(timedelta(seconds=system_time.uptime.uptime)))

    # close NETCONF session and exit
    provider.close()
    exit()

Sample output

$ ./hello-ydk.py
System uptime is 5 days, 3:52:08
$

Sample App Library

This repository include a large number of basic sample apps. They focus on a single model and have no or minimal programming logic (conditionals, loops, etc). They should be your starting point if you don't have strong experience with models or with programming. They are grouped by service and model. Version 0.5.0 of the YDK Python (YDK-Py) package is required to run the applications.

Installation

The sample apps do not require any special installation, but they do require that YDK-Py is installed including the Cisco IOS XR, OpenConfig and IETF model bundles:

$ pip list | grep ydk
ydk (0.5.0)
ydk-models-cisco-ios-xr (0.1.0)
ydk-models-ietf (0.1.0)
ydk-models-openconfig (0.1.0)
$

If it is not installed, verify first that you have Python 2.7 / 3.4 (or later) installed:

$ python --version
Python 2.7.6
$
$ python3 --version
Python 3.5.2
$

Download or clone the YDK-Py repository. Then, follow the installation instructions for YDK-Py in its README file.

Running an App

Instructions for using the basic apps can be found in their README file. For Cisco IOS XR models, you would need a device running version 6.0.0 or later as the target.

Vagrant Sandbox

You can instantiate a YDK-Py sandbox on your computer using Vagrant. The sandbox will provide an Ubuntu (14.04) VM with YDK-Py pre-installed. Make sure you have these prerequisites installed on your computer:

To create a sandbox, issue the following command from the directory where the Vagrantfile resides:

$ vagrant up

To verify the status of your sandbox use:

$ vagrant status

Once your sandbox is running, you can connect to it using:

$ vagrant ssh

Note that the samples and projects directories are shared between your host and your Vagrant box. Any changes to those directories are seen in both environments. Any other data in your Vagrant box is isolated from your host and will be lost if you destroy your Vagrant box.

You can suspend and resume your sandbox using:

$ vagrant suspend
$ vagrant resume

To destroy your sandbox, issue the following command:

$ vagrant destroy

If you previously instantiated a YDK-Py sandbox, you can check for updates using:

$ vagrant box outdated

If a newer version is available, you can update your sandbox automatically using:

$ vagrant box update

About

Sample apps for YDK-Py

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%