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

使用命令查询交换机配置,具体参数参考,《网络运维自动化入门三: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 ="""
 
  
   
    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:
        get_reply = m.get(("subtree", FILTER))
        print get_reply
if __name__=='__main__':
    test_connect()

输出结果:

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


  
    
      
        
          10GE1/0/4
          32
        
      
    
  

交换机实际配置:

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

你可能感兴趣的:(网络运维自动化八:查询交换机配置)