网络运维自动化六:写个简单的程序连接到交换机

交换机管理IP172.16.200.6 端口 22 用户名wsf535 密码 Abcd@2017 ,请根据自己的环境做更改。
test.py代码如下

#coding: utf-8
import sys
import logging
from ncclient import manager
from ncclient import operations
log=logging.getLogger(__name__)
def huawei_connect():
    return manager.connect(host='172.16.200.6',port=22,username='wsf535',password='Abcd@20
17',hostkey_verify= False,device_params={'name': "huawei"},allow_agent = False,look_for_keys = F
alse)
def test_connect():
    with huawei_connect() as m:
        n=m._session.id
        print "THE SESSION ID IS %s" % (n)
if __name__=='__main__':
    test_connect()

运行结果如下表示成功:
[root@10-57-22-228 ~]# python test.py
THE SESSION ID IS 55479

你可能感兴趣的:(网络运维自动化六:写个简单的程序连接到交换机)