What is YDK?
The YANG Development Kit (YDK) is a Software Development Kit that facilitates network programmability by abstracting [hiding the complexity of] data models, encodings and protocols. YDK generates APIs that are modeled in YANG in a variety of programming languages.
YDK has two main components: an API generator (YDK-gen) and a set of generated APIs.
YDK-gen takes YANG models as input and produces APIs that mirror the structure of the YANG models. Developers can either use pre-packaged generated bundles (e.g. ydk-py), or they can define their own bundle, consisting of a set of YANG models, using a bundle profile (e.g. ietf_0_1_1.json).
The generated APIs (e.g. ydk-py) which are APIs generated based on YANG models and packaged as bundles have three main components [core libraries]. YDK API core libraries include:
- Service Providers:
Provide implementation that abstracts underlying management protocol
details. Service providers supported by YDK include:
- Codec Service Provider
- NETCONF Service Provider
- gNMI Service Provider
- Opendaylight Service Provider
- RESTCONF Service Provider
- Services: Classes
that perform an action on a Service Provider objects. Service abstract the RPC encoding
and data serialization. Services include:
- Codec Service
- CRUD Service
- Executor Service
- NETCONF Service
- gNMI Service API
- Models: Classes that
mirror the hierarchies defined in YANG data models. Models are bundled in
- Cisco IOS XR
NETCONF Service Provider (which is a wrapper around the ncclient library) provides the mechanism to establish a connection to the remote server, delivers the payload to the server and outputs the reply from the server.
CRUD Service provides API for
Create/Read/Update/Delete operations on device configuration.
Less Coding: No need to code protocol specifics (e.g. NETCONF, RESTCONF) or manipulate serialized data (e.g. XML or JSON) directly.
Less Errors: The APIs perform local validation (e.g. type, value, config/operation, semantics, deviations, etc.) based on information embedded in the YANG model. This means that most errors are caught locally without having to communicate with the networking device.
More Portable Codes: The abstractions also make the automation applications more portable. An application could change providers (e.g. NETCONF with RESTCONF) with minimal changes to the code when using a service that supports multiple providers (e.g. CRUD service).
More Languages: YDK provides multiple programing language support.
# 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 time print("System uptime is " + str(timedelta(seconds=system_time.uptime.uptime))) # close NETCONFIG session and exit provider.close() exit()