网络运维自动化

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

2018-02-28  本文已影响676人  wsf535

配置使用<edit_config>命令,具体参数参考,《网络运维自动化入门三: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 ="""
<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()

执行结果:

[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>

交换机配置
执行前

[~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
上一篇下一篇

猜你喜欢

热点阅读