網(wǎng)絡(luò)運(yùn)維自動(dòng)化七:修改交換機(jī)的配置

配置使用<edit_config>命令,具體參數(shù)參考,《網(wǎng)絡(luò)運(yùn)維自動(dòng)化入門三:netconf配置說明》http://www.itdecent.cn/p/33104d4022e8

api文檔 http://support.huawei.com/hedex/hdx.do?docid=EDOC1000065657&lang=zh&tocURL=resources/dc/zh-cn_topic_0010960544.html

示例代碼把交換機(jī)10G1/0/4改成三層接口

#coding: utf-8
import sys
import logging
from ncclient import manager
from ncclient import operations
log=logging.getLogger(__name__)
L3_INTERFACE ="""
<config>
 <ethernet xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0">
  <ethernetIfs>
   <ethernetIf>
    <ifName>10GE1/0/4</ifName>
    <l2Enable>disable</l2Enable>
   </ethernetIf>
  </ethernetIfs>
 </ethernet>
</config>
"""
def huawei_connect():
    return manager.connect(host='172.16.200.6',port=22,username='wsf535',password='Abcd@2017',hostkey_verify= False,device_params={'name': "huawei"},allow_agent = False,look_for_keys = False)
def test_connect():
    with huawei_connect() as m:
        rpc_obj = m.edit_config(target='running', config=L3_INTERFACE)
        print rpc_obj
if __name__=='__main__':
    test_connect()

執(zhí)行結(jié)果:

[root@10-57-22-228 ~]# python test.py 
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply message-id="urn:uuid:7d0374f9-4463-4027-a47a-319f4392f593" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" flow-id="495">
  <ok/>
</rpc-reply>

交換機(jī)配置
執(zhí)行前

[~testare4-10GE1/0/4]dis this
#
interface 10GE1/0/4
 device transceiver 10GBASE-FIBER
#
return

執(zhí)行后

[~testare4-10GE1/0/4]dis this
#
interface 10GE1/0/4
 undo portswitch
 device transceiver 10GBASE-FIBER
#
return
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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