05-04-2021 06:14 AM
hi,
i'm trying to work out how to call a list of routers for a netconf python script samtest.py,
very simply shown here:
Here is my list of routers:
router_info.py
05-04-2021 08:31 AM
There is a couple of ways to do this. Like your example, I did this with Netmiko, you can create your devices and list all in here.
devices = [{ "device_type": "cisco_xr", "ip": "sbx-iosxr-mgmt.cisco.com", "username": "admin", "password": "C1sco12345", "port": "8181", }, { "device_type": "cisco_xe", "ip": "ios-xe-mgmt-latest.cisco.com", "username": "developer", "password": "C1sco12345", "port": "8181", }] for device in devices:
The only way is to use an inventory file, with JSON or YAML, for example this JSON file has a few routers in and what they do in the network - in this case some were route reflectors and other clients
{ "router:1": { "IP": "10.94.242.179", "type": "iosxr", "user": "cisco", "password": "cisco", "rr": "reflector" }, "router:2": { "IP": "10.94.242.171", "type": "iosxr", "user": "cisco", "password": "cisco", "rr": "client" }, "router:3": { "IP": "10.94.242.172", "type": "iosxr", "user": "cisco", "password": "cisco", "rr": "client" } }
In the code, pass in the JSON file (I did this with a try) then followed with a for loop
try: with open(args.inventory, "r") as f: device_data = json.load(f) except (ValueError, IOError, OSError) as err: merge_device("Could not read the 'devices' file:", err)
You will find some good examples like this on https://developer.cisco.com/codeexchange
Hope this helps.
05-04-2021 09:19 AM
Thanks!
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