• Programmatically update your routing table

 
 
Print Friendly, PDF & Email

Overview

This article describes a script which is designed to allow the insertion/removal of a route in/from the routing table. If you want a way to remotely add/delete routes to/from your routing table, then this is the tool for you – using it will make insertion/removal of static routes as easy as running a script on any remote device that supports Python.

How to get the code:

Installation

The script (updateRoute) can be run/installed on any device that runs Python 2.7 or later. In order to run updateRoute, first enable Command API on the switch, as follows (requires EOS-4.12.0 or later):

(config)#management api http-commands
(config-mgmt-api-http-cmds)#protocol [http|https]
(config-mgmt-api-http-cmds)#no shutdown

Then simply call the script from any device with IP connectivity to the switch, as follows:

%updateRoute <route/mask> <interface> <switch to update route> <username> <password> 

Mandatory command-line arguments:

  • <route/mask>: route with CIDR mask
  • <interface>: egress interface or next-hop address
  • <switch to update route>: hostname / IP address of the switch
  • <username>: switch user
  • <password>: user password

Optional  command-line arguments:

  • –delete: removes route from routing table (instead of adding it)
  • –http: use HTTP instead of the default HTTPS (for the Command API call)
  • –enable-password: enable-mode password

Example

Add a route to the routing table:

%updateRoute 1.1.1.0/24 Ethernet1 192.168.56.11 admin passadmin

Check the routing table to ensure that the route has been successfully added:

Arista#sh ip route
Codes: C - connected, S - static, K - kernel, 
 O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
 E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
 N2 - OSPF NSSA external type2, B I - iBGP, B E - eBGP,
 R - RIP, I - ISIS, A - Aggregate
Gateway of last resort is not set
S 1.1.1.0/24 is directly connected, Ethernet1
C 172.16.111.0/24 is directly connected, Management1

Success – the route was added to the routing table!

Now let’s delete the route:

%updateRoute –delete 1.1.1.0/24 Ethernet1 192.168.56.11 admin passadmin

Check to see whether the route has been removed from the routing table:

Arista#sh ip route
Codes: C - connected, S - static, K - kernel, 
 O - OSPF, IA - OSPF inter area, E1 - OSPF external type 1,
 E2 - OSPF external type 2, N1 - OSPF NSSA external type 1,
 N2 - OSPF NSSA external type2, B I - iBGP, B E - eBGP,
 R - RIP, I - ISIS, A - Aggregate
Gateway of last resort is not set
C 172.16.111.0/24 is directly connected, Management1
Success – the route was removed from the routing table!

 

Using updateRoute you can programmatically interact with the routing table of the Arista EOS-powered devices in your network. Give Arista EOS Command API a try – it is easy to use and allows for powerful interactions with your infrastructure.

The code – time to Git it!


Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: