The big picture: one script, every platform
What you will learn. In Program 1 you used netmiko against Cisco routers with the lab name nk_ios. A real network is rarely all Cisco. This module teaches you to write one collector that logs in to an IOS XE router, a Junos router, an Arista EOS switch and an NX-OS switch (and, in the reference sections, ASA, FortiOS and PAN-OS firewalls) with the real netmiko names, and to run it safely every night.
Analogy: a travel adapter and a good interpreter
Imagine you travel to five countries with one laptop. The laptop is your script. The wall sockets are the vendors: each has a different shape, voltage and rule (some switch off the pager, some need a commit, some ask for a second password). netmiko is the travel adapter kit plus an interpreter: you tell it the device_type ("this wall is Junos") and it knows the shape of the plug, how to say "stop paging", how to enter config mode and how to leave it. Your job is to pick the right adapter, to know what each wall expects, and to notice when the lights go out.
The collector reads who to talk to from a file, takes passwords from the environment and speaks each vendor's dialect through its device_type.
The five questions every vendor answers differently
Almost every surprise in this module is one of five questions. Keep them in your head; each later chapter answers them for one more platform.
| Question | What can differ |
|---|---|
| 1. How do I log in? | user and password, enable secret, a different password per device |
| 2. How is paging switched off? | terminal length 0, set cli screen-length 0, terminal pager 0 |
| 3. Where is config mode? | configure terminal, configure, configure session NAME, none at all (FortiOS) |
| 4. How does config become live? | immediately (IOS, NX-OS), on commit (Junos, PAN-OS, EOS sessions) |
| 5. How is it saved? | write memory, copy running-config startup-config, or nothing to do (Junos) |
Worked example. The same job, "show me the interfaces that have an IP address", is show ip interface brief on IOS XE, NX-OS and EOS, but show interfaces terse on Junos. The IOS answer comes back with the column proto, the EOS answer with protocol. Your collector must hide those differences so that the final table looks the same for all four. That is what you build in Lab 1.
Prerequisites
- auto-ssh and py-textfsm: you already connected with netmiko (
nk_ios) and parsed output with TextFSM. Here they come back only as short refreshers. - py-concurrency: threads and
ThreadPoolExecutor. - py-secrets and py-tools: environment variables,
.envfiles, logging, exit codes. - Linux shell basics, and the ability to read a Python traceback.
The lab network and the two labs
| Device | Platform | IP | Login |
|---|---|---|---|
| AUTO01 | Ubuntu server | 10.99.0.60 | netadmin / Deccan@123 |
| R1 | IOS XE (PUN-CORE-R1) | 10.99.0.1 | netops / NK@2026, enable NK@2026 |
| J1 | Junos | 10.99.0.11 | netops / NK@2026 |
| E1 | Arista EOS | 10.99.0.21 | netops / NK@2026, enable NK@2026 |
| N1 | NX-OS | 10.99.0.31 | netops / NKlab@123 |
Lab 1, "One script, four vendors", builds an inventory-driven collector step by step: an inventory file, a probe, an interface table, config backups, threads with retries and an alert, and a diff against yesterday. Lab 2, "Four collectors that work on Cisco and fail everywhere else", hands you four broken scripts to fix. Chapter 9 walks through it.
In the lab vs on real gear. The lab speaks no real SSH: the "SSH server" is the simulated device. Waits run on a virtual clock, so a 30-second timeout does not cost you 30 real seconds. Your scripts use from netmiko import ConnectHandler exactly as on real gear; import nkmiko is the lab's own name for the same library. When the lab differs from a real device, a note like this one says so.
Common mistakes. Believing that a script tested on one Cisco router is tested. Copying the Cisco device_type to every row of the inventory. Putting passwords in the code. Reading "no exception" as "it worked".
Exam trap. The lab names nk_ios, nk_junos and so on exist only in the lab. On real gear and in interviews you say cisco_ios, juniper_junos, arista_eos, cisco_nxos.
The nightly backup that silently skipped Junos
A team ran a backup script written on Cisco routers. It looped over fifty devices, and every device that was not Cisco got the same cisco_ios type. The Cisco backups worked; the Juniper boxes timed out and were skipped by a bare except. Nobody noticed for a month, until a Junos router died and there was no config to restore.
Lesson: the device type belongs in the inventory, per device, and every failure must be counted and reported.
"How would you automate backups across Cisco, Juniper and Arista with Python?"
I would keep an inventory file with host and netmiko device_type per device, take credentials from the environment, loop with ConnectHandler, choose the show command from a per-platform map, save one dated file per device, run devices in a thread pool with one connection per thread, retry only timeouts, write failures to a log and exit non-zero so monitoring notices.
Key takeaways
- One collector can serve many vendors if the vendor differences live in data (inventory, command maps), not in copy-pasted scripts.
- Five questions separate the vendors: login, paging, config mode, commit, save.
- Use the real netmiko names;
nk_*names are lab aliases. - Count and report failures; an exit code of 0 only means "no exception".