美文网首页网络运维自动化
网络运维自动化八:查询交换机配置

网络运维自动化八:查询交换机配置

作者: wsf535 | 来源:发表于2018-02-28 11:53 被阅读236次

    使用<get>命令查询交换机配置,具体参数参考,《网络运维自动化入门三:netconf配置说明》https://www.jianshu.com/p/33104d4022e8
    示例代码,查看接口10GE1/0/4配置

    #coding: utf-8
    import sys
    import logging
    from ncclient import manager
    from ncclient import operations
    log=logging.getLogger(__name__)
    FILTER ="""
     <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>
    """
    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:
            get_reply = m.get(("subtree", FILTER))
            print get_reply
    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:6910eee5-2681-4fcb-ac4a-6e71b5ec3ee3" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <data>
        <ethernet xmlns="http://www.huawei.com/netconf/vrp" format-version="1.0" content-version="1.0">
          <ethernetIfs>
            <ethernetIf>
              <ifName>10GE1/0/4</ifName>
              <ifIndex>32</ifIndex>
            </ethernetIf>
          </ethernetIfs>
        </ethernet>
      </data>
    </rpc-reply>
    

    交换机实际配置:

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

    相关文章

      网友评论

        本文标题:网络运维自动化八:查询交换机配置

        本文链接:https://www.haomeiwen.com/subject/wvkmxftx.html