BLOGPOST#140 Accelerate Your Network Engineering Skills with Python: A Comprehensive Guide to Installing and Using Yang Suite

Introduction:
If you’re a network engineer looking to learn how to automate network management tasks using Netconf or Restconf protocol , then this article is for you. In this first video of our Python Netconf and Restconf learning series, we’ll be installing Yang Suite and exploring some basic use cases.

What is Yang Suite?
Yang Suite is a tool from Cisco that can be downloaded and installed for free. It helps network engineers understand the structure of Yang data model, which is used by protocols like gNMI (Google RPC-based protocol)and it stands for Network Management Interface, NETCONF, and RESTCONF.

Installing Yang Suite:
To install Yang Suite, you can follow the instructions given in the below Udemy Course. For this demonstration, we’ll be doing a Docker-based installation on a fresh Ubuntu machine.

Exploring Yang Suite:
Once you have Yang Suite installed, you can start exploring its features. You’ll need to add devices and repositories to get started. You can add a device by clicking on “Create new device” and providing the credentials. Yang Suite supports various protocols, including NETCONF and RESTCONF. Once you have a device added, you can click on “Check selected device’ s reachability” to test if the device is reachable.
You’ll also need to configure Yang module sets, which are filters for all the Yang files downloaded into the server. You can create sets and add repositories and devices under them. You can explore the data model by clicking on the set, and you can click on “Load module” to see the structure of the data model.

Using Yang Suite:
In this video, we’ll be demonstrating a small use case of configuring the hostname using Yang Suite. Once you have the module loaded, you can test the protocol by going to RESTCONF and selecting the device and Yang module. You can generate APIs for all the hostname-related actions, and you can test them using the methods PUT, PATCH, GET, and DELETE. You can use Python scripts to automate these tasks.

Let’s see changing the hostname of the device using the PUT method. We’ll assume that you’re already familiar with REST APIs and how to make API calls. To change the hostname, we’ll use the PUT method. Simply make an API call to the device with the new hostname in the payload, like this:

{
"hostname": "From-Python"
}

Once you execute the PUT method, you should receive a response indicating that the hostname has been changed. You can verify this by checking the device configuration.

Now, let’s move on to enabling external access. By default, the device will only allow access from the same machine. To allow remote access, we need to enable external access. To do this, we’ll need to install Docker and YangSuit. Here are the steps to install Docker:

Execute GET update:

sudo apt-get update

-Add the ca certificate for Docker installation
-Use a code to set up the repository

Give GET update:
Install Docker by executing sudo apt install docker-ca. Once Docker is installed, we can proceed with installing YoungSuit. Here are the steps to install YoungSuit:

-Clone the repository using git clone:
‘git clone https://github.com/CiscoDevNet/yangsuit’
-Navigate to the YoungSuit directory using: ‘cd yangsuit/docker/’
-Execute ‘sudo bash ./start_yang_suite.sh’
-Enter the login credentials when prompted (default is admin/admin)
-Set up an email and confirm the password
-Accept the self-signed certificate

YangSuit will now be installed and running.To access it: 

-Open a browser and go to https://localhost:8443
-You may receive a security warning, but you can safely ignore it. 
-Accept the user license agreement and log in using your credentials.

Now that we have YangSuit up and running, we can explore its APIs and use them for automation tasks.This will be accessible only from local machine. Enable external access to your server and provide some basic API details to explore the available functionalities.

Accessing the server from a local machine:
If you encounter any issues, try accessing it from a different machine. Once you have accessed the server, stop the server and add the remote host IP to the allowed host list. This will allow any machine to access the server using the specified port number.

Configuring the server using Docker:
To configure the server, navigate to the Docker folder and edit the setup file. You can specify a specific host or give any host to allow access to the server from any machine on the network. Once you have made the necessary changes, start the server using Docker-compose up.

Exploring the API functionalities:
With the server configured and running, you can now explore the available API methods. You can use these methods to perform basic automations and query the Yang data model.

Conclusion:
Yang Suite is a powerful tool that can help network engineers automate network management tasks. In this video, we’ve demonstrated how to install and use Yang Suite to configure the hostname. Stay tuned for more videos in this Python learning series for network engineers.

Unlock the Power of Network Automation ! Enroll in our Comprehensive Udemy Course Today !

Topics & libraries Covered:

  • PARAMIKO, NETMIKO, NAPALM, NORNIR and NCCLIENT libraries
  • Cisco IOS, vIOS and NXOS SSH Automation
  • Cisco CSR 1000v Netconf and RestAPI examples
  • NX-API Automation (NXAPI CLI and bash)
  • PyATS, Cisco Genie Parser
  • NETCONF & RESTCONF API Automation
  • YANG Data Models and YANG Suite demo
  • IPAddress Module and requests module
  • Python Core Fundamentals for Network Engineers
  • Python Data Types
  • Python Text & CSV File operations (read/write) device data
  • Python IDE (PyCharm) Setup for Network Automation
  • GNS3 Lab Setup for Network Automation
  • Python Functions, Modules, Classes and Objects Tutorial
  • Python Multithreading Examples (threading and concurrent futures)
  • Python Logging, schedule and Email for monitoring
  • Python SSH CLI Parsing Using RegEx
  • How to Use JSON, YAML and XML Files for Device Config