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
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,628評論 19 139
  • 一、Python簡介和環(huán)境搭建以及pip的安裝 4課時實驗課主要內(nèi)容 【Python簡介】: Python 是一個...
    _小老虎_閱讀 6,339評論 0 10
  • 新年剛過,余熱似乎還未過,許多網(wǎng)友還沉迷歡快的春節(jié)假期中。春節(jié)余熱未過,但是全國多地已經(jīng)開啟熱、熱、熱的模式了,尤...
    小小娛樂閱讀 607評論 0 0
  • Slogan是什么? 標語(英語:Slogan)或口號,是在政治、社會、商業(yè)、軍事或是宗教等范籌上所使用的一句容易...
    吳星辰閱讀 2,404評論 0 1
  • 一、父母不孝,奉神無益。 二、兄弟不和,交友無益。 三、存心不善,風水無益。 四、行止不端,讀書無益。 五、心...
    同事閱讀 1,247評論 0 0

友情鏈接更多精彩內(nèi)容