Reading is safe; changing is where automation earns its keep. Send configuration sets with Netmiko, save them, and confirm what actually changed.
Why: send_config_set enters configuration mode, applies a list of commands, and exits — so you push real changes atomically instead of typing them. When: use it for any change (VLANs, interfaces, ACLs) across one or many devices. Where: it returns the session log so you can see exactly what the device did.
from netmiko import ConnectHandler
commands = [
"vlan 30",
"name Guest",
"interface range Fa0/13 - 24",
"switchport mode access",
"switchport access vlan 30",
]
with ConnectHandler(**device) as conn:
output = conn.send_config_set(commands) # enters config mode, applies, exits
print(output)Why: like a human at the CLI, your script must save the running-config or the change is lost on reboot — and you should confirm the result rather than assume success. When: save after every change; verify with a follow-up show. Where: forgetting to save is just as easy to do in code as by hand.
with ConnectHandler(**device) as conn:
conn.send_config_set(commands)
conn.save_config() # write mem / copy run start
# Confirm the change actually took:
check = conn.send_command("show vlan brief | include Guest")
print("Applied:" , "Guest" in check)Why: real changes come from a reviewed config file, not commands hard-coded in a script — send_config_from_file applies a file you can version-control and diff in a pull request. When: keep device configs as files in Git and push them with automation. Where: this is the bridge to templating (next lesson), where the files are generated per device.
with ConnectHandler(**device) as conn:
# Apply a reviewed, version-controlled config file:
output = conn.send_config_from_file("configs/sw1_vlans.txt")
conn.save_config()
print(output)