config_change.py
直接更改配置
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
nxos1 = {
'host': 'nxos1.twb-tech.com',
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_nxos',
}
commands = [
'logging history size 500'
]
net_connect = Netmiko(**nxos1)
print()
print(net_connect.find_prompt())
output = net_connect.send_config_set(commands)
output += net_connect.send_command("copy run start")
print(output)
print()
config_change_file.py
读取本地txt文件更改配置
#!/usr/bin/env python
from netmiko import Netmiko
from getpass import getpass
nxos1 = {
'host': 'nxos1.twb-tech.com',
'username': 'pyclass',
'password': getpass(),
'device_type': 'cisco_nxos',
}
cfg_file = 'config_changes.txt'
net_connect = Netmiko(**nxos1)
print()
print(net_connect.find_prompt())
output = net_connect.send_config_from_file(cfg_file)
print(output)
print()
net_connect.save_config()
net_connect.disconnect()
config_changes.txt
新增vlan100,101,102
vlan 100
name blue100
vlan 101
name blue101
vlan 102
name blue102