05-22-2024 01:02 AM
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.
Solved! Go to Solution.
05-22-2024 02:45 AM
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.
05-22-2024 02:45 AM
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.
05-24-2024 01:06 AM
YAML will simplify your deployments going forward
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide