Why Network Programmability is a big deal and why should you care as a Network Engineer!

 

Hello, Greetings for the day!

Just reading the word “programming” we might think, what does it have to do with network engineers where Network and programming being two different fields. Well it does. Let’s find out.

What is Network Programmability?

Network Programmability is currently defined as a set of practical software tools to deploy, verify, manage, and troubleshoot network problems regardless of number of devices, whether it is 1 or 100. This concept is born from the benefits of saving time, reducing human errors, innovation and customization.

There are so many benefits of utilizing programming for Network Automation, Which is also a big thing now days, we will discuss it in depth in soon.

The best thing about it, that it is time Saving. Here are some script examples that I wrote to demonstrate on how we can use these to utilize our time rightly.

Deshmukh Saif

Stay tuned for many upcoming cool blogs like this one.

Thanks & Regards
Deshmukh Saif

The following scenarios are used as an example

How cool would be it be if we could backup all the devices configuration with single click, regardless of how many sites we have and how many devices in each sites we have. Just imagine how much time it would save. 

Here I am doing backup for only single device for demonstration purpose.

import sys
import time
import paramiko 
import os
import cmd
import datetime

#set date and time
now = datetime.datetime.now()

#authentication
HOST = '192.168.100.1'
USER = 'saif'
PASSWORD = 'saif123'
secret = 'password'

#prefix files for backup
filename_prefix ='cisco-backup'

#ssh session starts
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(HOST, username=USER, password=PASSWORD)

#ssh shell
chan = client.invoke_shell()
time.sleep(1)
#enter enable secret
chan.send('en\n')
chan.send(secret +'\n')
time.sleep(1)
#terminal lenght for no paging 
chan.send('term len 0\n')
time.sleep(1)
#show config and write output
chan.send('sh run\n')
time.sleep(10)
output = chan.recv(99999)
#show output config and write file with prefix, date and time
print output
filename = "%s_%.2i-%.2i-%i_%.2i-%.2i-%.2i" % (filename_prefix,now.day,
now.month,now.year,now.hour,now.minute,now.second) f = open(filename, 'a') f.write(output) f.close() #close ssh session client.close()

What is Network Programmability?

You just got an alert saying that one of site is your infrastructure is down. Being a traditional network engineer you would try to to make sure that it is not a false alert or 

you can write a python script in advance and in a single click you are pinging all the devices, logging into some devices and checking the up time and showing the results. Yes, in a single click.

import time
from netmiko import ConnectHandler
from netmiko import redispatch
from pythonping import ping

device = "8.8.8.8"

a = ping(device)

if a == "Reply from 8.8.8.8, 9 bytes in 8.17ms": #if ping is successul
then execute the commands below print("Device is up and rechable") device = { 'device_type' : 'cisco_ios_telnet', 'ip': '192.168.42.90' , 'username' : 'saif',## This is the device information we
are storing in to the varibale 'password' : 'saif123', 'secret' : 'sec', 'port' : 23 } try: c = ConnectHandler(**device) ##Opening a connection c.enable() output = c.send_command('show version')
# sending command to check system uptime print(output)
# print the output output = c.send_command('show alarms breif')
# sending a command to take the print(output) c.close() except Exception as e: print(e) else: print("Device is down, ping is failing")

 

What is Network Programmability?

Lets say that, there is an important logical interface on “Device 1”, going that down would be really bad idea. To make things simple you have used HA to avoid any failures or you did not. What if we could write a EEM script that is monitoring that interface and as soon as it goes down, based on the event the action is executed which is running the “EEM-interface-routes.py” file. it will create a new logical interface and make it primary interface for the traffic and all this is happening while we are sleeping.

It will create a new logical interface and make it primary interface for the traffic

event manager applet INTERFACE-DOWN
 event syslog pattern "LINEPROTO-5-UPDOWN: 
Line protocol on Interface GigabitEthernet0/0, changed state to down" action 0.0 cli command "en" action 1.0 cli command "guestshell run python EEM-interface-routes.py"

 

These are just a small things you can do with Network Programmability. I have merely scratched the surface. trust me, your mind is the limit. All you need to know is the basics of python skills and a curios mind. Software Defined Network is the future.