What does NAPALM give you that Netmiko does not? Explain getters and config replace vs merge.
Show the answer
Say this first
NAPALM is a vendor-neutral Python API over several platforms (core drivers for IOS, IOS XR, NX-OS, EOS and
Junos). Getters such as get_facts, get_interfaces and get_bgp_neighbors return the same structured
dictionaries on every platform. For config it loads a candidate, shows a diff with compare_config, then
commit_config, discard_config or later rollback. Merge adds your lines to the running config; replace
makes the running config exactly equal to the file you load.
Go deeper
Getters
get_facts, get_interfaces, get_interfaces_ip, get_arp_table, get_mac_address_table,
get_lldp_neighbors, get_bgp_neighbors, get_environment, get_config, get_route_to and more.
Not every driver implements every getter; unsupported ones raise NotImplementedError.
Config workflow
from napalm import get_network_driver
driver = get_network_driver("eos")
with driver("10.0.0.21", "netops", "secret") as dev:
print(dev.get_facts()["os_version"])
dev.load_merge_candidate(config="ntp server 10.0.0.5\n")
diff = dev.compare_config()
if diff:
print(diff)
dev.commit_config()
else:
dev.discard_config()Merge vs replace
load_merge_candidate | load_replace_candidate | |
|---|---|---|
| You supply | Only the lines to add or change | The full intended config |
| Lines on the device you did not mention | Stay | Removed |
| Good for | Small additive changes | Full config management, drift removal |
| Risk | Stale config builds up | An incomplete file deletes real config |
How it works under the hood
Each driver uses the platform's best mechanism: Junos has a native candidate and commit, EOS uses
configuration sessions, IOS XR has its own commit model. IOS has no candidate, so the driver copies the
candidate file to flash with SCP and uses configure replace for a replace. That is why IOS needs
ip scp server enable for NAPALM config operations.
Validation
compliance_report("validate.yml") compares getter results with expected values in a YAML file, for
example "these BGP peers are up". It is a quick post-check.
They will ask next
Why is replace mode better for automation, and when is it dangerous?
It is the only mode that removes config nobody declared, so it ends drift and makes the device equal to the source of truth. It is dangerous when the generated file is incomplete: a missing AAA or management ACL section is deleted on commit. Diff first, and start with a lab device.
Traps
- Assuming every getter works on every driver. Check the support matrix for your platforms.