cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
206
Views
0
Helpful
2
Replies

Pyats topo file

mariavelas
Level 1
Level 1

 I have been reading up on pyats and would like to know how to create a topology file as a dict like {'hostname':'ip"} instead of the yaml file shown in the examples. I am trying to connect to multiples devices to run specific show commands and store the output.

2 Replies 2

You could use something like this (update for your use case) this dictionary contains three devices, each with a hostname and IP address, you can use this topology dictionary to connect to the devices and run show commands.

topology = {
    "csr1000v-1": {"ip": "10.1.1.1"},
    "csr1000v-2": {"ip": "10.1.1.2"},
    "csr1000v-3": {"ip": "10.1.1.3"},
}
from pyats.topology import loader

# Load the testbed file
testbed = loader.load('testbed.yaml')

# Add the topology dictionary to the testbed
testbed.devices.update(topology)

# Connect to the devices
for device in topology.keys():
    testbed.devices[device].connect()

# Run show commands on the devices
for device in topology.keys():
    output = testbed.devices[device].execute('show version')
    print(output)

# Disconnect from the devices
for device in topology.keys():
    testbed.devices[device].disconnect()

Hope this helps.  

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

Ruben Cocheno
Spotlight
Spotlight

@mariavelas 

YAML will simplify your deployments going forward

Tag me to follow up.
Please mark it as Helpful and/or Solution Accepted if that is the case. Thanks for making Engineering easy again.
Connect with me for more on Linkedin https://www.linkedin.com/in/rubencocheno/