Using EEM (w/Python, Tcl, etc.) to Call an External API (REST)
I'm not sure if this is possible but wanted to ask the question before asking specifics. Here's what I'm trying to do:
Have EEM w/IP SLA monitor an existing network connection. In the event the remote side becomes unreachable I need to run a script (or something) that will make external REST API calls to an external device. The REST API calls will tell the external device to dynamically create a second circuit (it cannot be up and running concurrently with the first). Then I want to move traffic over to the new connection. The secondary interface on the router/switch will be preconfigured on the Cisco router/switch. The actual layer 2 circuit providing transport (on an external device) is what needs to be created dynamically.
Is this possible? I know the EEM portion will work, what I don't know is if it's possible to make external calls via REST to an external device. (Via Python, EEM Applet, EEM Script, Tcl or something else.) Note, the external device is a provider switch and not Cisco but supports REST for circuit creation.
Hi Carlos, yes you should be able to do this as part of your PnP Python script using the urllib module and at the end of your script once a routable IP-address and other identification has been provisioned which initiates a post-operation toward your automation engine depending upon which object your tool is listening to………………..for regular IOS devices we don’t have a GuestShell to be able to run the Python scripting (which is part of the reason that the IOS-XE devices are more expensive, as they have additional CPU/Memory to be able to operate Linux GuestShell, etc).
[guestshell@guestshell /]$ ls -l /usr/lib64/python3.6/urllib
-rw-r--r--. 1 root root 38327 Nov 21 2019 parse.py
-rw-r--r--. 1 root root 100028 Nov 21 2019 request.py
-rw-r--r--. 1 root root 2299 Dec 23 2018 response.py
-rw-r--r--. 1 root root 8832 Dec 23 2018 robotparser.py
ISR4431#guestshell run python3
Python 3.6.8 (default, Nov 21 2019, 19:31:34)
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cli
>>> import urllib ß import all the requests module
>>> from urllib import request ß or import just the request module
Help on module urllib.request in urllib:
urllib.request - An extensible library for opening URLs using a variety of protocols
The simplest way to use this module is to call the urlopen function, which accepts a string containing a URL or a Request object (described below). It opens the URL and returns the results as file-like object; the returned object has some extra methods described below.
The OpenerDirector manages a collection of Handler objects that do all the actual work. Each Handler implements a particular protocol or option. The OpenerDirector is a composite object that invokes the Handlers needed to open the requested URL. For example, the HTTPHandler performs HTTP GET and POST requests and deals with non-error returns. The HTTPRedirectHandler automatically deals with HTTP 301, 302, 303 and 307 redirect errors, and the HTTPDigestAuthHandler deals with digest authentication.
urlopen(url, data=None) -- Basic usage is the same as original urllib. pass the url and optionally data to post to an HTTP URL, and get a file-like object back. One difference is that you can also pass a Request instance instead of URL. Raises a URLError (subclass of OSError); for HTTP errors, raises an HTTPError, which can also be treated as a valid response.
Listen: https://smarturl.it/CCRS9E25 Follow us: twitter.com/ciscochampions
With applications and users everywhere, the networks are now, more than ever, being tasked with delivering consistent protection while providing an exceptional user exper...
Listen: https://smarturl.it/CCRS9E24 Follow us: https://twitter.com/CiscoChampion
Cisco Radio Aware Routing addresses several of the challenges faced when merging IP routing and radio communications in mobile networks, especially those exhibiti...
Listen: https://smarturl.it/CCRS9E23 Follow us: https://twitter.com/CiscoChampion The Wi-Fi 6E Catalyst 9136 access point takes advantage of the 6-GHz band to produce a network that is more reliable and secure, with higher throughput, more ...
When moving from OSPFv2 to OSPFv3, there are many changes in the format of the LSAs Type, but the most known changes are: IP prefix informations are no longer carried in Type-1 LSA and Type-2 LSA, new LSAs Type 8 and 9 are added to carry these prefixes.