Posted on September 30, 2016 3:03 am
 |  Asked by Harikrishnan Sankar
 |  4237 views
0
0
Print Friendly, PDF & Email

Hi,

I added a new event-handler called TEST, what it does is when int49 operational status goes to “notconnect”, I want to disable the port. normal bash command is not working. (tested with TAC)

Switch : Arista 7150 – 52 port

EOS: 4.14.9.1M

so I wrote a python script and stored in /mnt/flash/hello1.py (when I separately run the command, it checks the status of the interface (“notconnect”) and disabling them properly.

But to call the script in event-handler command? FastCli ????

Can some one please help me..

Thanks

Hari

 

1
Posted by Alexandru
Answered on September 30, 2016 10:31 am

Try this setup:

management api http-commands
   protocol http
   protocol unix-socket
   no shutdown

event-handler testing
   trigger on-intf Ethernet49 operstatus
   action bash python /mnt/flash/shutdown.py Ethernet49

On Flash create the following script named shutdown.py

#!/usr/bin/env python
import sys
import subprocess
from jsonrpclib import Server
switch = Server( "unix:/var/run/command-api.sock")

m_int=sys.argv[1]

def configint(interface, config):
    si="interface " + interface
    switch.runCmds(1, ["configure", si, config])

m_int_status=switch.runCmds(1, [ "show interfaces status" ])

if ( m_int_status[0]["interfaceStatuses"][m_int]["linkStatus"] == "notconnect" ):
    configint(m_int, "shutdown")

This should admin disable the Ethernet49 when this inteface goes into notconnect state. Please note that this will kick in only when the interface goes from connected to notconnect. It will not kick in when the interface goes from disabled to notconnect.

Marked as spam

Thanks Alexandru for your help, I got the same script too but bit different :P

Is there a difference between calling unix socket VS HTTPS calling command-api ?? (I understand there is a pain to go to every switch and change the IP of the switches) are there any technical difference b/w them ?

eg: switch = Server( ”https://XXX:XXX@192.168.57.13/command-api” )

(Harikrishnan Sankar at October 4, 2016 12:07 am)

Post your Answer

You must be logged in to post an answer.