网络运维自动化七:修改交换机的配置

配置使用命令,具体参数参考,《网络运维自动化入门三:netconf配置说明》https://www.jianshu.com/p/33104d4022e8

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

示例代码把交换机10G1/0/4改成三层接口

#coding: utf-8
import sys
import logging
from ncclient import manager
from ncclient import operations
log=logging.getLogger(__name__)
L3_INTERFACE ="""

 
  
   
    10GE1/0/4
    disable
   
  
 

"""
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()

执行结果:

[root@10-57-22-228 ~]# python test.py 


  

交换机配置
执行前

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

执行后

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

你可能感兴趣的:(网络运维自动化七:修改交换机的配置)