Python script - String Search - Arista
<p>I'm trying to run a script on arista switch, which is a simple python script. I got some values by running a command on the switch and I need to find a value from that command. for eg:</p>

<pre><code>#!/usr/bin/python
from jsonrpclib import Server

switch = Server( "http://XXX:XXX@192.168.XX.XX/command-api" )

response = switch.runCmds( 1, [ "show interfaces ethernet 49 status" ] )

a = response[0]

print a
</code></pre>

<h2>output is</h2>

<pre><code>{'interfaceStatuses': {'Ethernet49': {'vlanInformation': {'interfaceMode': 'routed', 'interfaceForwardingModel': 'routed'}, 'bandwidth': 10000000000L, 'interfaceType': '10GBASE-SR', 'description': 'GH1TPQACORS1 Et1', 'autoNegotiateActive': False, 'duplex': 'duplexFull', 'autoNegotigateActive': False, ***'linkStatus': 'connected'***}}}
</code></pre>

<p>Out of this result, I just need 'linkStatus' : 'connected' value, how do I do it?</p>

<p>Basically you have dictionary of dictionary of dictionary. For this case, its simply. But if you have multiple of such cases, you have to iterate with the keys of first two dictionaries (dict1: interface and dict2: ethernet)</p>

<pre><code>a['interfaceStatuses']['Ethernet49']['linkStatus']
</code></pre>

python python-2.7 string-search