netmiko使用案例6 改变配置文件

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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容