Today just a short entry. I’ve found that it’s much easier to use Dq to get your values from parsed outputs.
This is the traditional, ”complex way” of getting value for the key [‚version short’] of the ”subdictionary” of the main dictionary where the key is [‚version’]
testbed = Genie.init('testbed.yml') r1 = testbed.devices['R1'] r1.connect(log_stdout=False) shver = r1.parse("show version") print('software version is: ' + shver['version']['version_short’])
And this is the cool way: creating a query.
from genie.utils import Dq from genie.testbed import load routingTable = r1.parse('show ip route') print(routingTable.q.contains('connected').get_values('routes')) OUTPUT: ['200.200.200.200/32', '200.200.200.201/32', '192.168.122.0/24', '1.1.1.1/32', '100.100.0.0/24']
This could be used to find any values that are below or above some threshold: eigrp neighbors that have flapped recently, ”fresh” BGP routes, spanning tree events etc.