diff --git a/.travis.yml b/.travis.yml old mode 100755 new mode 100644 diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 68b7fd0..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,85 +0,0 @@ -pipeline { - agent { - label 'node-cloudlab002' - } - options { - buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) - } - triggers { - pollSCM('H/2 * * * *') - } - stages { - stage('pre.git') { - steps { - sh ''' - root="/apps/data/tomcat_8080/jenkins_file" - python_folder=$root/python/forward - source ~/.bash_profile>/dev/null 2>&1 - pyenv activate forward - pip install -r requirements.txt >/dev/null - python setup.py clean --all >/dev/null - ''' - } - } - stage('pre.unittest+flake8') { - steps { - sh ''' - #flake8_check - source ~/.bash_profile>/dev/null 2>&1 - pyenv activate forward - echo ">[run flake8]" - flake8 ./ --config=protocol/flake8 - result_flake8=$? - echo ">[run nosetest]" - nosetests -c nosetests.ini - result_nosetests=$? - if [ ! $result_flake8 -eq 0 ] || [ ! $result_nosetests -eq 0 ];then - echo "[ERROR]: test pre failed!" - exit 1 - fi - #cp $WORKSPACE/unittests/nosetests.xml - #cp $WORKSPACE/unittests/coverage.xml - ''' - cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: 'unittests/coverage.xml', conditionalCoverageTargets: '70, 0, 0', failUnhealthy: false, failUnstable: false, lineCoverageTargets: '80, 0, 0', maxNumberOfBuilds: 0, methodCoverageTargets: '80, 0, 0', onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false - junit 'unittests/nosetests.xml' - } - } - stage('pre.install') { - steps { - sh ''' - #setuptools - source ~/.bash_profile>/dev/null 2>&1 - pyenv activate forward - echo ">[build & install]" - python setup.py install - ''' - } - } - stage('pre.regression') { - steps { - sh ''' - source ~/.bash_profile>/dev/null 2>&1 - pyenv activate forward - echo ">[run regression testing]" - echo "Null, Waiting for add..." - ''' - } - } - } - post { - success { - emailext body: ''' -

Forward开源版-预发布环境-CI

-
-

Forward develop分支提交构建已完成

- ''', - postsendScript: '$DEFAULT_POSTSEND_SCRIPT', - presendScript: '$DEFAULT_PRESEND_SCRIPT', - subject: '[Success][预发布-Forward开源版] $DEFAULT_SUBJECT', - to: '13802880354@139.com,zhangqc@fits.com.cn' - } - failure { - emailext(subject: '[Failed][预发布-Forward开源版]$DEFAULT_SUBJECT', body: '$DEFAULT_CONTENT', to: '13802880354@139.com,zhangqc@fits.com.cn') - } - } -} diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 2b0bbf4..ecdc1dd --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ * Building virtual environment (optional) 构建虚拟环境 (可选) - * 开发者用户推荐,使用pyenv和virtualenv构建纯净的python环境,基于python版本2.7.10,同时兼容python3. - * We recommend that developer users use pyenv and virtualenv to build a pure Python environment which is based on Python version 2.7.10, and compatible with python3 at the same time. + * 开发者用户推荐,使用pyenv和virtualenv构建纯净的python环境,基于python版本2.7.10 + * We recommend that developer users use pyenv and virtualenv to build a pure Python environment which is based on Python version 2.7.10. ```Bash pyenv virtualenv 2.7.10 forward @@ -28,7 +28,7 @@ * Pull 拉取当前版本 ```Bash - git clone https://github.com/tecstack/forward.git + git clone http://192.168.182.51/promise/forward.git cd forward ``` @@ -55,30 +55,19 @@ from forward import Forward new = Forward() - - # 分别传入IP地址、设备型号、登录账户、登录密码 new.addTargets(['192.168.113.1-192.168.113.2'], 'n7018', 'username', 'password') instances = new.getInstances() - # 获取实例 cisco1 = instances['192.168.113.1'] cisco2 = instances['192.168.113.2'] - # 执行show version命令 result1 = cisco1.execute('show version') result2 = cisco2.execute('show version') - # 查看命令结果 if result1['status']: - # python 2 print '[%s] OS version info: %s' % ('cisco1', result1['content']) - # python 3 - print('[%s] OS version info: %s' % ('cisco1', result1['content'])) if result2['status']: - # python 2 - print '[%s] OS version info: %s' % ('cisco2', result1['content']) - # python 3 - print('[%s] OS version info: %s' % ('cisco2', result1['content'])) + print '[%s] OS version info: %s' % ('cisco2', result2['content']) ``` * 上述代码段中出现的'cisco1'和'cisco2'就是Forward设备类实例(N7018),不同设备类实例包含的方法可能不同,具体请查阅[类库文档](/docs/class)。 @@ -90,7 +79,7 @@ * [初始化 Initialize](/docs/advance/initialize.md) * [预登陆 PreLogin](/docs/advance/prelogin.md) -* [自定义指令(适合开发者) command](/docs/advance/command.md) +* [自定义指令 command](/docs/advance/command.md) --- @@ -122,7 +111,7 @@ * alpha分支对应一个早期的内部测试版本。 * RC,Releases and Stables are named after the version number plus any kind of fish. * The devel branch corresponds to the release actively under development. -* The alpha branch corresponds to a early release which is used for In-House test. +* The alpha branch corresponds to a early release thich is used for In-House test. --- diff --git a/docs/BranchInfo.md b/docs/BranchInfo.md index 3c461bf..ff82a0b 100644 --- a/docs/BranchInfo.md +++ b/docs/BranchInfo.md @@ -4,4 +4,4 @@ *   alpha分支对应一个早期的内部测试版本。 *   RC,Releases and Stables are named after the version number plus any kind of fish. *   The devel branch corresponds to the release actively under development. -*   The alpha branch corresponds to a early release which is used for In-House test. +*   The alpha branch corresponds to a early release thich is used for In-House test. diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index f5b4e67..0fd0eba 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -16,15 +16,9 @@ result2 = cisco2.execute('show version') if result1['status']: - # python 2 print '[%s] OS version info: %s' % ('cisco1', result1['content']) - # python 3 - print('[%s] OS version info: %s' % ('cisco1', result1['content'])) if result2['status']: - # python 2 - print '[%s] OS version info: %s' % ('cisco2', result1['content']) - # python 3 - print('[%s] OS version info: %s' % ('cisco2', result1['content'])) + print '[%s] OS version info: %s' % ('cisco2', result2['content']) ``` *   上述代码段中出现的'cisco1'和'cisco2'就是Forward设备类实例(N7018),不同设备类实例包含的方法可能不同,具体请查阅类库文档。 *   The 'cisco1' and 'cisco2' appearing in the above code segment are Forward device class instances (N7018). Different device class instances contain different methods. Please consult the class library document. diff --git a/docs/Installation.md b/docs/Installation.md index 43e82ce..a5c0495 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -1,14 +1,14 @@ ## Installation 1. Building virtual environment (optional) 构建虚拟环境 (可选) - *   开发者用户推荐,使用pyenv和virtualenv构建纯净的python环境,推荐python版本2.7.10及以上版本,兼容python3 - *   We recommend that developer users use pyenv and virtualenv to build a pure Python environment, and recommend Python version 2.7.10 and later versions, including python3. + *   开发者用户推荐,使用pyenv和virtualenv构建纯净的python环境,推荐python版本2.7.10 + *   We recommend that developer users use pyenv and virtualenv to build a pure Python environment, and recommend Python version 2.7.10. ```Bash pyenv virtualenv 2.7.10 forward pyenv activate forward ``` 2. Pull 拉取当前版本 ```Bash - git clone https://github.com/tecstack/forward.git + git clone http://192.168.182.51/promise/forward.git cd forward ``` 3. Dependency 安装依赖包 diff --git a/docs/VersionInfo.md b/docs/VersionInfo.md index 79db421..ea53473 100644 --- a/docs/VersionInfo.md +++ b/docs/VersionInfo.md @@ -1,13 +1,4 @@ ## Version Update Record 版本更新记录 -### V3.2.0 -1. 实现Forward对python3的兼容性。 -2. 新增了一批设备方法,包括查询系统坂本、端口信息、路由信息、vlan、ntp信息等,详见[类库文档](/docs/class)。 -3. 完善文档。 - -### V3.1.0 -1. 简化command方法调用格式,详见[自定义指令 command](/docs/advance/command.md)。 -2. 修复优化了部分核心代码。 - ### V3.0.8 1. 新增sshv1和telnet通道标准类的command命令模式。 diff --git a/docs/advance/command.md b/docs/advance/command.md index 8c10cf3..6add678 100644 --- a/docs/advance/command.md +++ b/docs/advance/command.md @@ -6,15 +6,13 @@ ##### Options -| parameter | required | example | comments | -|:--:|:--:|:--:|:--:| -| cmd | yes | 'show vlan name VLAN2018' | Command to execute. | -| prompt | yes | { 'success': 'VLAN\s+Name[\s\S]*#', 'non-exist': r'ERROR.+not exist[\s\S]*#' } | Result type and the corresponding regex. | +| parameter | required | default | choices | comments | +|:--:|:--:|:--:|:--:|:--:| +| cmd | yes | none | | The command line you want to execute. | +| prompt | yes | none | | The prompt dict which will decide the type of CMD execution result. | * command会在执行cmd之后依次匹配prompt中定义的正则表达式,匹配后中断后续匹配并返回状态结果。 -* prompt中定义的正则表达式匹配成功后即返回结果,可能会导致设备返回的后续结果没有完整接收,所以建议活用正则表达式(例如以命令提示符为结尾)以避免上述情况。 - ##### Return * command指令返回一个字典结构 @@ -22,9 +20,9 @@ | attr | type | example | comments | |:--:|:--:|:--:|:--:| | status | boolean | True | CMD execution status. | -| state | string | 'non-exist' | CMD execution result type. | -| content | string | 'ERROR: VLAN does not exist, vlan name VLAN2018' | CMD execution console output. | -| errLog | string | '.....' | CMD execution error log(when status is False). | +| state | string | 'state_you_defined' | CMD execution result type. | +| content | boolean | True | CMD execution console output. | +| errLog | boolean | True | CMD execution error log(when status is False). | ##### Example @@ -63,18 +61,18 @@ linux = fw.getInstances()['192.168.10.10'] def cp(from_path, to_path, overwrite): cmd = 'cp -i %s %s' % (from_path, to_path) - prompt = { - 'exist': r'overwrite', - 'denied': r'permission denied', - 'success': r'COREVM60 \~\]\$' - } + prompt = [ + { 'exist': ['overwrite'] }, + { 'denied': ['permission denied'] }, + { 'success': ['COREVM60 \~\]\$', '\$'] } + ] def call_exist(): confirm_cmd = overwrite - confirm_prompt = { - 'error': r'error', - 'success': r'COREVM60 \~\]\$' - } + confirm_prompt = [ + { 'error': ['error'] }, + { 'success': ['COREVM60 \~\]\$', '\$'] } + ] confirm_result = linux.command(cmd=confirm_cmd, prompt=confirm_prompt) if confirm_result['status'] == True and confirm_result['state'] == 'success': print 'copy complete! overwrite: %s' % overwrite diff --git a/docs/class/README.md b/docs/class/README.md index 3fc0f8a..47f9af1 100644 --- a/docs/class/README.md +++ b/docs/class/README.md @@ -62,7 +62,3 @@ * [zx5952](/docs/class/sshv2/zte/zx5952.md) * [baseBrocade](/docs/class/sshv2/brocade) * [vlb](/docs/class/sshv2/brocade/vlb.md) - * [baseRuijieV1](/docs/class/sshv1/ruijie) - * [rg5510](/docs/class/sshv1/ruijie/rg5510v1.md) - * [baseRuijieV2](/docs/class/sshv2/ruijie) - * [rg5510](/docs/class/sshv2/ruijie/rg5510v2.md) \ No newline at end of file diff --git a/docs/class/sshv1/README.md b/docs/class/sshv1/README.md index 39232cb..e69de29 100644 --- a/docs/class/sshv1/README.md +++ b/docs/class/sshv1/README.md @@ -1,202 +0,0 @@ -## 基本介绍 - -* 支持凡是使用SSH协议第1版本进行远程控制的设备。 -* 使用Pexpect作为远程登录模块。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | - -## 接口详情 - - - - -* __init__ - - 在登录设备之前,Forward需要取得登录设备的基本信息,诸如IP地址、设备型号、账号密码、用户名、特权模式密码等;同时需要设定一些初始化参数,用于记录程序运行状态。最后程序返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | - | --- | --- | --- | --- | - | ip | str | 是 | 目标设备的IP地址 | - | username | str | 是 | 目标设备的登录账户 | - | password | str | 是 | 目标设备的密码 | - | privilegePw | str | 否 | 特权模式密码 | - | port | int | 否 | 目标设备端口,默认端口22 | - | timeout | int | 否 | 消息接收超时时间,默认30秒 | - | kwargs | dict | 否 | 自定义参数,非Forward所使用 | - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> {"status":False,"content":"","errLog":"用户名或密码错误。"} - ``` - ---- - -* logout - - 注销与单个设备的会话。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.logout() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | show version | - - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ...cisco Nexus7700 C7710 (10 Slot) Chassis ("Supervisor Module-2")... | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.execute("show version") - >>> {"status":True,"content":"...cisco Nexus7700 C7710 (10 Slot)...","errLog":""} - ``` - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | enable | - | prompt | dict | 是 | 预测将会出现的字符 | {"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "} | - | timeout | int | 否 | 消息接收超时时间 | 60(单位:秒) | - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | TEST-N7710-1# | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - - * 案例 - - ``` Python - >>> instance...... - >>> instance.command("enable",prompt={"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "}) - >>> {"status":True,"content":"...TEST-N7710-1# ","errLog":""} - ``` - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - * 调用参数 - - 无。 - - * 返回参数 - 无,但可通过self.prompt取得。 - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | bufferData | str | 是 | 当前已收到的命令结果 | ******-- More -- | - - * 返回参数 - - 无。 - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - * 调用参数 - - 无。 - - * 返回参数 - - 无。 \ No newline at end of file diff --git a/docs/class/sshv1/maipu/README.md b/docs/class/sshv1/maipu/README.md index b3cf478..e69de29 100644 --- a/docs/class/sshv1/maipu/README.md +++ b/docs/class/sshv1/maipu/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持迈普设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV1](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv1/maipu/s3300.md b/docs/class/sshv1/maipu/s3300.md index e2a181d..e69de29 100644 --- a/docs/class/sshv1/maipu/s3300.md +++ b/docs/class/sshv1/maipu/s3300.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持迈普的S3300型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseMaipu](/docs/class/sshv1/maipu/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/README.md b/docs/class/sshv2/README.md index fe4c1e2..e69de29 100644 --- a/docs/class/sshv2/README.md +++ b/docs/class/sshv2/README.md @@ -1,202 +0,0 @@ -## 基本介绍 - -* 支持凡是使用SSH协议第2版本进行远程控制的设备。 -* 使用Pramiko作为远程登录模块。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | - -## 接口详情 - - - - -* __init__ - - 在登录设备之前,Forward需要取得登录设备的基本信息,诸如IP地址、设备型号、账号密码、用户名、特权模式密码等;同时需要设定一些初始化参数,用于记录程序运行状态。最后程序返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | - | --- | --- | --- | --- | - | ip | str | 是 | 目标设备的IP地址 | - | username | str | 是 | 目标设备的登录账户 | - | password | str | 是 | 目标设备的密码 | - | privilegePw | str | 否 | 特权模式密码 | - | port | int | 否 | 目标设备端口,默认端口22 | - | timeout | int | 否 | 消息接收超时时间,默认30秒 | - | kwargs | dict | 否 | 自定义参数,非Forward所使用 | - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> {"status":False,"content":"","errLog":"用户名或密码错误。"} - ``` - ---- - -* logout - - 注销与单个设备的会话。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.logout() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | show version | - - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ...cisco Nexus7700 C7710 (10 Slot) Chassis ("Supervisor Module-2")... | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.execute("show version") - >>> {"status":True,"content":"...cisco Nexus7700 C7710 (10 Slot)...","errLog":""} - ``` - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | enable | - | prompt | dict | 是 | 预测将会出现的字符 | {"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "} | - | timeout | int | 否 | 消息接收超时时间 | 60(单位:秒) | - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | TEST-N7710-1# | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - - * 案例 - - ``` Python - >>> instance...... - >>> instance.command("enable",prompt={"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "}) - >>> {"status":True,"content":"...TEST-N7710-1# ","errLog":""} - ``` - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - * 调用参数 - - 无。 - - * 返回参数 - 无,但可通过self.prompt取得。 - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | bufferData | str | 是 | 当前已收到的命令结果 | ******-- More -- | - - * 返回参数 - - 无。 - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - * 调用参数 - - 无。 - - * 返回参数 - - 无。 \ No newline at end of file diff --git a/docs/class/sshv2/baer/README.md b/docs/class/sshv2/baer/README.md index 8b71f98..e69de29 100644 --- a/docs/class/sshv2/baer/README.md +++ b/docs/class/sshv2/baer/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持贝尔设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/baer/sr7750.md b/docs/class/sshv2/baer/sr7750.md index 509bf39..e69de29 100644 --- a/docs/class/sshv2/baer/sr7750.md +++ b/docs/class/sshv2/baer/sr7750.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持贝尔SR7750型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/baer/sr7950.md b/docs/class/sshv2/baer/sr7950.md index 69c7ee3..e69de29 100644 --- a/docs/class/sshv2/baer/sr7950.md +++ b/docs/class/sshv2/baer/sr7950.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持贝尔SR7950型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/brocade/README.md b/docs/class/sshv2/brocade/README.md index 5f33869..e69de29 100644 --- a/docs/class/sshv2/brocade/README.md +++ b/docs/class/sshv2/brocade/README.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持博科设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/brocade/adx03100.md b/docs/class/sshv2/brocade/adx03100.md deleted file mode 100644 index 32f1fad..0000000 --- a/docs/class/sshv2/brocade/adx03100.md +++ /dev/null @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持博科ADX03100和部分VLB设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseBrocade](/docs/class/sshv2/brocade/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/example.md b/docs/class/sshv2/brocade/vlb.md similarity index 100% rename from example.md rename to docs/class/sshv2/brocade/vlb.md diff --git a/docs/class/sshv2/cisco/README.md b/docs/class/sshv2/cisco/README.md index 0197caa..e69de29 100644 --- a/docs/class/sshv2/cisco/README.md +++ b/docs/class/sshv2/cisco/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/adx03100.md b/docs/class/sshv2/cisco/adx03100.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/class/sshv2/cisco/asa.md b/docs/class/sshv2/cisco/asa.md index c6d717d..e69de29 100644 --- a/docs/class/sshv2/cisco/asa.md +++ b/docs/class/sshv2/cisco/asa.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科ASA设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/asr1006.md b/docs/class/sshv2/cisco/asr1006.md index 692403b..e69de29 100644 --- a/docs/class/sshv2/cisco/asr1006.md +++ b/docs/class/sshv2/cisco/asr1006.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科ASR1006设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/c2960.md b/docs/class/sshv2/cisco/c2960.md index 43b1fc0..e69de29 100644 --- a/docs/class/sshv2/cisco/c2960.md +++ b/docs/class/sshv2/cisco/c2960.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科C2960设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/c4510.md b/docs/class/sshv2/cisco/c4510.md index 45bc806..e69de29 100644 --- a/docs/class/sshv2/cisco/c4510.md +++ b/docs/class/sshv2/cisco/c4510.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科C4510设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/c6506.md b/docs/class/sshv2/cisco/c6506.md index 86859a0..e69de29 100644 --- a/docs/class/sshv2/cisco/c6506.md +++ b/docs/class/sshv2/cisco/c6506.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科C6506设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/c6509.md b/docs/class/sshv2/cisco/c6509.md index f9957cc..e69de29 100644 --- a/docs/class/sshv2/cisco/c6509.md +++ b/docs/class/sshv2/cisco/c6509.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科C6509设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/n5548.md b/docs/class/sshv2/cisco/n5548.md index 3ef91a5..e69de29 100644 --- a/docs/class/sshv2/cisco/n5548.md +++ b/docs/class/sshv2/cisco/n5548.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科N5548设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/n5596.md b/docs/class/sshv2/cisco/n5596.md index 5d74219..e69de29 100644 --- a/docs/class/sshv2/cisco/n5596.md +++ b/docs/class/sshv2/cisco/n5596.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科N5596设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/n7010.md b/docs/class/sshv2/cisco/n7010.md index a7cbd29..e69de29 100644 --- a/docs/class/sshv2/cisco/n7010.md +++ b/docs/class/sshv2/cisco/n7010.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科N7018设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/n7018.md b/docs/class/sshv2/cisco/n7018.md index 3f41ebd..e69de29 100644 --- a/docs/class/sshv2/cisco/n7018.md +++ b/docs/class/sshv2/cisco/n7018.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持思科N7018设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/cisco/n7710.md b/docs/class/sshv2/cisco/n7710.md index 4ca15d2..e69de29 100644 --- a/docs/class/sshv2/cisco/n7710.md +++ b/docs/class/sshv2/cisco/n7710.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持思科N7710设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/cisco/n7718.md b/docs/class/sshv2/cisco/n7718.md index 7c5e3c1..e69de29 100644 --- a/docs/class/sshv2/cisco/n7718.md +++ b/docs/class/sshv2/cisco/n7718.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持思科N7718设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseCisco](/docs/class/sshv2/cisco/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/depp/README.md b/docs/class/sshv2/depp/README.md index 05f8070..e69de29 100644 --- a/docs/class/sshv2/depp/README.md +++ b/docs/class/sshv2/depp/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持迪普设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/depp/f1000.md b/docs/class/sshv2/depp/f1000.md index eea5af5..e69de29 100644 --- a/docs/class/sshv2/depp/f1000.md +++ b/docs/class/sshv2/depp/f1000.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持迪普设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseDepp](/docs/class/sshv2/deep/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/f5/README.md b/docs/class/sshv2/f5/README.md index 8b71f98..e69de29 100644 --- a/docs/class/sshv2/f5/README.md +++ b/docs/class/sshv2/f5/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持贝尔设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/f5/f510000.md b/docs/class/sshv2/f5/f510000.md index 29ffad7..e69de29 100644 --- a/docs/class/sshv2/f5/f510000.md +++ b/docs/class/sshv2/f5/f510000.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持F5的F510000型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseF5](/docs/class/sshv2/f5/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/fenghuo/README.md b/docs/class/sshv2/fenghuo/README.md index a620ca6..e69de29 100644 --- a/docs/class/sshv2/fenghuo/README.md +++ b/docs/class/sshv2/fenghuo/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持烽火设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/fenghuo/s5800.md b/docs/class/sshv2/fenghuo/s5800.md index 49de3d4..e69de29 100644 --- a/docs/class/sshv2/fenghuo/s5800.md +++ b/docs/class/sshv2/fenghuo/s5800.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持F5的S5800型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseFenghuo](/docs/class/sshv2/fenghuo/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/fortinet/README.md b/docs/class/sshv2/fortinet/README.md index d62face..e69de29 100644 --- a/docs/class/sshv2/fortinet/README.md +++ b/docs/class/sshv2/fortinet/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持飞塔设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} diff --git a/docs/class/sshv2/fortinet/fg1240.md b/docs/class/sshv2/fortinet/fg1240.md index c2f978d..e69de29 100644 --- a/docs/class/sshv2/fortinet/fg1240.md +++ b/docs/class/sshv2/fortinet/fg1240.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持烽火的FG1240型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseBaer](/docs/class/sshv2/baer/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/fortinet/fg3040.md b/docs/class/sshv2/fortinet/fg3040.md index 7749c0a..e69de29 100644 --- a/docs/class/sshv2/fortinet/fg3040.md +++ b/docs/class/sshv2/fortinet/fg3040.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持烽火的FG3040型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/fortinet/fg3950.md b/docs/class/sshv2/fortinet/fg3950.md index 6c7ae42..e69de29 100644 --- a/docs/class/sshv2/fortinet/fg3950.md +++ b/docs/class/sshv2/fortinet/fg3950.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持烽火的FG3950型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseFortinet](/docs/class/sshv2/fortinet/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/README.md b/docs/class/sshv2/huawei/README.md index 3e43616..e69de29 100644 --- a/docs/class/sshv2/huawei/README.md +++ b/docs/class/sshv2/huawei/README.md @@ -1,411 +0,0 @@ -## 基本介绍 - -* 支持华为设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/e1000e.md b/docs/class/sshv2/huawei/e1000e.md index 0411d09..e69de29 100644 --- a/docs/class/sshv2/huawei/e1000e.md +++ b/docs/class/sshv2/huawei/e1000e.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的E1000E型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/e8000e.md b/docs/class/sshv2/huawei/e8000e.md index a4a920b..e69de29 100644 --- a/docs/class/sshv2/huawei/e8000e.md +++ b/docs/class/sshv2/huawei/e8000e.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的E8000E型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/e8160e.md b/docs/class/sshv2/huawei/e8160e.md index e223a10..e69de29 100644 --- a/docs/class/sshv2/huawei/e8160e.md +++ b/docs/class/sshv2/huawei/e8160e.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的E8160E型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/ne40ex16.md b/docs/class/sshv2/huawei/ne40ex16.md index 29d6ad1..e69de29 100644 --- a/docs/class/sshv2/huawei/ne40ex16.md +++ b/docs/class/sshv2/huawei/ne40ex16.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的NE40EX16型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/ne40ex3.md b/docs/class/sshv2/huawei/ne40ex3.md index f2cd5c2..e69de29 100644 --- a/docs/class/sshv2/huawei/ne40ex3.md +++ b/docs/class/sshv2/huawei/ne40ex3.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的NE40EX3型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s5328.md b/docs/class/sshv2/huawei/s5328.md index 2de9ff6..e69de29 100644 --- a/docs/class/sshv2/huawei/s5328.md +++ b/docs/class/sshv2/huawei/s5328.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S5328型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s5352.md b/docs/class/sshv2/huawei/s5352.md index fde3c72..e69de29 100644 --- a/docs/class/sshv2/huawei/s5352.md +++ b/docs/class/sshv2/huawei/s5352.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S5352型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s8512.md b/docs/class/sshv2/huawei/s8512.md index f6b9482..e69de29 100644 --- a/docs/class/sshv2/huawei/s8512.md +++ b/docs/class/sshv2/huawei/s8512.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S8512型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s9303.md b/docs/class/sshv2/huawei/s9303.md index f0be5d8..e69de29 100644 --- a/docs/class/sshv2/huawei/s9303.md +++ b/docs/class/sshv2/huawei/s9303.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S9303型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s9306.md b/docs/class/sshv2/huawei/s9306.md index 42f9013..e69de29 100644 --- a/docs/class/sshv2/huawei/s9306.md +++ b/docs/class/sshv2/huawei/s9306.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S9306型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/huawei/s9312.md b/docs/class/sshv2/huawei/s9312.md index 4abc07d..e69de29 100644 --- a/docs/class/sshv2/huawei/s9312.md +++ b/docs/class/sshv2/huawei/s9312.md @@ -1,391 +0,0 @@ -## 基本介绍 - -* 支持华为的S9312型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| generalMode | 切换至普通模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) - ---- - -* privilegeMode - - 在设备上,切换至特权(sys)模式。 - - 注意:账户需要具备权限才能切换,否则不能切换。 - - 功能特性继承自[baseHuawei](/docs/class/sshv2/huawei/README.md) ---- - -* generalMode - - 在设备上,切换至至普通模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:保存配置需要降低至该模式下。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.generalModeMode() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - diff --git a/docs/class/sshv2/linux/README.md b/docs/class/sshv2/linux/README.md index eb77447..e69de29 100644 --- a/docs/class/sshv2/linux/README.md +++ b/docs/class/sshv2/linux/README.md @@ -1,89 +0,0 @@ -## 基本介绍 - -* 支持Linux设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | - - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseSSHV2](/docs/class/sshv2/README.md) diff --git a/docs/class/sshv2/linux/bclinux7.md b/docs/class/sshv2/linux/bclinux7.md index ca88179..e69de29 100644 --- a/docs/class/sshv2/linux/bclinux7.md +++ b/docs/class/sshv2/linux/bclinux7.md @@ -1,89 +0,0 @@ -## 基本介绍 - -* 支持Linux设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | - - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseLinux](/docs/class/sshv2/linux/README.md) diff --git a/docs/class/sshv2/raisecom/README.md b/docs/class/sshv2/raisecom/README.md index 2062710..e69de29 100644 --- a/docs/class/sshv2/raisecom/README.md +++ b/docs/class/sshv2/raisecom/README.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持瑞斯康达设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/raisecom/r3048g.md b/docs/class/sshv2/raisecom/r3048g.md index 5f74b3e..e69de29 100644 --- a/docs/class/sshv2/raisecom/r3048g.md +++ b/docs/class/sshv2/raisecom/r3048g.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持瑞斯康达R3048G型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/ruijie/README.md b/docs/class/sshv2/ruijie/README.md deleted file mode 100644 index c4e1d4b..0000000 --- a/docs/class/sshv2/ruijie/README.md +++ /dev/null @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持锐捷设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/ruijie/rg5510.md b/docs/class/sshv2/ruijie/rg5510.md deleted file mode 100644 index ba5835c..0000000 --- a/docs/class/sshv2/ruijie/rg5510.md +++ /dev/null @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持锐捷的RG5510型设备操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/zte/README.md b/docs/class/sshv2/zte/README.md index 4f2a3c3..e69de29 100644 --- a/docs/class/sshv2/zte/README.md +++ b/docs/class/sshv2/zte/README.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持中兴设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/zte/m6000.md b/docs/class/sshv2/zte/m6000.md index 1e35613..e69de29 100644 --- a/docs/class/sshv2/zte/m6000.md +++ b/docs/class/sshv2/zte/m6000.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持中兴设备的M6000型设备操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/sshv2/zte/zx5952.md b/docs/class/sshv2/zte/zx5952.md index e23429e..e69de29 100644 --- a/docs/class/sshv2/zte/zx5952.md +++ b/docs/class/sshv2/zte/zx5952.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持中兴设备的ZX5952型设备操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/telnet/README.md b/docs/class/telnet/README.md index 16938eb..e69de29 100644 --- a/docs/class/telnet/README.md +++ b/docs/class/telnet/README.md @@ -1,202 +0,0 @@ -## 基本介绍 - -* 支持凡是使用TELNET协议进行远程控制的设备。 -* 使用TelnetLib作为远程登录模块。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | - -## 接口详情 - - - - -* __init__ - - 在登录设备之前,Forward需要取得登录设备的基本信息,诸如IP地址、设备型号、账号密码、用户名、特权模式密码等;同时需要设定一些初始化参数,用于记录程序运行状态。最后程序返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | - | --- | --- | --- | --- | - | ip | str | 是 | 目标设备的IP地址 | - | username | str | 是 | 目标设备的登录账户 | - | password | str | 是 | 目标设备的密码 | - | privilegePw | str | 否 | 特权模式密码 | - | port | int | 否 | 目标设备端口,默认端口22 | - | timeout | int | 否 | 消息接收超时时间,默认30秒 | - | kwargs | dict | 否 | 自定义参数,非Forward所使用 | - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> {"status":False,"content":"","errLog":"用户名或密码错误。"} - ``` - ---- - -* logout - - 注销与单个设备的会话。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.logout() - >>> {"status":True,"content":"","errLog":""} - ``` - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | show version | - - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ...cisco Nexus7700 C7710 (10 Slot) Chassis ("Supervisor Module-2")... | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.execute("show version") - >>> {"status":True,"content":"...cisco Nexus7700 C7710 (10 Slot)...","errLog":""} - ``` - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | cmd | str | 是 | 设备操作系统命令 | enable | - | prompt | dict | 是 | 预测将会出现的字符 | {"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "} | - | timeout | int | 否 | 消息接收超时时间 | 60(单位:秒) | - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | True | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | TEST-N7710-1# | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | | - - - * 案例 - - ``` Python - >>> instance...... - >>> instance.command("enable",prompt={"success":"TEST-N7710-1# ","error":"TEST-N7710-1> "}) - >>> {"status":True,"content":"...TEST-N7710-1# ","errLog":""} - ``` - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - * 调用参数 - - 无。 - - * 返回参数 - 无,但可通过self.prompt取得。 - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - * 调用参数 - - | 参数名 | 类型 | 必须 | 描述 | 样例 | - | --- | --- | --- | --- | --- | - | bufferData | str | 是 | 当前已收到的命令结果 | ******-- More -- | - - * 返回参数 - - 无。 - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - * 调用参数 - - 无。 - - * 返回参数 - - 无。 \ No newline at end of file diff --git a/docs/class/telnet/juniper/README.md b/docs/class/telnet/juniper/README.md index 3eb83e7..e69de29 100644 --- a/docs/class/telnet/juniper/README.md +++ b/docs/class/telnet/juniper/README.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持Juniper设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/telnet/juniper/mx960.md b/docs/class/telnet/juniper/mx960.md index d7094bd..e69de29 100644 --- a/docs/class/telnet/juniper/mx960.md +++ b/docs/class/telnet/juniper/mx960.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持Juniper的MX960型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/telnet/juniper/srx3400.md b/docs/class/telnet/juniper/srx3400.md index 4c87f65..e69de29 100644 --- a/docs/class/telnet/juniper/srx3400.md +++ b/docs/class/telnet/juniper/srx3400.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持Juniper的SRX3400型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/telnet/venustech/README.md b/docs/class/telnet/venustech/README.md index a50b83a..e69de29 100644 --- a/docs/class/telnet/venustech/README.md +++ b/docs/class/telnet/venustech/README.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持启明星成设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/docs/class/telnet/venustech/usg1000.md b/docs/class/telnet/venustech/usg1000.md index ad3f4b6..e69de29 100644 --- a/docs/class/telnet/venustech/usg1000.md +++ b/docs/class/telnet/venustech/usg1000.md @@ -1,412 +0,0 @@ -## 基本介绍 - -* 支持启明星成的USG1000型设备的操作。 - -## 接口列表 - - -| 接口名 | 描述 | -| --- | --- | -| __init__ | 实例初始化 | -| login | 登录目标设备 | -| logout | 登出目标设备 | -| execute | 执行查询命令(普通) | -| command | 执行所有命令(高级) | -| getPrompt | 获取主机提示符,并识别登录设备后所处模式 | -| getMore | 自动获取分页消息 | -| cleanBuffer | 清除通道内残留信息 | -| privilegeMode | 切换至特权模式 | -| configMode | 切换至配置模式 | -| commit | 保存配置 | -| showVersion | 查看设备版本信息 | -| showRoute | 查看路由表信息 | -| showVlan | 查看Vlan表信息 | -| showNtp | 查看NTP服务器地址信息 | -| showLog | 查看SYSLOG服务器地址信息 | -| showSnmp | 查看SNMP服务端地址信息 | -| showInterface | 查看Interface列表信息 | - -## 接口详情 - - -* __init__ - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* login - - 调用此接口进行登录(参数来自init),成功后取得shell环境、清除登陆后设备发送的欢迎信息、设置超时时间(timeout),判断登录设备是否遇到密码过期提醒需要修改、以及取得主机提示符,比如 `[root@localhost ] # ` 。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* logout - - 注销与单个设备的会话。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* execute - - 在目标设备上执行一个`查询`命令,比如`show`、`display`,然后取得该命令的执行结果,最后返回一个字典(dict)格式的数据。 - - 注意: 不要使用该接口执行切换模式的命令,比如`enable`、`sys`、`config`、`interface`,也不要在切换模式后使用该接口,如果真的有需要,请使用command高级开发接口。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* command - - 在目标设备上执行`任何`命令,然后一直等待收取该命令的执行结果,直到`预期的消息出现`或`等待超时`为止,最后返回一个字典(dict)格式的数据。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getPrompt - - 取得目标设备上的主机提示符,比如:`TEST-N7710-1# `、`TEST-N7710-1> `等。 - - `注意:该接口一般仅用于Forward内部使用。` - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* getMore - - 自动获取因一个命令结果较长而导致的分页内容。 - - `注意:该接口仅用于Forward内部使用`。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - ---- - -* cleanBuffer - - 清除在`socket`内,因接受消息不彻底而遗留的字符数据。 - - 注意:`execute`、`command`在每次执行命令之前会自动调用该接口进行清除,该接口一般只用于Forward内部使用。 - - 功能特性继承自[baseRaiseCome](/docs/class/sshv2/raisecome/README.md) - - ---- - -* privilegeMode - - 在设备上,切换至特权模式。支持从普通模式切换至特权模式,也支持从更高一级的模式(如配置模式、接口模式等)降低至特权模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果设备提示需要输入特权模式密码的,在登录之前必须传递对应的特权模式密码给Forward,以便在切换时自动输入,否则会切换失败;如果切换至特权模式无需密码的,可以传递特权模式密码动作。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 用户名或密码错误 | - - * 案例(部分设备需切换至特权模式才能执行show run命令,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.privilegeMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("show run",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` ---- - -* configMode - - 在设备上,切换至配置模式。支持从普通模式直接切换至配置模式,也支持从更高一级的模式(如接口模式等)降低至配置模式。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:如果是从普通模式直接切换到配置模式的,中间需要经过切换至`特权模式`,在该过程中有可能需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 切换失败 | - - * 案例(当设备进入配置模式时,才能进入interface模式,下面模拟这样的场景) - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.configMode() - >>> {"status":True,"content":"","errLog":""} - >>> instance.command("interface ge0/0/1",prompt={"success":"(#|>|\]) ?$"},"error":"error") - ``` - ---- - -* commit - - 在设备上,当配置好一些参数后,可以调用该接口进行保存配置。而在调用之前,无需关心设备处于哪一级模式下。 - - 注意:调用该接口需要shell处于特权模式下(华为设备除外),在这个过程中可能会需要特权模式密码。所以在Forward登录之初,就应该传递特权模式密码以备用,如果设备不需要特权模式密码,则可以不用传递。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 保存失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.commit() - >>> {"status":True,"content":"保存成功","errLog":""} - ---- - -* showVersion - - 查看设备的软件版本信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | str | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVersion() - >>> {"status":True,"content":"V7.1.2.3","errLog":""} - ---- - -* showRoute - - 查看设备的路由表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | 路由列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 路由列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | net | str | 网段 | 192.168.1.0 | - | mask | str | 掩码 | 24 | - | metric | str | metric值 | 1 | - | type | str | 路由类型 | ospf | - | description | str | 描述 | 无 | - | interface | str | 网卡口 | g1 | - | via | str | 下一跳网关地址 | 10.0.0.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showRoute() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showVlan - - 查看设备的Vlan列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Vlan列表的详细字段 | - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * Vlan列表的详细字段 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | id | str | ID | 20 | - | description | str | 描述 | 无 | - | status | str | 状态 | 无 | - | type | str | Vlan类型 | 无 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showVlan() - >>> {"status":True,"content":[{...},{...}],"errLog":""} - ---- - -* showNtp - - 查看设备的NTP服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.1.1","192.168.1.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showNtp() - >>> {"status":True,"content":["192.168.1.1","192.168.1.2"],"errLog":""} - ---- - -* showLog - - 查看设备的SYSLOG服务器地址列表信息。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.2.1","192.168.2.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showLog() - >>> {"status":True,"content":["192.168.2.1","192.168.2.2"],"errLog":""} - ---- - -* showSnmp - - 查看设备的SYSLOG服务器地址列表信息。 - - 注意:该接口只获取trap模式的SNMP服务器地址列表。 - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | ["192.168.3.1","192.168.3.2"]| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showSnmp() - >>> {"status":True,"content":["192.168.3.1","192.168.3.2"],"errLog":""} - -* showInterface - - 查看设备的Interface列表信息。 - - - * 调用参数 - - 无。 - - * 返回参数 - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | status | bool | 调用该接口是否成功 | False | - | content | list | 调用该接口所产生的正确内容输出,但可能为空,这取决于所执行命令的结果 | Interface数据格式字段| - | errLog | str | 调用该接口所产生的错误内容或Forward的错误提示信息 | 命令执行失败 | - - - * Interface数据格式字段 - - - | 字段 | 类型 | 描述 | 样例 | - | --- | --- | --- | --- | - | interfaceName| str | 名称 | ge/0/1/1 | - | members | list | 接口绑定的网卡 | [....] | - | lineState | str | 接口状态 | enable或其他叫法 | - | adminSteate | str | 管理状态 | admin down等等 | - | description | str | 描述 | 无 | - | speed | str | 接口速率 | 100M/bps | - | type | str | 接口类型 | 各个设备型号叫法不一 | - | duplex | str | 工作模式 | 双工/半双工/自动 | - | inputRate | str | 接口吞数据量速率 | 无 | - | outputRate | str | 接口吐数据量速率 | 无 | - | crc | str | CRC值 | 无 | - | mtu | str | MTU值 | 1500 | - | ip | str | 接口配置的IP地址 | 192.168.1.1 | - - - * 案例 - - ``` Python - >>> instance=...... - >>> instance.login() - >>> instance.showInterface() - >>> {"status":True,"content":[{...},{...}],"errLog":""} \ No newline at end of file diff --git a/lib/forward/__init__.py b/lib/forward/__init__.py old mode 100755 new mode 100644 index e25fa60..afed61b --- a/lib/forward/__init__.py +++ b/lib/forward/__init__.py @@ -1,23 +1,10 @@ -# coding:utf8 +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael import threading import importlib -import six import forward.release from forward.utils.forwardError import ForwardError from forward.utils.loginThread import loginThread @@ -50,7 +37,7 @@ def addTargets(self, iplist, model, username, password, **kwargs): if paraCheck([[ip, model, username, password, kwargs]]): targetList.append([ip, model, username, password, kwargs]) else: - six.print_("[Add Targets Error]: %s parameters type error, please check." % ip) + print "[Add Targets Error]: %s parameters type error, please check." % ip self.targets.extend(targetList) diff --git a/lib/forward/devclass/__init__.py b/lib/forward/devclass/__init__.py index 618b041..e69de29 100644 --- a/lib/forward/devclass/__init__.py +++ b/lib/forward/devclass/__init__.py @@ -1,14 +0,0 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . diff --git a/lib/forward/devclass/adx03100.py b/lib/forward/devclass/adx03100.py index fc15839..606b400 100644 --- a/lib/forward/devclass/adx03100.py +++ b/lib/forward/devclass/adx03100.py @@ -1,30 +1,17 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for ADX03100. +Author: Cheung Kei-chuen """ -from forward.devclass.baseBrocade import BASEBROCADE +from forward.devclass.baseCisco import BASECISCO -class ADX03100(BASEBROCADE): - """The device model belongs to the BROCADE series - so the attributes and methods of BASEBROCADE are inherited. +class ADX03100(BASECISCO): + """The device model belongs to the cisco series + so the attributes and methods of BASECISCO are inherited. """ pass diff --git a/lib/forward/devclass/asa.py b/lib/forward/devclass/asa.py index 18270db..3c12f96 100644 --- a/lib/forward/devclass/asa.py +++ b/lib/forward/devclass/asa.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for asa. +Author: Cheung Kei-chuen """ import re @@ -35,7 +22,7 @@ def cleanBuffer(self): to fit the device of this type. """ if self.shell.recv_ready(): - self.shell.recv(4096).decode() + self.shell.recv(4096) self.shell.send('\r\n') buff = '' """ When after switching mode, the prompt will change, @@ -43,109 +30,6 @@ def cleanBuffer(self): while not re.search(self.basePrompt, buff.split('\n')[-1]): try: # Cumulative return result - buff += self.shell.recv(1024).decode() - # Remove the \x charactor - buff += re.sub("\x07", "", buff) + buff += self.shell.recv(1024) except Exception: raise ForwardError('Receive timeout [%s]' % (buff)) - - def addUser(self, username, password): - # Overriding methods - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} password {password}\n') - - def changePassword(self, username, password): - # Overriding methods - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} password {password}\n') - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+.+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in re.findall("Interface[\s\S]+?5 minute drop rate", result["content"]): - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "mac": "", - } - # Get name of the interface - tmp = re.search("Interface (.*?),", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("IP Address (.*),", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search("address ([\S]+),", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - # Line Protocol. - tmp = re.search("line protocol is (.*)", _interfaceInfo) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo diff --git a/lib/forward/devclass/asr1006.py b/lib/forward/devclass/asr1006.py index c339467..ba5b06e 100644 --- a/lib/forward/devclass/asr1006.py +++ b/lib/forward/devclass/asr1006.py @@ -1,25 +1,12 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for ASR1006. +Author: Cheung Kei-chuen """ -import re + from forward.devclass.baseCisco import BASECISCO @@ -27,16 +14,4 @@ class ASR1006(BASECISCO): """The device model belongs to the cisco series so the attributes and methods of BASECISCO are inherited. """ - def addUser(self, username, password): - # Overriding methods - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def changePassword(self, username, password): - # Overriding methods - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') + pass diff --git a/lib/forward/devclass/baseBaer.py b/lib/forward/devclass/baseBaer.py index 8e477f0..4bf26a0 100644 --- a/lib/forward/devclass/baseBaer.py +++ b/lib/forward/devclass/baseBaer.py @@ -1,437 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Baer. +Author: zhangqichuan """ from forward.devclass.baseSSHV2 import BASESSHV2 -import re class BASEBAER(BASESSHV2): """This is a manufacturer of baer, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("admin save", - prompt={"success": "Completed[\s\S]+[\r\n]+\S+# ?$"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - else: - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def privilegeMode(self): - # Switch to privilege mode. - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - """ - *A:XXX-XXC-X-XXX-1# configure - *A:XXX-XXX-X-XXX-1>config# service - *A:XXX-XX-X-XXXXX-1>config>service# - """ - result = self.command("exit all", prompt={"success": "[\r\n]+\S+# ?$"}) - if result["state"] == "success": - if re.search("[\r\n]+\S+.+>config>[a-z>]+# ?$", result["content"]): - njInfo["errLog"] = "Switch to privilegeMode is faild. current located config mode." - else: - self.mode == 2 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def configMode(self): - # Switch to config mode. - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command("config", prompt={"success": "[\r\n]+\S+>config# ?$"}) - if result["state"] == "success": - self.mode == 3 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - # Switch to config mode. - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - result = self.command("show version", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - # TiMOS-C-10.0.R12 cpm/hops ALCATEL SR 7750 Copyright (c) 2000-2013 Alcatel-Lucent. --> TiMOS-C-10.0.R12 - tmp = re.search("(TiMOS\S+)", result["content"]) - if tmp: - njInfo["content"] = tmp.group(1) - else: - njInfo["errLog"] = "Version information was not available." - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - # Switch to config mode. - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - result = self.command("show router route-table", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - """ - Dest Prefix[Flags] Type Proto Age Pref - Next Hop[Interface Name] Metric - ------------------------------------------------------------------------------- - 0.0.0.0/0 Remote OSPF(10) 28d14h34m 190 - 10.32.2.2 102 - 0.0.0.0/0 Remote OSPF(10) 28d14h34m 190 - 10.32.2.6 102 - 10.32.0.1/32 Remote OSPF(10) 0484d16h 10 - 10.32.2.2 2 - 10.32.0.1/32 Remote OSPF(10) 0484d16h 10 - 10.32.2.6 2 - 10.32.0.2/32 Remote OSPF(10) 0484d16h 10 - 10.32.2.2 2 - """ - if result["state"] == "success": - allLine = result["content"].split("\r\n") - i = 0 - for line in allLine: - lineInfo = {"net": "", - "mask": "", - "metric": "", - "description": "", - "type": "", - "interface": "", - "via": ""} - tmp = re.search("(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(\d{1,2})\s+\S+\s+([A-Za-z]+)", line) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["type"] = tmp.group(3) - # Get via and metric of routing from next line. - tmp = re.search("([\s\S]+)(\d+)", allLine[i + 1]) - if tmp: - lineInfo["via"] = tmp.group(1).split()[0].strip("()") - lineInfo["metric"] = tmp.group(2) - njInfo["content"].append(lineInfo) - else: - continue - i += 1 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show port detail" - result = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - reg = "Description :[\s\S]+?========================================" - allLine = re.findall(reg, result["content"]) - for _interfaceInfo in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "mac": "", - "ip": ""} - # Get name of the interface - tmp = re.search("Interface : (\S+)", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1) - else: - continue - # Get description of the interface. - tmp = re.search("Description : (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp .group(1).strip() - # Get speed of the interface. - tmp = re.search("Oper Speed : (.*)", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1).strip() - # Get adminState of the interface. - tmp = re.search("Admin State : ([a-zA-Z]+)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1) - # Get duplex of the interface. - tmp = re.search("Oper Duplex : ([a-zA-Z]+)", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Get state of the interface. - tmp = re.search("Oper State : ([a-zA-Z]+)", _interfaceInfo) - if tmp: - lineInfo["interfaceState"] = tmp.group(1) - # Get mtu of the interface. - tmp = re.search("MTU : (\d+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # Get Egress of the interface. - tmp = re.search("Egress Rate : (\S+)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1) - # Get Igress of the interface. - tmp = re.search("Ingress Rate : (\S+)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1) - # Get mac of the interface. - tmp = re.search("Hardware Address : (.*)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - # Get type of interface. - result = self.command("show port", prompt={"success": "[\r\n]+\S+.+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - i = 0 - """ - 5/2/nat-in-ip Up Yes Up - accs qinq vport - 5/2/nat-out-ip - Up Yes Up - accs qinq vport <----convert to a row - 5/2/nat-in-l2 Up Yes Up - netw dotq vport - """ - # Convert to a row. - content = re.sub("\r\n\s+\S+$", " ", result["content"]) - for line in njInfo["content"]: - # Match interfaceName from njInfo["content"] - interfaceName = line["interfaceName"] - tmp = re.search("%s.*" % interfaceName, content) - """ - Port Admin Link Port Cfg Oper LAG/ Port Port Port C/QS/S/XFP/ - Id State State MTU MTU Bndl Mode Encp Type MDIMDX - 4/1/1 Up Yes Up 9192 9192 22 netw null xlgige 40GBASE-SR4 - 4/1/1 Up Yes Up 9192 9192 22 netw null xlgige - 4/1/1 Up Yes Up 22 netw null xlgige - """ - if tmp: - # Get type of interface. - key = tmp.group().split() - # Port type in the penultimate first or second field - if len(key) == 11: - njInfo["content"][i]["type"] = key[9] - else: - njInfo["content"][i]["type"] = key[-1] - i += 1 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Switch to config mode. - njInfo = { - "status": False, - "content": [{"ip": "", - "port": ""}], - "errLog": "" - } - result = self.command("show log snmp-trap-group", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - tmp = re.findall("\d+\.\d+\.\d+\.\d+:\d+", result["content"]) - """ - 90 192.168.1.1:162 - 90 192.168.1.2:16222 - """ - if tmp.__len__() > 0: - njInfo["content"] = [{"ip": group.split(":")[0], "port": group.split(":")[-1]} for group in tmp] - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - result = self.command("show log syslog", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - tmp = re.findall("[\r\n]+\d+\s+(\d+\.\d+\.\d+\.\d+)\s+\d+", result["content"]) - """ - 1 10.0.0.1 514 warning - """ - if tmp.__len__() > 0: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - # Switch to config mode. - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - result = self.command("show system ntp", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - tmp = re.findall("\d+\.\d+\.\d+\.\d+", result["content"]) - """ - Clock Source : 10.0.0.1 - """ - if tmp.__len__() > 0: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - # Get list of vlans. - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - result = self.command("show service sap-using", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Bad command[\s\S]+"}) - if result["state"] == "success": - for line in result["content"].split("\r\n"): - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": ""} - tmp = re.search("^(\S+):(\d+)\s+\S+\s+(\S+)\s+\S+\s+(.*)", line) - """ - lag-24 100 Up Up (Not Specified) - lag-31:221 1000 Up Up (Not Specified) - 1/2/6 1001 Up Up (Not Specified) - lag-31:9 2000 Up Up (Not Specified) - """ - if tmp: - lineInfo["interface"] = [tmp.group(1)] - lineInfo["id"] = tmp.group(2) - lineInfo["status"] = tmp.group(3) - # Remove the '(' and ')' - lineInfo["description"] = tmp.group(4).strip("()") - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show uptime"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" up ?time:? .+(day|year|week).*", result["content"], flags=re.IGNORECASE) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "admin display-config" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseBrocade.py b/lib/forward/devclass/baseBrocade.py index f6647f9..f9fdab2 100644 --- a/lib/forward/devclass/baseBrocade.py +++ b/lib/forward/devclass/baseBrocade.py @@ -1,452 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Brocade. +Author: Cheung Kei-chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -from forward.utils.paraCheck import mask_to_int -import re class BASEBROCADE(BASESSHV2): """This is a manufacturer of brocade, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write memory sync", - prompt={"success": "startup-config done[\s\S]+[\r\n]+\S+# ?$", - "error": "need to configure config-sync peer before issuing this command[\S\s]+"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - elif data["state"] == "success": - result["content"] = "The configuration was saved successfully." - result["status"] = True - else: - result["content"] = "You cannot save the configuration on a slave device." - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def configMode(self): - # Switch to config mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[vV]ersion[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("[vV]ersion (\S+)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.split("PORT-VLAN", result["content"]) - for _vlanInfo in allLine: - _vlanInfo = _vlanInfo.strip() - # Get the line of vlan. - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": ""} - # Get id of the vlan. - tmp = re.search("^\d+", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group() - njInfo["content"].append(lineInfo) - else: - continue - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Get SNMP informatinos. - njInfo = { - "status": False, - # [{"ip:"10.1.1.1","port":"456"}] - "content": [], - "errLog": "" - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command("show running-config | include snmp", prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host (\d+\.\d+\.\d+\.\d+).*?port (\d+)", - result["content"], flags=re.DOTALL) - """ - snmp-server host ip1 version 2c xxx udp-port 612 notify-ty - snmp-server host ip2 version 2c xxx udp-port 621 notify-ty - """ - if tmp.__len__() > 0: - njInfo["content"] = [{"ip": group[0], "port": group[-1]} for group in tmp] - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show run ntp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp.*?([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - # Get server address of syslog. - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show running-config | include logging''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - # Gets the row containing the word logging + IP - validLine = re.search("logging[\s\S]+?[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", result["content"]) - if validLine: - # Get the ip of snmp. - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", validLine) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+\ -([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+\ -([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+\ -(\S+)\s+\ -\S+\s+\ -(\S+)", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = mask_to_int(tmp.group(2)) - lineInfo["via"] = tmp.group(3) - lineInfo["interface"] = tmp.group(4) - lineInfo["type"] = tmp.group(5) - if lineInfo["type"] == "B": - lineInfo["type"] = "bgp" - elif lineInfo["type"] == "Be": - lineInfo["type"] = "ebgp" - elif lineInfo["type"] == "Bi": - lineInfo["type"] = "ibgp" - elif lineInfo["type"] == "D": - lineInfo["type"] = "Connected" - elif lineInfo["type"] == "R": - lineInfo["type"] = "rip" - elif lineInfo["type"] == "S": - lineInfo["type"] = "static" - elif lineInfo["type"] == "O": - lineInfo["type"] = "ospf" - elif lineInfo["type"] == "Oi": - lineInfo["type"] = "ospf inter area" - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall("Port[\s\S]+?DMA.*", result["content"]) - for _interfaceInfo in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - tmp = re.search("^Port\s+(\S+)", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1) - else: - continue - # Get line state of the interface. - tmp = re.search("line protocol is (\S+)", _interfaceInfo) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip(",") - # Get adminState of the interface. - tmp = re.search("link keepalive is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search("MAC address is (\S+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get speed of the interface - tmp = re.search("speed \S+, actual (\S+),", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # Get the duplex of the interface. - tmp = re.search("duplex \S+, actual (\S+)", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1).strip() - # Get type of the interface. - tmp = re.search("port state is (\S+)", _interfaceInfo) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - # Get mtu of the interface. - tmp = re.search("MTU (\d+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # Get input rate of the interface. - tmp = re.search("300 second input rate: (.*sec)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1) - - # Get output rate of the interface. - tmp = re.search("300 second output rate: (.*sec)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" [Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseCisco.py b/lib/forward/devclass/baseCisco.py index fc0f7e9..83582c1 100644 --- a/lib/forward/devclass/baseCisco.py +++ b/lib/forward/devclass/baseCisco.py @@ -1,913 +1,21 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- # +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Base device class for cisco basic device method, by using paramiko module. +Author: Cheung Kei-Chuen, Wangzhe """ import re from forward.devclass.baseSSHV2 import BASESSHV2 from forward.utils.forwardError import ForwardError -from forward.utils.paraCheck import checkIP class BASECISCO(BASESSHV2): """This is a manufacturer of cisco, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("copy running-config startup-config", - prompt={"success": "Copy complete[\s\S]+[\r\n]+\S+# ?$"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - else: - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def configMode(self): - # Switch to config mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*|Access denied.*|Bad secrets.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show run ntp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show running-config | i log''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("loggin server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | i "snmp-server host"''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[vV]ersion[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("(software|system).*version(.*)", result["content"], flags=re.IGNORECASE) - if tmp.lastindex == 2: - njInfo["content"] = tmp.group(2).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - """ - 2206 VLAN2206 active Po12, Po13, Eth1/3, Eth1/2/1 - Eth1/2/2, Eth1/2/3, Eth1/2/4 - 2207 VLAN2207 active Po12, Po13, Eth1/3, Eth1/2/1 - Eth1/2/2, Eth1/2/3, Eth1/2/4 - - LAN Type Vlan-mode - ---- ----- ---------- - 1 enet CE - """ - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - currentSection = "vlanName" - isContinueLine = False - for _interfaceInfo in result["content"].split("\r\n"): - if re.search("\-\-\-\-", _interfaceInfo): - continue - if re.search("^[0-9]", _interfaceInfo) and currentSection == "vlanName": - isContinueLine = True - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - tmp = re.search("([0-9]+)\s+(\S+)\s+([a-z]+)\s+(.*)", _interfaceInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["description"] = tmp.group(2) - lineInfo["status"] = tmp.group(3) - if tmp.lastindex == 4: - lineInfo["interface"] = tmp.group(4).split(", ") - njInfo["content"].append(lineInfo) - continue - elif isContinueLine is True and not re.search("VLAN Type", - _interfaceInfo) and currentSection == "vlanName": - for _interface in _interfaceInfo.split(","): - - lineInfo = njInfo["content"].pop() - lineInfo["interface"].append(_interface.strip()) - njInfo["content"].append(lineInfo) - continue - else: - isContinueLine = False - if re.search("VLAN Type", _interfaceInfo): - currentSection = "vlanType" - continue - if currentSection == "vlanType": - if re.search("^[0-9]", _interfaceInfo): - tmp = re.search("([0-9]+) ([a-z]+)", _interfaceInfo) - if tmp: - vlanID = tmp.group(1) - vlanType = tmp.group(2) - i = 0 - for _vlan in njInfo["content"]: - if vlanID == _vlan["id"]: - njInfo["content"][i]["type"] = vlanType - i += 1 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show routing" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - # record the route table. - if re.search("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]{1,2}", _interfaceInfo): - '''try: - """Store the previously acquired routing information - before processing the new routing information""" - njInfo["content"].append(lineInfo) - except Exception: - pass''' - lineInfo = { - "net": "", - "mask": "", - "via": "", - "metric": "", - "type": "", - "via": "", - } - # Get net of the route. - lineInfo["net"] = _interfaceInfo.split("/")[0] - # Get mask of net of the route. - lineInfo["mask"] = _interfaceInfo.split("/")[1].split(",")[0] - njInfo["content"].append(lineInfo) - elif re.search("\*via [0-9]", _interfaceInfo): - lineInfo = njInfo["content"].pop() - lineInfo["via"] = re.search("\*via (.*?),", _interfaceInfo).group(1) - lineInfo["interface"] = _interfaceInfo.split(",")[1].strip() - lineInfo["type"] = _interfaceInfo.split()[-1] - njInfo["content"].append(lineInfo) - # save the last record. - try: - njInfo["content"].append(lineInfo) - except Exception: - pass - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in result["content"].split("\r\n\r\n"): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - if i == 0: - _interfaceInfo = _interfaceInfo.split("\r\r\n")[1] - tmp = re.search("(.*) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - continue - else: - tmp = re.search("(.*?) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search(", address: ([\S]+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def addUser(self, username, password): - """Increating a user on the device. - """ - result = { - "status": False, - "content": "", - "errLog": "" - } - # Assembling command - cmd = "username {username} password {password}".format(username=username, password=password) - - # Switch to privilege mode. - switch = self.privilegeMode() - if not switch["status"]: - # Switch failure. - return switch - # Switch to configure-mode. - switch = self.configMode() - if not switch["status"]: - # Switch failed. - return switch - # Run a command - data = self.command(cmd, prompt={"success": self.basePrompt}) - # Check status - if re.search("% Invalid|ERROR:", data["content"]): - result["errLog"] = "%s" % data["content"] - return result - if data["state"] == "success": - result = self.commit() - return result - else: - result["errLog"] = "%s" % data["content"] - return result - - def deleteUser(self, username): - """remove a user on the device. - """ - result = { - "status": False, - "content": "", - "errLog": "" - } - # Assembling command - cmd = "no username {username} ".format(username=username) - # Switch to privilege mode. - switch = self.privilegeMode() - if not switch["status"]: - # Switch failure. - return switch - # Switch to configure-mode. - switch = self.configMode() - if not switch["status"]: - # Switch failed. - return switch - # Run a command - data = self.command(cmd, prompt={"success": self.basePrompt}) - # Check status - if re.search("% Invalid|ERROR:", data["content"]): - result["errLog"] = "%s" % data["content"] - return result - if data["state"] == "success": - result = self.commit() - return result - else: - result["errLog"] = "%s" % data["content"] - return result - - def changePassword(self, username, password): - return self.addUser(username, password) - - def getUserList(self, username=None): - """Get all user from the device. - resunt format: - { - "username-1":{"username":"username-1","level" :15}, - "username-2":{"username":"username-2","level" :14} - } - """ - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Assembling command - if username is None or re.search("^ *$", username): - cmd = "show running-config | include username" - else: - cmd = "show running-config | include username {username}".format(username=username) - # Switch to privilege mode. - switch = self.privilegeMode() - if not switch["status"]: - # Switch failure. - return switch - # Run a command - data = self.command(cmd, prompt={"success": self.basePrompt}) - # Check status - if re.search("% Invalid|ERROR:", data["content"]): - result["errLog"] = "%s" % data["content"] - return result - if data["state"] is None: - # The command was not executed correctly - result["errLog"] = "%s" % data["content"] - return result - # Seasrch user - tmp = re.findall("username.*", data["content"]) - for _line in tmp: - line = _line.split() - try: - _username = line[1] - except IndexError: - continue - result["content"][_username] = {"username": _username, "level": 0} - result["status"] = True - return result - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, name=None): - """ - @param vlan_id: vlan-id, - @param name: name of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - if name is None: - # no name. - cmd = "vlan {vlan_id}".format(vlan_id=vlan_id) - else: - cmd = "vlan {vlan_id}\rname {name}".format(vlan_id=vlan_id, name=name) - prompt = { - "success": "[\r\n]+\S+config\-vlan\)(#|>) ?$", - "error": "[\r\n]+(Invalid|Error)[\s\S]+", - } - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success" and not re.search(prompt["error"], tmp["content"]): - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - self.deleteVlan(vlan_id) - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Delete vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "no vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.vlanExist(vlan_id)["status"]: - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def interfaceVlanExist(self, vlan_id): - # parameter vlan_id: Vlan123 - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameter - vlan_id = str(vlan_id).strip() - if re.search("^[0-9]+$", vlan_id): - vlan_id = "Vlan" + vlan_id - for line in self.showInterface()["content"]: - if vlan_id == line["interfaceName"]: - result["status"] = True - return result - result["errLog"] = "The interface-vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def deleteInterfaceVlan(self, vlan_id): - # Deleting virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "no interface vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.interfaceVlanExist(vlan_id)["status"]: - # The interface-vlan was deleted successfuly. - result["content"] = "The interface-vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The interface-vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def createInterfaceVlan(self, vlan_id, ip=None, mask=None, description="None"): - # Creating virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameters. - if ip is None or mask is None: - result["errLog"] = "parameter of ip and mask can not be None." - return result - elif checkIP(ip) is False: - result["errLog"] = "Illegal IP address." - return result - elif checkIP(mask) is False: - result["errLog"] = "Illegal net mask." - return result - cmd1 = "interface vlan {vlan_id}".format(vlan_id=vlan_id) - cmd2 = "description {description}".format(description=description) - cmd3 = "ip address {ip} {mask}".format(ip=ip, mask=mask) - # Forward need to check if The vlan exists,before creating. - if not self.vlanExist(vlan_id)["status"]: - # no exists. - result["errLog"] = "The vlan({vlan_id}) does not exists,\ -thus can't create interface-vlan.".format(vlan_id=vlan_id) - return result - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - prompt1 = { - "success": "[\r\n]+\S+config\-if\)# ?$", - "error": "[\r\n]+\S+config\)# ?$", - # "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt2 = { - "success": "{cmd2}[\r\n]+\S+config\-if\)# ?$".format(cmd2=cmd2), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt3 = { - "success": "{cmd3}[\r\n]+\S+config\-if\)# ?$".format(cmd3=cmd3), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - # Running cmd1. - tmp = self.command(cmd1, prompt=prompt1) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd2 - tmp = self.command(cmd2, prompt=prompt2) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd3 - tmp = self.command(cmd3, prompt=prompt3) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Checking... - if self.interfaceVlanExist(vlan_id)["status"]: - result["content"] = "The configuration was created by Forwarder." - result["status"] = True - else: - # The configuration was not created and rolled back. - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = "The configuration was not created and rolled back" - return result - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - # Find uptime of the devices. - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" [Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - pass - # Find information of firewall-connection. - result = self.command(cmd="show conn", prompt=prompt) - if result["state"] == "success": - dataLine = re.search("([0-9]+) in use", result["content"]) - if dataLine is not None: - njInfo["content"]["firewallConnection"]["status"] = True - njInfo["content"]["firewallConnection"]["content"] = dataLine.group() - else: - pass - else: - # That forwarder execute the command is failed. - pass - - else: - return tmp - return njInfo - - def showOSPF(self, cmd="show ip ospf neighbors"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return njInfo - result = self.command(cmd, prompt) - dataLine = re.findall("[0-9]{1,3}.*", result["content"]) - if len(dataLine) == 0: - return njInfo - for line in dataLine: - line = line.split() - if len(line) == 7: - njInfo["content"].append({ - "neighbor-id": line[0], - "pri": line[1], - "state": line[2] + line[3], - "uptime": line[4], - "address": line[5], - "interface": line[6], - "deadTime": ""} - ) - else: - # The line does not matched data of expection. - continue - return njInfo - - def showVRRP(self, cmd="show hsrp brief"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - for line in result["content"].split("\r\n"): - dataLine = line.split() - try: - njInfo["content"].append({ - "vr-state": "", - "vr-mode": "", - "timer": "", - "type": "", - "interface": dataLine[0], - "group": dataLine[1], - "prio": dataLine[2], - "p": dataLine[3], - "state": dataLine[4], - "active": dataLine[5], - "standby-addr": dataLine[6], - "group-addr": dataLine[7], - "address": dataLine[8]} - ) - except Exception: - pass - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseDepp.py b/lib/forward/devclass/baseDepp.py index c54b665..4a1b301 100644 --- a/lib/forward/devclass/baseDepp.py +++ b/lib/forward/devclass/baseDepp.py @@ -1,1351 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Depp. +Author: Cheung Kei-chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -import re -import os class BASEDEPP(BASESSHV2): """This is a manufacturer of depp, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def showNtp(self): - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - cmd = "show running-config | include ntp" - prompt = { - # Problems caused by special characters cannot be added with host prompt - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - # Gets the row with NTP configuration information. - tmp = re.findall("ntp client master-slave-server.*", result["content"]) - # ntp client master-slave-server ip1 ip2 ip3 - if tmp: - # Separate IP addresses - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", tmp.group()) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - # Firewall has no syslog configuration - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - njInfo["status"] = True - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show run | include target-host" - prompt = { - # Problems caused by special characters cannot be added with host prompt - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("target-host address ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - # Get software version of device. - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "Software Release[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Software Release (.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - # Get software version of device. - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("The VLANs include:[\r\n]+.*\d+[\r\n]", result["content"]) - allVlan = [] - if tmp: - data = tmp.group() - _vlan = re.findall("(\d+\-?\d*)", data) - # ["1","2003-2009","2333",.....] - for vlanGroup in _vlan: - # Converts a value to a numberic type - line = [int(x) for x in vlanGroup.split("-")] - if len(line) == 1: - # [1] --> [1,2] - line.append(line[0] + 1) - else: - line[-1] += 1 - # --> [1,2003,2004,2005......] - allVlan.extend(range(*line)) - # Get more info. - for vlanId in allVlan: - result = self.command("show vlan {vlanId}".format(vlanId=vlanId), prompt=prompt) - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": ""} - if result["state"] == "success": - lineInfo["id"] = vlanId - # Get type of vlan. - tmp = re.search("VLAN Type: (\S+)", result["content"]) - if tmp: - lineInfo["type"] = tmp.group(1) - # Get description of vlan. - tmp = re.search("Description:(.*)", result["content"]) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - if re.search("\S?>\* [0-9]", _interfaceInfo): - tmp = re.search(">\* ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - via = re.search("via ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", _interfaceInfo) - if via: - lineInfo["via"] = via.group(1) - # Match the route table - tmp = re.search("([A-Z])>\*", _interfaceInfo) - if tmp: - _type = tmp.group(1) - if _type == "C": - _type = "connected" - elif _type == "S": - _type = "static" - elif _type == "R": - _type = "rip" - elif _type == "O": - _type = "ospf" - elif _type == "K": - _type = "kernel" - elif _type == "I": - _type = "isis" - elif _type == "B": - _type = "bgp" - elif _type == "G": - _type == "guard" - elif _type == "*": - _type = "fib" - else: - _type == "select" - lineInfo["type"] = _type - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("[\r\n]{0,}Interface", result["content"])[1::] - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface. - lineInfo['interfaceName'] = _interfaceInfo.split("\r")[0].strip(" ") - # Get admin state of the interface and remove extra character. - lineInfo['adminState'] = re.search("administration state is (.*),", _interfaceInfo).group(1) - # Get state of line protocol of the interface and remove extra character. - lineInfo['lineState'] = re.search("line.*is (.*)", _interfaceInfo).group(1).strip() - # Get description of the interface. - tmp = re.search("Description:(.*)", _interfaceInfo) - if tmp: - lineInfo['description'] = re.search("Description:(.*)", _interfaceInfo).group(1).strip() - # Get MUT of the interface. - tmp = re.search("MTU : ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - else: - lineInfo["mtu"] = "" - # Get duplex of the interface. - tmp = re.search("([a-z]+)\-duplex mode", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - else: - lineInfo["duplex"] = "" - # Get ip of the interface. - tmp = re.search("ipv4 address primary: (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - else: - lineInfo["ip"] = "" - # Get mac of the interface. - tmp = re.search("Hardware address is (.*)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - else: - lineInfo["mac"] = "" - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def getMore(self, bufferData): - """Automatically get more echo infos by sending a blank symbol - """ - # if check buffer data has 'more' flag, at last line. - # if re.search(self.moreFlag, bufferData.split('\n')[-1]): - # can't used to \n and ' \r' ,because produce extra enter character - if re.search(self.moreFlag, bufferData.split('\n')[-1]): - self.shell.send(' ') - - def updateIPObject(self, name, oldName, ip=None, vsysName="PublicSystem", - applyTime=None): - # load module of suds. - from suds.client import Client - # create a ip or ip-range - """ - parameter oldName : str type, originally name - parameter name : str type, any - parameter ip : str type, ip address, such as 10.0.0.1 or 10.0.0.100-10.0.0.200 - parameter url : str type, webservice URL - parameter username: str type, device's username,for authentiction - parameter password: str typedevice's password,for authentication - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - url = "http://" + self.ip + "/func/web_main/wsdl/netaddr/netaddr.wsdl" - # parameters check - if re.search("\/", ip): - # for 10.0.0.1/32 - ip = "{ip}/32".format(ip.split("/")[0]) - elif re.search("\-", ip): - # The other one is 10.0.0.100-10.0.200,remove mask - ip = re.sub("\/[0-9]+", "", ip) - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - try: - client.service.modAddrObj(**{"oldname": oldName, "name": name, "ip": ip}) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def deleteIPObject(self, name, vsysName="PublicSystem"): - # load module of suds. - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/netaddr/netaddr.wsdl" - # delete ip object - """ - parameter name : str type, any - parameter ip : str type, ip address, such as 10.0.0.1 or 10.0.0.100-10.0.0.200 - parameter url : str type, webservice URL - parameter username: str type, device's username,for authentiction - parameter password: str typedevice's password,for authentication - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - try: - client.service.delAddrObj(name=name) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def createIPObject(self, name, ip=None, vsysName="PublicSystem", - applyTime=None): - # load module of suds. - from suds.client import Client - # create a ip or ip-range - """ - parameter name : str type, any - parameter ip : str type, ip address, such as 10.0.0.1 or 10.0.0.100-10.0.0.200 - parameter url : str type, webservice URL - parameter username: str type, device's username,for authentiction - parameter password: str typedevice's password,for authentication - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - url = "http://" + self.ip + "/func/web_main/wsdl/netaddr/netaddr.wsdl" - # parameters check - if re.search("\/", ip): - # for 10.0.0.1/32 - ip = "{ip}/32".format(ip.split("/")[0]) - elif re.search("\-", ip): - # The other one is 10.0.0.100-10.0.200,remove mask - ip = re.sub("\/[0-9]+", "", ip) - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - try: - client.service.addAddrObj(**{"name": name, "ip": ip}) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def updateServiceObject(self, name, protocol=None, sRange=None, - dRange=None, vsysName="PublicSystem", applyTime=None): - # load module of suds. - from suds.client import Client - """ - create a service object - parameter name: str type, any - parameter url : str type, webservice url - parameter protocol : str type, tcp,udp or icmp - parameter sRange : str type, such as 90-91 - parameter dRange : str type, suce as 100-101 - parameter vsysName : str type, default is PublicSystem - parameter username : str type, device's username - parameter password : str type, device's password - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - url = "http://" + self.ip + "/func/web_main/wsdl/netservice/netservice.wsdl" - # parameters check. - if protocol is None or sRange is None or dRange is None: - raise IOError("Specify url,protocol,url,sRange and dRange parameters.") - # Protocol code conversion - if re.search("tcp", protocol, re.IGNORECASE): - protocolNumber = 6 - elif re.search("udp", protocol, re.IGNORECASE): - protocolNumber = 17 - elif re.search("icmp", protocol, re.IGNORECASE): - protocolNumber = 1 - else: - result["errLog"] = "Unkow protocol" - return result - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - p = {"name": name, - "protocol": protocolNumber, - "sourcePortRange": sRange, - "destinationPortRange": dRange, - "vsysName": vsysName} - try: - client.service.updateServerObject(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def deleteServiceObject(self, name, protocol=None, sRange=None, - dRange=None, vsysName="PublicSystem"): - # load module of suds. - from suds.client import Client - """ - delete a service object - parameter name: str type, any - parameter url : str type, webservice url - parameter protocol : str type, tcp,udp or icmp - parameter sRange : str type, such as 90-91 - parameter dRange : str type, suce as 100-101 - parameter vsysName : str type, default is PublicSystem - parameter username : str type, device's username - parameter password : str type, device's password - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - url = "http://" + self.ip + "/func/web_main/wsdl/netservice/netservice.wsdl" - # parameters check. - if protocol is None or sRange is None or dRange is None: - raise IOError("Specify url,protocol,url,sRange and dRange parameters.") - # Protocol code conversion - if re.search("tcp", protocol, re.IGNORECASE): - protocolNumber = 6 - elif re.search("udp", protocol, re.IGNORECASE): - protocolNumber = 17 - elif re.search("icmp", protocol, re.IGNORECASE): - protocolNumber = 1 - else: - result["errLog"] = "Unkow protocol" - return result - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - p = {"name": name, - "protocol": protocolNumber, - "sourcePortRange": sRange, - "destinationPortRange": dRange, - "vsysName": vsysName} - try: - client.service.deleteServerObject(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def createServiceObject(self, name, protocol=None, sRange=None, - dRange=None, vsysName="PublicSystem", - applyTime=None, **kws): - # load module of suds. - from suds.client import Client - """ - create a service object - parameter name: str type, any - parameter url : str type, webservice url - parameter protocol : str type, tcp,udp or icmp - parameter sRange : str type, such as 90-91 - parameter dRange : str type, suce as 100-101 - parameter vsysName : str type, default is PublicSystem - parameter username : str type, device's username - parameter password : str type, device's password - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - url = "http://" + self.ip + "/func/web_main/wsdl/netservice/netservice.wsdl" - # parameters check. - if protocol is None or sRange is None or dRange is None: - raise IOError("Specify url,protocol,url,sRange and dRange parameters.") - # Protocol code conversion - if re.search("tcp", protocol, re.IGNORECASE): - protocolNumber = 6 - elif re.search("udp", protocol, re.IGNORECASE): - protocolNumber = 17 - elif re.search("icmp", protocol, re.IGNORECASE): - protocolNumber = 1 - else: - result["errLog"] = "Unkow protocol" - return result - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - p = {"name": name, - "protocol": protocolNumber, - "sourcePortRange": sRange, - "destinationPortRange": dRange, - "vsysName": vsysName} - try: - client.service.createServerObject(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def updateStaticNAT(self, name, interface=None, globalAddress=None, localAddress=None, enable="true", - vsysName="PublicSystem", applyTime=None): - # notice: the parameter enable must be as string type. - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - if localAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the localAddress" - if globalAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the globalAddress" - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "globalAddress": globalAddress, - "enable": enable, - "localAddress": localAddress} - try: - client.service.updateStaticNat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def deleteStaticNAT(self, name, interface=None, globalAddress=None, localAddress=None, enable="true", - vsysName="PublicSystem"): - # notice: the parameter enable must be as string type. - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - if localAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the localAddress" - if globalAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the globalAddress" - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "globalAddress": globalAddress, - "enable": enable, - "localAddress": localAddress} - try: - client.service.deleteStaticNat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def createStaticNAT(self, name, interface=None, globalAddress=None, localAddress=None, enable="true", - vsysName="PublicSystem", applyTime=None): - # notice: the parameter enable must be as string type. - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - if localAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the localAddress" - if globalAddress is None: - result["errLog"] = "[Forward Error] Please specify the value of the globalAddress" - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "globalAddress": globalAddress, - "enable": enable, - "localAddress": localAddress} - try: - client.service.createStaticNat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def updateDNAT(self, name, interface=None, globalAddress="", localAddress=None, enable=True, - vsysName="PublicSystem", applyTime=None): - return self.createDNAT(name, interface=interface, globalAddress=globalAddress, localAddress=localAddress, - enable=enable, vsysName=vsysName, - applyTime=applyTime) - - def deleteDNAT(self, name, interface=None, globalAddress="", localAddress=None, enable=True, - vsysName="PublicSystem"): - result = { - 'status': False, - 'content': '', - 'errLog': ''} - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - if not re.search("\-", localAddress): - result["errLog"] = "[Forward Error] Please specify the value of the localAddress as a address range." - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "globalAddress": globalAddress, - "enable": enable, - "localAddress": localAddress} - try: - client.service.deleteDnat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def createDNAT(self, name, interface=None, globalAddress="", localAddress=None, enable=True, - vsysName="SPublicystem", applyTime=None): - result = { - 'status': False, - 'content': '', - 'errLog': ''} - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - if not re.search("\-", localAddress): - result["errLog"] = "[Forward Error] Please specify the value of the localAddress as a address range." - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "globalAddress": globalAddress, - "enable": enable, - "localAddress": localAddress} - try: - client.service.createDnat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def updateSNAT(self, name, interface=None, addressPool="", enable=True, vsysName="PublicSystem", - applyTime=None): - return self.createSNAT(name, interface=interface, addressPool=addressPool, enable=enable, - vsysName=vsysName, applyTime=applyTime) - - def deleteSNAT(self, name, interface=None, addressPool="", enable=True, vsysName="PublicSystem", - username=None, password=None): - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "addressPool": addressPool, - "enable": enable} - try: - client.service.deleteSnat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error." - return result - - def createSNAT(self, - name, - interface="", - addressPool="", - sourceIP={"type": "0", - "name": "XXXXXXX-10.0.0.1"}, - destinationIP={"type": 0, - "name": ""}, - service={"type": 0, - "name": "ECHO-reply"}, - enable=True, - vsysName="PublicSystem", - applyTime=None): - """ - @param name(str): The name of SNAT. - @param interface(str): The name of export interface,eg:"vlan1,vlan2,vlan3",maxomum is 16 - @param addressPool(str): The address pool,eg: "" for using export-address - or "#" for using None-NAT or "192.168.1.1,192.168.1.2,..1.7" ,maximum is 7 - """ - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/nat/NatManager.wsdl" - if interface is None: - result["errLog"] = "[Forward Error] Please specify the value of the interface." - return result - try: - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = {"vsysName": vsysName, - "name": name, - "interface": interface, - "addressPool": addressPool, - "sourceIpObjects": sourceIP, - "destinationIpObjects": destinationIP, - "serverObjects": service, - "enable": enable} - try: - client.service.createSnat(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,the configuration-name already exist,or vsysName not exist" - else: - result["errLog"] = "Unknow error[%s]." % str(e) - return result - - def updateSecurityPolicy(self, name, action=None, - sZone=None, dZone=None, - sIPType=None, sIPName=None, - dIPType=None, dIPName=None, - serviceType=None, serviceName=None, - vsysName="PublicSystem", - applyTime=None): - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/pf_policy/pf_policy/pf_policy.wsdl" - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - # default parameters - # default sort 1 - position = 1 - # default should be true - enabled = "true" - """ - Create security policy - parameter name : str type, any - parameter vsysName : str type, it must exist ,such as PublicSystem - parameter position : int type, sort - parameter enable : str type, true/false - parameter sZone : str type, source security zone,must be exist - parameter dZone : str type, destination security zone,must be exist - parameter action : str type, allow/deny - parameter sIPType : str type, source ip object name, single/group - parameter sIPName : str type, source ip object name ,must be exist - parameter dIPType : str type, destination ip object name, single/group - parameter dIPName : str type, destination ip object name ,must be exist - parameter serviceType : str type, service object,single/group - parameter serviceName : str type, service object name ,must be exist - - """ - # parameters check - if action is None or (not action == "allow" and not action == "deny"): - result["errLog"] = "[Forward Error] Please specify the value of the parameter action as allow/deny." - return result - if sZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the sZone." - return result - if dZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dZone." - return result - if sIPType is None or (not sIPType == "single" and not sIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPType,and value is single/group" - return result - if sIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPName,and value is single/group" - return result - if dIPType is None or (not dIPType == "single" and not dIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the dIPType,and value is single/group" - return result - if dIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dIPName." - return result - if serviceType is None or (not serviceType == "single" and not serviceType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the serviceType,and value is single/group" - return result - if serviceName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the serviceName." - return result - # Parameter transformation - if sIPType == "single": - sIPTypeCode = "0" - else: - sIPTypeCode = "1" - if dIPType == "single": - dIPTypeCode = "0" - else: - dIPTypeCode = "1" - if serviceType == "single": - serviceTypeCode = "0" - else: - serviceTypeCode = "1" - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = { - "name": name, - "vsysName": vsysName, - "position": position, - "enabled": enabled, - "action": action, - "sourceSecurityZone": sZone, - "destinationSecurityZone": dZone, - "sourceIpObjects": [ - { - "type": sIPTypeCode, - "name": sIPName, - } - ], - "destinationIpObjects": [ - { - "type": dIPTypeCode, - "name": dIPName, - } - ], - "serverObjects": [ - { - "type": serviceTypeCode, - "name": serviceName - } - ] - } - try: - client.service.updateSecurityPolicy(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def deleteSecurityPolicy(self, name, action=None, - sZone=None, dZone=None, - sIPType=None, sIPName=None, - dIPType=None, dIPName=None, - serviceType=None, serviceName=None, - vsysName="PublicSystem"): - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/pf_policy/pf_policy/pf_policy.wsdl" - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - # default parameters - # default sort 1 - position = 1 - # default should be true - enabled = "true" - """ - Create security policy - parameter name : str type, any - parameter vsysName : str type, it must exist ,such as PublicSystem - parameter position : int type, sort - parameter enable : str type, true/false - parameter sZone : str type, source security zone,must be exist - parameter dZone : str type, destination security zone,must be exist - parameter action : str type, allow/deny - parameter sIPType : str type, source ip object name, single/group - parameter sIPName : str type, source ip object name ,must be exist - parameter dIPType : str type, destination ip object name, single/group - parameter dIPName : str type, destination ip object name ,must be exist - parameter serviceType : str type, service object,single/group - parameter serviceName : str type, service object name ,must be exist - - """ - # parameters check - if action is None or (not action == "allow" and not action == "deny"): - result["errLog"] = "[Forward Error] Please specify the value of the parameter action as allow/deny." - return result - if sZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the sZone." - return result - if dZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dZone." - return result - if sIPType is None or (not sIPType == "single" and not sIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPType,and value is single/group" - return result - if sIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPName,and value is single/group" - return result - if dIPType is None or (not dIPType == "single" and not dIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the dIPType,and value is single/group" - return result - if dIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dIPName." - return result - if serviceType is None or (not serviceType == "single" and not serviceType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the serviceType,and value is single/group" - return result - if serviceName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the serviceName." - return result - # Parameter transformation - if sIPType == "single": - sIPTypeCode = "0" - else: - sIPTypeCode = "1" - if dIPType == "single": - dIPTypeCode = "0" - else: - dIPTypeCode = "1" - if serviceType == "single": - serviceTypeCode = "0" - else: - serviceTypeCode = "1" - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = { - "name": name, - "vsysName": vsysName, - "position": position, - "enabled": enabled, - "action": action, - "sourceSecurityZone": sZone, - "destinationSecurityZone": dZone, - "sourceIpObjects": [ - { - "type": sIPTypeCode, - "name": sIPName, - } - ], - "destinationIpObjects": [ - { - "type": dIPTypeCode, - "name": dIPName, - } - ], - "serverObjects": [ - { - "type": serviceTypeCode, - "name": serviceName - } - ] - } - try: - client.service.deleteSecurityPolicy(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def createSecurityPolicy(self, name, action=None, - sZone=None, dZone=None, - sIPType=None, sIPName=None, - dIPType=None, dIPName=None, - serviceType=None, serviceName=None, - vsysName="PublicSystem", applyTime=None): - from suds.client import Client - url = "http://" + self.ip + "/func/web_main/wsdl/pf_policy/pf_policy/pf_policy.wsdl" - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - # default parameters - # default sort 1 - position = 1 - # default should be true - enabled = "true" - """ - Create security policy - parameter name : str type, any - parameter vsysName : str type, it must exist ,such as PublicSystem - parameter position : int type, sort - parameter enable : str type, true/false - parameter sZone : str type, source security zone,must be exist - parameter dZone : str type, destination security zone,must be exist - parameter action : str type, allow/deny - parameter sIPType : str type, source ip object name, single/group - parameter sIPName : str type, source ip object name ,must be exist - parameter dIPType : str type, destination ip object name, single/group - parameter dIPName : str type, destination ip object name ,must be exist - parameter serviceType : str type, service object,single/group - parameter serviceName : str type, service object name ,must be exist - - """ - # parameters check - if action is None or (not action == "allow" and not action == "deny"): - result["errLog"] = "[Forward Error] Please specify the value of the parameter action as allow/deny." - return result - if sZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the sZone." - return result - if dZone is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dZone." - return result - if sIPType is None or (not sIPType == "single" and not sIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPType,and value is single/group" - return result - if sIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the sIPName,and value is single/group" - return result - if dIPType is None or (not dIPType == "single" and not dIPType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the dIPType,and value is single/group" - return result - if dIPName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the dIPName." - return result - if serviceType is None or (not serviceType == "single" and not serviceType == "group"): - result["errLog"] = "[Forward Error] Please specify a parameter\ - for the serviceType,and value is single/group" - return result - if serviceName is None: - result["errLog"] = "[Forward Error] Please specify a parameter for the serviceName." - return result - # Parameter transformation - if sIPType == "single": - sIPTypeCode = "0" - else: - sIPTypeCode = "1" - if dIPType == "single": - dIPTypeCode = "0" - else: - dIPTypeCode = "1" - if serviceType == "single": - serviceTypeCode = "0" - else: - serviceTypeCode = "1" - try: - # connect to url - client = Client(url, username=self.username, password=self.password) - except Exception as e: - result["errLog"] = "[Forward Error] Connected to {url} was\ - failure, reason: {err}".format(err=str(e), url=url) - return result - p = { - "name": name, - "vsysName": vsysName, - "position": position, - "enabled": enabled, - "action": action, - "sourceSecurityZone": sZone, - "destinationSecurityZone": dZone, - "sourceIpObjects": [ - { - "type": sIPTypeCode, - "name": sIPName, - } - ], - "destinationIpObjects": [ - { - "type": dIPTypeCode, - "name": dIPName, - } - ], - "serverObjects": [ - { - "type": serviceTypeCode, - "name": serviceName - } - ] - } - try: - client.service.createSecurityPolicy(p) - result["status"] = True - except Exception as e: - num = e.message[0] - if num == 401: - result["errLog"] = "username or password invalid." - elif num == 506: - result["errLog"] = "Specify parameters error,or the configuration-name already exist." - else: - result["errLog"] = "Unknow error." - return result - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "([Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - runningDate = -1 - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" [Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+(#|>|\]) ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseF5.py b/lib/forward/devclass/baseF5.py index 7c23999..d21ddd3 100644 --- a/lib/forward/devclass/baseF5.py +++ b/lib/forward/devclass/baseF5.py @@ -1,328 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for F5. +Author: Cheung Kei-chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -import re class BASEF5(BASESSHV2): """This is a manufacturer of F5, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "tmsh show /sys version" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Version +([0-9\.]+)", result["content"]) - if tmp: - njInfo["content"] = tmp.group(1) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "tmsh list /sys ntp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Get SNMP informatinos. - njInfo = { - "status": False, - # [{"ip:"10.1.1.1","port":"456"}] - "content": [], - "errLog": "" - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - cmd = "tmsh list /sys snmp" - result = self.command(cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("host.*(\d+\.\d+\.\d+\.\d+)\r\n\s+(port \d+)?", - result["content"]) - """ - xxxx_1 { - community xxxx_2015 - host 10.1.1.5 - prot 8888 - } - yyyyy_1 { - community yyyyy_2015 - host 10.1.1.1 - } - """ - for line in tmp: - ip, port = line - port = re.sub("port ", "", port) - njInfo["content"].append({"ip": ip, "port": port}) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - # Get the interface information - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "tmsh list /net interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall("net[\s\S]+?\r\n\}", result["content"]) - for line in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - tmp = re.search("net interface (\S+)", line) - if tmp: - lineInfo["interfaceName"] = tmp.group(1) - # Get mtu of the interface. - tmp = re.search("mtu (\d+)", line) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search("mac-address (.*)", line) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get description of the interface. - tmp = re.search("description (.*)", line) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "tmsh list /sys syslog" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "tmsh list /net route" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - # Get name of routes. - result = self.command(cmd=cmd, prompt=prompt) - """ - net route default_route { - gw 10.1.1.1 - network default - } - """ - if result["state"] == "success": - allLine = re.findall("net[\s\S]+?\r\n\}", result["content"]) - for section in allLine: - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": ""} - # Get via of the routing. - tmp = re.search("gw (\d+\.\d+\.\d+\.\d+)", section) - if tmp: - lineInfo["via"] = tmp.group(1) - else: - continue - # Get destination of the routing. - tmp = re.search("network (.*)", section) - if tmp: - # Intercept the prefix of the destination-network - lineInfo["net"] = re.search("(.*)/?", tmp.group(1)).group(1).strip() - # Intercept the sufix of the destination-network,but may be no sufix. - mask = re.search("/(\d+)", tmp.group(1)) - if mask: - lineInfo["mask"] = mask.group(1) - else: - continue - # Get description of the routing. - tmp = re.search("description(.*)", section) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "tmsh list /net vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "command not found[\s\S]+", - } - # Get name of routes. - result = self.command(cmd=cmd, prompt=prompt) - """ - net route default_route { - gw 10.1.1.1 - network default - } - """ - if result["state"] == "success": - allLine = re.findall("net [\s\S]+?\r\n\}", result["content"]) - for section in allLine: - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": ""} - # Get id of the vlan. - tmp = re.search("tag (\d+)", section) - if tmp: - lineInfo["id"] = tmp.group(1) - # Get interfaes of the vlan. - tmp = re.search("interfaces \{([\s\S]+?)\}", section) - if tmp: - lineInfo["interface"] = re.findall("[A-Za-z0-9\.\-]+", tmp.group(1)) - # Get description of the routing. - tmp = re.search("description(.*)", section) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="uptime"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(command not found|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - runningDate = -1 - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" up .+(day|year|week).*", result["content"], flags=re.IGNORECASE) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - return njInfo + pass diff --git a/lib/forward/devclass/baseFenghuo.py b/lib/forward/devclass/baseFenghuo.py index 0e07cb0..055fbe4 100644 --- a/lib/forward/devclass/baseFenghuo.py +++ b/lib/forward/devclass/baseFenghuo.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see .n """ -----Introduction----- [Core][forward] Device class for Fenghuo. +Author: Cheung Kei-Chuen """ import re from forward.devclass.baseSSHV2 import BASESSHV2 @@ -28,461 +15,4 @@ class BASEFENGHUO(BASESSHV2): """This is a manufacturer of fenghuo, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - # Excute a command. - tmp = self.command("write file", - prompt={"success": "Are you sure\?\(y/n\) \[y\] ?$", - "error": "Unknown command[\s\S]+"}) - if tmp["state"] == "success": - continueCommandResult = self.command("y", prompt={"success": "\[OK\][\s\S]+[\r\n]+\S+# ?$"}) - if continueCommandResult["state"] == "success": - # Successfully. - result["status"] = True - else: - # Failed. - result["errLog"] = "Failed save configuration,\ - relate-information: [{content}]".format(content=continueCommandResult["content"]) - result["status"] = False - elif tmp["state"] == "error": - result["errLog"] = "The command failed to execute.info: [{content}]".format(content=tmp["content"]) - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=tmp["content"], errLog=tmp["errLog"]) - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def configMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - return _result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config", prompt={"success": "[\r\n]+\S+\(config\)# ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config include substring ntp" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("unicast-server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config include substring snmp" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("trap-server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[sS]oftware[\s\S]+[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("software.*version(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config include substring syslog" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("syslog server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan all" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = result["content"].split("\r\n") - i = 0 - for _vlanInfo in allLine: - _vlanInfo = _vlanInfo.strip() - if re.search("^VID", _vlanInfo): - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - # Split the interface-line - for _interface in _vlanInfo.split()[1:]: - # VID ge-1/0/1-ge-1/0/48 xge-1/1/1-xge-1/1/2 xge-1/2/1-xge-1/2/2 - interfaceGroup = re.findall("[a-z]+\-[0-9]+/[0-9]+/[0-9]+", _interface) - interfaceProfix = re.search("([a-z]+\-[0-9]+/[0-9]+)/[0-9]+\-", _interface).group(1) - startNum = int(re.search("([0-9]+)$", interfaceGroup[0]).group(1)) - endNum = int(re.search("([0-9]+)$", interfaceGroup[1]).group(1)) + 1 - for realInterface in range(startNum, endNum): - realInterface = "{interfaceProfix}/{realInterface}".format(interfaceProfix=interfaceProfix, - realInterface=realInterface) - lineInfo["interface"].append(realInterface) - lineInfo["id"] = allLine[i + 1].split()[0].strip() - njInfo["content"].append(lineInfo) - - i += 1 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - if re.search("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]{1,2}", _interfaceInfo): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})\s+\ -([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+([0-9]+/[0-9]+)\s+\ -(\S+)\s+(\S+)", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["via"] = tmp.group(3) - lineInfo["metric"] = tmp.group(4) - lineInfo["interface"] = tmp.group(5) - lineInfo["type"] = tmp.group(6) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>|\]|\$) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = {"members": [], - "lineState": "", - "speed": "", - "type": "", - "inputRate": "", - "outputRate": "", - "crc": "", - } - # Get name of the interface - tmp = re.search("([a-z]+\-[0-9]+/[0-9]+/[0-9]+)", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1) - else: - # it is not interface - continue - # Get state of the interface. - lineInfo["interfaceState"] = re.search("(up|down)/(up|down)", _interfaceInfo).group() - # Get description of the interface. - lineInfo["description"] = _interfaceInfo.split()[-1].strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, name=None): - """ - @param vlan_id: vlan-id, - @param name: name of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - if name is None: - # no name. - cmd = "vlan {vlan_id}".format(vlan_id=vlan_id) - else: - cmd = "vlan {vlan_id}\rname {name}".format(vlan_id=vlan_id, name=name) - prompt = { - "success": "[\r\n]+\S+\(vlan\-{vlan_id}\)# ?$".format(vlan_id=vlan_id), - "error": "[\r\n]+(Invalid|Error)[\s\S]+", - } - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success" and not re.search(prompt["error"], tmp["content"]): - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - self.deleteVlan(vlan_id) - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Delete vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "no vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.vlanExist(vlan_id)["status"]: - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = {"success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "([Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+"} - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" [Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseFortinet.py b/lib/forward/devclass/baseFortinet.py index dee73d3..0605df1 100644 --- a/lib/forward/devclass/baseFortinet.py +++ b/lib/forward/devclass/baseFortinet.py @@ -1,531 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Fortinet. +Author: Cheung Kei-Chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -from forward.utils.paraCheck import int_to_mask -import re class BASEFORTINET(BASESSHV2): """This is a manufacturer of foritinet, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - - def privilegeMode(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = '''end''' - prompt = { - "success": "end\r\r\n\r\n\S+(#|>) ?$", - "normal": "Unknown action[\s\S]+", - } - result = self.command(cmd, prompt=prompt) - if not result["state"] is None: - njInfo["status"] = True - self.mode = 2 - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def configMode(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = '''end''' - prompt = { - "success": "end\r\r\n\r\n\S+(#|>) ?$", - "normal": "Unknown action[\s\S]+", - } - result = self.command(cmd, prompt=prompt) - if not result["state"] is None: - njInfo["status"] = True - self.mode = 3 - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def commit(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = '''end''' - prompt = { - "success": "end\r\r\n\r\n\S+(#|>) ?$", - "normal": "Unknown action[\s\S]+", - } - result = self.command(cmd, prompt=prompt) - if not result["state"] is None: - njInfo["status"] = True - self.mode = 2 - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - """ - Since the syslog information needs to be obtained according to the - configuration name of the syslog on the device of this model, - the name of the syslog needs to be trained until the configuration does not exist. - For example: - syslog - syslog2 - syslog3 - """ - prompt = { - "success": "end[\r\n]+\S+(#|>) ?$", - "error": "Return code \-61[\s\S]+", - } - i = 0 - while True: - i += 1 - if i == 1: - cmd = "show full-configuration log syslogd setting" - else: - cmd = "show full-configuration log syslogd{i} setting".format(i=i) - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search('set server "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"', - result["content"]) - if tmp: - njInfo["content"].append(tmp.group(1)) - njInfo["status"] = True - else: - # Exit if the configuration does not exist - njInfo["errLog"] = result["errLog"] - break - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show full-configuration system ntp''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown action[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall('set server "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})"', - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show full-configuration system snmp community''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown action[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall('set ip ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})', - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show full-configuration system interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("next", result["content"]) - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"members": [], - "interfaceState": "", - "interfaceName": "", - "speed": "", - "type": "", - "inputRate": "", - "outputRate": "", - "ip": "", - "lineState": "", - "adminState": "", - "mtu": "", - "duplex": "", - "description": "", - "crc": ""} - # Get name of the interface. - tmp = re.search('edit "(.+)"', _interfaceInfo) - if tmp: - lineInfo['interfaceName'] = tmp.group(1) - else: - continue - # Only interface information is obtained here, not vlan information - if re.search("vlan", lineInfo['interfaceName']): - continue - tmp = re.search("set description(.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip().strip('"\'') - njInfo["content"].append(lineInfo) - # Get the details through the physical interface name - detail = self.command(cmd="get system interface physical", prompt=prompt) - """ - ==[npu1-vlink0] - mode: static - ip: 0.0.0.0 0.0.0.0 - ipv6: ::/0 - status: down - speed: n/a - ==[npu1-vlink1] - mode: static - ip: 0.0.0.0 0.0.0.0 - ipv6: ::/0 - status: down - speed: n/a - """ - if detail["state"] == "success": - interfacesFullInfo = re.split("==", detail["content"]) - for _interfaceInfo in interfacesFullInfo: - data = {"ip": "", - "type": "", - "interfaceState": "", - "speed": "", - "duplex": ""} - tmp = re.search("(\[\S+\])", _interfaceInfo) - if tmp: - _interfaceName = tmp.group(1).strip("[]") - # Get ip - tmp = re.search("ip: (\S*)", _interfaceInfo) - if tmp: - data["ip"] = tmp.group(1) - # Get type - tmp = re.search("mode: (\S*)", _interfaceInfo) - if tmp: - data["type"] = tmp.group(1) - # Get status - tmp = re.search("status: (\S*)", _interfaceInfo) - if tmp: - data["interfaceState"] = tmp.group(1) - # Get speed - tmp = re.search("speed: (\S*)", _interfaceInfo) - if tmp: - data["speed"] = tmp.group(1) - # Get duplex - tmp = re.search("Duplex: ([A-Za-z]+)", _interfaceInfo) - if tmp: - data["duplex"] = tmp.group(1) - # Update data - index = 0 - for _line in njInfo["content"]: - if _interfaceName == _line["interfaceName"]: - njInfo["content"][index].update(**data) - index += 1 - else: - continue - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show full-configuration system interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("next", result["content"]) - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": ""} - # Get name of the interface. - tmp = re.search('set vlanid (\d+)', _interfaceInfo) - if tmp: - lineInfo['id'] = tmp.group(1) - else: - # Only Vlan information is obtained here, not vlan information - continue - # Get description. - tmp = re.search("set description(.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip().strip('"\'') - # Get status. - tmp = re.search("set status (.*)", _interfaceInfo) - if tmp: - lineInfo["status"] = tmp.group(1).strip().strip('"\'') - # Get interface. - tmp = re.search('set interface "(.*)"', _interfaceInfo) - if tmp: - lineInfo["interface"] = re.split(",| ", tmp.group(1).strip('"')) - # Get type. - tmp = re.search('set mode ([A-Za-z]+)', _interfaceInfo) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "get system status" - prompt = { - "success": "Release[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Version:.*v(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "get router info routing-table all" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+[\r\n]+[\S]+.+(#|>) ?$", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("[\r\n]+", result["content"]) - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"net": "", - "mask": "", - "metric": "", - "description": "", - "type": "", - "interface": "", - "via": ""} - tmp = re.search("(\S)\s+", _interfaceInfo) - # Get type of routing. - if tmp: - """ - S 1.1.1.0/24 [10/0] via 100.11.1.97, inter-vlanxxxx - S 1.1.2.0/24 [10/0] via 100.11.1.113, inter-vlanyyyy - S 1.1.4.0/24 [10/0] via 100.11.1.129, inter-vlanzzzz - """ - _type = tmp.group(1) - if _type == "S": - lineInfo["type"] = "static" - elif _type == "C": - lineInfo["type"] = "direct" - elif _type == "O": - lineInfo["type"] = "ospf" - elif _type == "R": - lineInfo["type"] = "rip" - elif _type == "B": - lineInfo["type"] = "bgp" - else: - lineInfo["type"] = "unkown" - # Get net,mask and interface of routing. - tmp = re.search("(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/(\d{1,2})", _interfaceInfo) - if tmp: - dataLine = _interfaceInfo.split() - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["interface"] = dataLine[-1] - if lineInfo["type"] == "static": - lineInfo["via"] = dataLine[4].strip(",") - else: - continue - # Saving above data. - njInfo["content"].append(lineInfo) - continue - elif re.search("^\s+\[\d+/\d+\]", _interfaceInfo): - """ - S 1.3.3.0/24 [10/0] via 192.168.19.129, inter-vlanyyyy - S 1.1.1.4/32 [10/0] via 192.168.93.41, inter-vlanxxxx - [10/0] via 192.168.199.1, mgxxx <------ Get this line - """ - # Get net and mask from njInfo["content"],then added new via and interface of routing to list. - lineInfo = njInfo["content"][-1] - dataLine = _interfaceInfo.split() - lineInfo["via"] = dataLine[2] - lineInfo["interface"] = dataLine[3] - njInfo["content"].append(lineInfo) - # Get description of routing for static routing only. - detail = self.command("show router static", prompt=prompt) - if detail["state"] == "success": - index = 0 - for line in njInfo["content"]: - # Get original net and mask from njInfo. - net = line["net"] - mask = int(line["mask"]) - # Only static routing. - if not line["type"] == "static": - continue - for config in detail["content"].split("next"): - # Match the description. - reg = "set comment(.*)[\r\n]+.*[\r\n]+\s+set dst %s %s" % (net, int_to_mask(mask)) - tmp = re.search(reg, config) - if tmp: - # Get description. - njInfo["content"][index]["description"] = tmp.group(1).strip().strip('"\'') - index += 1 - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="get system performance status"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = {"success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "([Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+"} - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search("[Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showOSPF(self, cmd="get router info ospf neighbor"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - dataLine = re.findall("[0-9]{1,3}.*", result["content"]) - if len(dataLine) == 0: - return njInfo - for line in dataLine: - line = line.split() - if len(line) == 7: - njInfo["content"].append({ - "neighbor-id": line[0], - "pri": line[1], - "state": line[2] + line[3], - "uptime": "", - "address": line[5], - "interface": line[6], - "deadTime": line[4]} - ) - else: - # The line does not matched data of expection. - continue - return njInfo - - def showRun(self): - cmd = "show full-configuration" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseH3C.py b/lib/forward/devclass/baseH3C.py deleted file mode 100644 index 2fa0ace..0000000 --- a/lib/forward/devclass/baseH3C.py +++ /dev/null @@ -1,1103 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Base device class for H3C basic device method, by using paramiko module. -""" - -import re -import logging -import time -import random -from forward.devclass.baseSSHV2 import BASESSHV2 -from forward.utils.forwardError import ForwardError -from forward.utils.paraCheck import checkIP -from forward.utils.deviceListSplit import DEVICELIST - - -class BASEH3C(BASESSHV2): - """This is a manufacturer of h3c, using the - SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. - """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - tmp = self.generalMode() - if not tmp["status"]: - # Switch failure. - return tmp - # Excute a command. - tmp = self.command("save", - prompt={"success": "Are you sure\? \[Y/N\]: ?$", - "error": "Error:Incomplete command[\s\S]+"}) - if tmp["state"] == "success": - tmp = self.command("Y", prompt={"success": "press the enter key\): ?$"}) - if tmp["state"] == "success": - tmp = self.command("", prompt={"success": "overwrite\? \[Y/N\]: ?$"}) - if tmp["state"] == "success": - tmp = self.command("Y", prompt={"success": "successfully\.[\r\n]+<\S+>?$"}) - if tmp["state"] == "success": - result["status"] = True - result["content"] = tmp["content"] - else: - result["errLog"] = "That save configuration is failed.related information: [{content}]".format(content=tmp["content"]) - else: - result["errLog"] = "That save configuration is failed.related information: [{content}]".format(content=tmp["content"]) - - else: - result["errLog"] = "Failed save configuration,related information: [{content}]".format(content=tmp["content"]) - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=tmp["content"], errLog=tmp["errLog"]) - return result - - def generalMode(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position before switch to general mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode > 1: - tmp = self.command("return", prompt={"success": "[\r\n]+\S+> ?$"}) - if tmp["state"] == "success": - result["status"] = True - self.mode = 1 - return result - else: - result["errLog"] = tmp["errLog"] - return result - else: - result["status"] = True - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - toGeneralModeResult = self.generalMode() - if toGeneralModeResult["status"] is False: - result["errLog"] = "Demoted from hight-mode to general-mode failed." - return result - # else,go into privilege-mode. - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnableResult = self.command("system-view", prompt={"success": "[\r\n]+\S+\] ?$", - "error": "[\r\n]+\S+> ?$"}) - if sendEnableResult["state"] == "success": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnableResult["state"] == "error": - result["errLog"] = "Failed to switch to privilege mode, \ - related information: [{errLog}],[{content}]".format(errLog=sendEnableResult["errLog"], - content=sendEnableResult["content"]) - return result - else: - return sendEnableResult - - def showLog(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "display current-configuration | i log" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("loghost ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "dis version" - prompt = { - "success": "[\s\S]+[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("software.*version(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - # Gets the NTP server address of the device - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "dis current-configuration | i ntp" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp-service unicast-server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Gets the SNMP server address of the device - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "dis current-configuration | i snmp" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("udp-domain ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display vlan" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - currentSection = "vlanName" - isContinueLine = False - for _vlanInfo in result["content"].split("\r\r\n"): - if re.search("\-\-\-\-", _vlanInfo): - continue - if re.search("^[0-9]", _vlanInfo) and currentSection == "vlanName": - isContinueLine = True - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - tmp = re.search("([0-9]+)\s+(\S+)[\s\S]+:(.*)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["type"] = tmp.group(2) - if tmp.lastindex == 3: - lineInfo["interface"] = tmp.group(3).split() - njInfo["content"].append(lineInfo) - else: - # Vlan has not yet configured interfaces. - tmp = re.search("([0-9]+)\s+([a-z]+)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["type"] = tmp.group(2) - njInfo["content"].append(lineInfo) - elif isContinueLine is True and not re.search("VID Status", - _vlanInfo) and currentSection == "vlanName": - for _interface in _vlanInfo.split(): - lineInfo = njInfo["content"].pop() - lineInfo["interface"].append(_interface.strip()) - njInfo["content"].append(lineInfo) - continue - else: - isContinueLine = False - if re.search("VID Status", _vlanInfo): - currentSection = "vlanType" - continue - if currentSection == "vlanType": - if re.search("^[0-9]", _vlanInfo.strip()): - tmp = re.search("([0-9]+)[ \t]+([a-z]+).*", _vlanInfo) - if tmp: - vlanID = tmp.group(1) - vlanStatus = tmp.group(2) - vlanDescription = tmp.group().split()[-1].strip() - i = 0 - for _vlan in njInfo["content"]: - if vlanID == _vlan["id"]: - njInfo["content"][i]["status"] = vlanStatus - njInfo["content"][i]["description"] = vlanDescription - i += 1 - - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display ip routing-table" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\r\n"): - # record the route table. - lineInfo = {"net": "", - "mask": "", - "metric": "", - "description": "", - "type": "", - "interface": "", - "via": ""} - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})\s+(\S+)\s+\ - \S+\s+\S+\s+\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+(\S+)", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["type"] = tmp.group(3) - lineInfo["via"] = tmp.group(4) - lineInfo["interface"] = tmp.group(5) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display interface" - # There are Special characters in some descriptions. - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.findall(".*current state[\s\S]+?Output bandwidth utilization :.*", - result["content"]) - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "mac": "", - "ip": ""} - # Get name of the interface. - lineInfo['interfaceName'] = re.search("(.*)current state", _interfaceInfo).group(1).strip() - # Get state of the interface and remove extra character. - lineInfo['interfaceState'] = re.search("current state :(.*)", _interfaceInfo).group(1).strip() - # Get state of line protocol of the interface and remove extra character. - lineInfo['lineState'] = re.search("Line protocol current state :(.*)", _interfaceInfo).group(1).strip() - # Get description of the interface. - lineInfo['description'] = re.search("Description:(.*)", _interfaceInfo).group(1).strip() - # Get MUT of the interface. - tmpMTU = re.search("The Maximum Transmit Unit is ([0-9]+)", _interfaceInfo) - if tmpMTU: - lineInfo["mtu"] = tmpMTU.group(1) - else: - lineInfo["mtu"] = "" - # Get speed of the interface. - tmp = re.search("Speed : ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["speed"] = int(tmp.group(1)) - else: - lineInfo["speed"] = "" - # Get duplex of the interface. - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo, flags=re.IGNORECASE) - if tmp: - lineInfo["duplex"] = tmp.group(1) - else: - lineInfo["duplex"] = "" - # Get duplex of the interface for s9312 - tmp = re.search("Duplex: ([a-z]+)", _interfaceInfo, flags=re.IGNORECASE) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Get ip of the interface. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - else: - lineInfo["ip"] = "" - # Get mac of the interface. - tmpMAC = re.search("Hardware address is (.*)", _interfaceInfo) - if tmpMAC: - lineInfo["mac"] = tmpMAC.group(1).strip() - else: - lineInfo["mac"] = "" - # Get port type of the interface. - tmpPortType = re.search("Physical is (\S+)", _interfaceInfo) - if tmpPortType: - lineInfo["type"] = tmpPortType.group(1).strip().strip(",") - else: - lineInfo["type"] = "" - # Last 300 seconds input rate - tmp = re.search("Last 300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - else: - lineInfo["inputRate"] = "" - tmp = re.search("Last 300 seconds output rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - else: - lineInfo["outputRate"] = "" - # CRC: - tmp = re.search("CRC:.*([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["crc"] = tmp.group(1) - else: - lineInfo["crc"] = "" - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, name=None): - """ - @param vlan_id: vlan-id, - @param description: description of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - if name is None: - cmd = "vlan {vlan_id}".format(vlan_id=vlan_id) - else: - cmd = "vlan {vlan_id}\rname {name}".format(vlan_id=vlan_id, name=name) - prompt = { - "success": "[\r\n]+\S+vlan{vlan_id}\] ?$".format(vlan_id=vlan_id), - "error": "Error:[\s\S]+", - } - # runing command of vlan. - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success" and not re.search(prompt["error"], tmp["content"]): - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - self.deleteVlan(vlan_id) - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Deleting vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "undo vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "{cmd}[\r\n]+\S+\] ?$".format(vlan_id=vlan_id, cmd=cmd), - "error": "(Error):[\s\S]+", - } - tmp = self.command(cmd, prompt=prompt) - logging.debug("runing command result:" + str(tmp)) - if tmp["state"] == "success": - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted[{content},{errLog}].".format(vlan_id=vlan_id, - content=tmp["content"], - errLog=tmp["errLog"]) - return result - - def interfaceVlanExist(self, vlan_id): - # parameter vlan_id: Vlan123 - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameter - vlan_id = str(vlan_id).strip() - if re.search("^[0-9]+$", vlan_id): - vlan_id = "Vlanif" + vlan_id - for line in self.showInterface()["content"]: - if vlan_id == line["interfaceName"]: - result["status"] = True - return result - result["errLog"] = "The interface-vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def deleteInterfaceVlan(self, vlan_id): - # Deleting virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter privilege-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "undo interface vlanif {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+(\]|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.interfaceVlanExist(vlan_id)["status"]: - # The interface-vlan was deleted successfuly. - result["content"] = "The interface-vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The interface-vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def createInterfaceVlan(self, vlan_id, ip=None, mask=None, description="None"): - # Creating virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameters. - if ip is None or mask is None: - result["errLog"] = "parameter of ip and mask can not be None." - return result - elif checkIP(ip) is False: - result["errLog"] = "Illegal IP address." - return result - elif checkIP(mask) is False: - result["errLog"] = "Illegal net mask." - return result - # Enter privilege-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd1 = "interface vlanif {vlan_id}".format(vlan_id=vlan_id) - cmd2 = "description {description}".format(description=description) - cmd3 = "ip address {ip} {mask}".format(ip=ip, mask=mask) - # Forward need to check if The vlan exists,before creating. - if not self.vlanExist(vlan_id)["status"]: - # no exists. - result["errLog"] = "The vlan({vlan_id}) does not exists,\ -thus can't create interface-vlan.".format(vlan_id=vlan_id) - return result - prompt1 = { - "success": "[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id), - "error": "[\r\n]+\S+\] ?$", - # "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt2 = { - "success": "{cmd2}[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id, cmd2=cmd2), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt3 = { - "success": "{cmd3}[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id, cmd3=cmd3), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - # Running cmd1. - tmp = self.command(cmd1, prompt=prompt1) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd2 - tmp = self.command(cmd2, prompt=prompt2) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd3 - tmp = self.command(cmd3, prompt=prompt3) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Checking... - if self.interfaceVlanExist(vlan_id)["status"]: - result["conent"] = "The configuration was created by Forwarder." - result["status"] = True - else: - # The configuration was not created and rolled back. - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - - def basicInfo(self, cmd="display version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" uptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) years?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) weeks?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) days?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showOSPF(self, cmd="display ospf peer brief"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - dataLine = re.findall("[0-9]{1,3}.*", result["content"]) - if len(dataLine) == 0: - return njInfo - for line in dataLine: - line = line.split() - if len(line) == 4: - njInfo["content"].append({ - "neighbor-id": line[2], - "pri": "", - "state": line[3], - "uptime": "", - "address": line[0], - "deadTime": "", - "interface": line[1]}, - ) - else: - # The line does not matched data of expection. - continue - return njInfo - - def createObjectGroupIPAddress(self, host=[]): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - if isinstance(host, list): - if len(host) == 0: - raise IOError("hosts's value should not be empty.") - else: - raise IOError("host's formate is incorrect.") - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - objectGroupName = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime()) + "." + str(random.randint(100000, 999999)) - cmd = "object-group ip address {objectGroupName}".format(objectGroupName=objectGroupName) - prompt = { - "success": "[\r\n]+\S+{objectGroup}\] ?$".format(objectGroup="-obj-grp-ip-" + objectGroupName) - } - # Mode of entry into object-group-ip-address - result = self.command(cmd, prompt) - if not result["state"] == "success": - raise IOError(result["errLog"]) - # Create object-group ip address - i = 0 - for ip in host: - if re.search("\-", ip): - ipA, ipB = ip.split("-") - cmd = "{i} network host address {ipA} {ipB}".format(i=i, ipA=ipA, ipB=ipB) - else: - cmd = "{i} network host address {ip}".format(i=i, ip=ip) - i += 1 - result = self.command(cmd, prompt) - errLine = "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command|Wrong|Too many)" - if not result["state"] == "success" or re.search(errLine, result["content"], flags=re.IGNORECASE): - raise IOError(result["content"]) - njInfo = {"status": True, "content": objectGroupName} - return njInfo - - def createObjectGroupService(self, configuration, serviceName): - """ - @ parame configuration: 'service udp source gt 0 destination eq 30002' or 'service udp source gt 0 destination eq 30002' - @ parame serviceName: name of object-group-service. - """ - njInfo = { - "status": False, - "content": "", - "errLog": "" - } - cmdA = "object-group service {serviceName}".format(serviceName=serviceName) - promptA = { - "success": "[\r\n]+\S+{serviceName}\] ?$".format(serviceName="-obj-grp-service-" + serviceName) - } - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - result = self.command(cmdA, promptA) - if not result["state"] == "success": - raise IOError(result["errLog"]) - promptB = { - "success": "[\r\n]+\S+{serviceName}\] ?$".format(serviceName="-obj-grp-service-" + serviceName) - } - result = self.command(configuration, promptB) - errLine = "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command|Wrong|Too many)" - if not result["state"] == "success" or re.search(errLine, result["content"]): - raise IOError(result["errLog"]) - njInfo = {"status": True, "content": serviceName} - return njInfo - - def isExistObjectGroupService(self, configuration): - """ - @ parame configuration: 'service udp source gt 0 destination eq 30002' or 'service udp source gt 0 destination eq 30002' - """ - njInfo = { - "status": False, - "content": "", - "errLog": "The object-group is not exist." - } - prompt = { - "success": "[\r\n]+\S+\] ?$", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - cmd = '''display object-group service''' - result = self.command(cmd, prompt) - if not result["state"] == "success": - raise IOError(result["errLog"]) - serviceName = None - for line in result["content"].split("\r\n"): - tmp = re.search("Service object group (\S+):", line) - # Get name of object-group's service - if tmp: - serviceName = tmp.group(1) - continue - # Match configuration - if re.search(configuration, line): - njInfo = {"status": True, "content": serviceName} - break - return njInfo - - def isExistObjectPolicyIP(self, policyName): - """ - @parame policyName: any string - """ - njInfo = { - "status": False, - "content": "", - "errLog": "The object-group-policy {policyName} is not exist.".format(policyName=policyName) - } - prompt = { - "success": "[\r\n]+\S+\] ?$", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - cmd = "display object-policy ip" - tmp = self.command(cmd=cmd, prompt=prompt) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - cmdA = "object-policy ip {policyName}".format(policyName=policyName) - cmdB = "display this" - promptA = { - "success": "[\r\n]+\S+\-object-policy-ip-{policyName}\] ?$".format(policyName=policyName), - } - if re.search("Object-policy ip {policyName}".format(policyName=policyName), tmp["content"]): - tmp = self.command(cmdA, promptA) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - # Get list of rules. - tmp = self.command(cmdB, promptA) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - ruleID = 0 - for line in tmp["content"].split("\r\r\n"): - result = re.search("rule ([0-9]+)", line) - if result: - ruleID = int(result.group(1)) + 1 - njInfo = {"status": True, "content": ruleID} - return njInfo - - def isExistObjectGroupIPAddress(self, hostList=[]): - """ - @param hostList: ['10.0.0.1','10.0.0.2-10.0.0.3'] - njInfo = {"status":True,"content":"object-group-name"} - """ - if not isinstance(hostList, list): - raise IOError("The parameter's formate is incorrect.Its formate should is ['10.,0.0.1','192.168.1.1','192.168.2.100-192.168.2.200']") - hostList = DEVICELIST(hostList).getIpList() - hostList = sorted(hostList) - njInfo = { - "status": False, - "content": "", - "errLog": "The object-group ip is not exist." - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - cmd = '''dis object-group ip address | include "Ip address object group"''' - result = self.command(cmd, prompt) - if not result["state"] == "success": - return result - allGroups = [] - # Getting all groups of object. - for line in result["content"].split("\r\n"): - tmp = re.search("Ip address object group (\S+):", line) - if tmp: - allGroups.append(tmp.group(1)) - # Enter a mode of object-group,and then get hosts of all. - # example: {"object-group-a":["10.0.0.1","10.0.0.2"]} - allObjectIP = {} - for group in allGroups: - cmdA = "object-group ip address {objectGroup}".format(objectGroup=group) - prompt = { - "success": "[\r\n]+\S+{objectGroup}\] ?$".format(objectGroup="-obj-grp-ip-" + group) - } - # Enter a mode of object-group - tmp = self.command(cmd=cmdA, prompt=prompt) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - cmdB = "dis this" - # Get datas of object-group - tmp = self.command(cmd=cmdB, prompt=prompt) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - hosts = [] - for line in tmp["content"].split("\r\n"): - # Get single ip. - info = re.search("[0-9]+ network host address ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", line) - if info: - hosts.append(info.group(1)) - continue - # Get ip range. - info = re.search("[0-9]+ network range ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", line) - if info: - iplist = [info.group(1) + "-" + info.group(2)] - hosts.append(DEVICELIST(iplist).getIpList()) - cmdC = "quit" - promptC = { - "success": "[\r\n]+\S+\] ?$" - } - tmp = self.command(cmd=cmdC, prompt=promptC) - if not tmp["state"] == "success": - raise IOError(tmp["errLog"]) - allObjectIP[group] = hosts - # Match whether there are existing object-group. - for group, value in allObjectIP.items(): - if hostList == sorted(value): - njInfo = {"status": True, "content": group} - break - return njInfo - - def addObjectPolicyIP(self, policyName, configuration, comment): - tmp = self.privilegeMode() - if tmp["status"] is False: - raise IOError(tmp["errLog"]) - cmdA = "object-policy ip {policyName}".format(policyName=policyName) - promptA = { - "success": "[\r\n]+\S+\-object-policy-ip-{policyName}\] ?$".format(policyName=policyName), - } - errLine = "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command|Wrong|Too many)" - tmp = self.command(cmdA, promptA) - if not tmp["state"] == "success": - return tmp - # Create rule - tmp = self.command(configuration, promptA) - if not tmp["state"] == "success" or re.search(errLine, tmp["content"]): - raise IOError(tmp["content"]) - # set comment - tmp = self.command(comment, promptA) - if not tmp["state"] == "success": - if re.search(errLine, tmp["content"]): - raise IOError(tmp["content"]) - else: - return tmp - return tmp - - def createSecurityPolicy(self, - sourceHost=[], - destinationHost=[], - policyName=None, - comment="", - serviceParam={"protocol": "tcp/udp", - "sourcePort": None, # '80' or '80-90' - "sourcePortType": "eq/gt/lt/range", - "destinationPort": None, # '80' or '80-90' - "destinationPortType": "eq/gt/lt/range"}): - """ - @sourcdeHost: list type, ex: ["10.0.0.1",".10.0.0.3-10.0.0.5","192.168.1.1"]; - @destinationHost: list type, ex: ["10.0.0.1","10.0.0.2-10.0.0.5","192.168.1.1"]; - @policyName: string type , ex: TestName; - @comment: strying type, ex: test-comment; - @ serviceParam: dict type, ex: - {"protocol":"tcp", - "sourcePort":None or '890' or '900-999', - "sourcePortType":"eq" or "lt" or "gt" or "range", - "destinationPort":None or '890' or '900-999', - "destinationPortType":"eq" or "lt" or "gt" or "range", - } - return {"status":False/True,"content":"...","errLog":"Cause failed facotr"} - """ - # Check whether parameters meet thee requirements. - if not isinstance(comment, str): - raise IOError("comment's formate should be a string and not be empty.") - else: - if re.search("^ *$", comment): - raise IOError("comment's format should not be empty") - if not isinstance(policyName, str): - raise IOError("policyName's format should be a string and not be empty") - else: - if re.search("^ *$", policyName): - raise IOError("policyName's format should not be empty") - if not isinstance(sourceHost, list): - raise IOError("sourceHost's formate should is a list,ex: ['10.0.0.1','10.0.0.1-10.0.0.3']") - elif not isinstance(destinationHost, list): - raise IOError("destinationHost's formate should is a list,ex: ['10.0.0.1','10.0.0.1-10.0.0.3']") - elif not isinstance(serviceParam, dict): - raise IOError("serviceParam's formate should is a dict.plase use help(createSecurityPolicy) to see details.") - else: - if serviceParam.has_key("protocol"): - if (not serviceParam["protocol"] == "tcp") and (not serviceParam["protocol"] == "udp"): - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - raise IOError("serviceParam's formate should is a dict and incloude key of protocol.plase use help(createSecurityPolicy) to see details.") - if serviceParam.has_key("sourcePort"): - if (not isinstance(serviceParam["sourcePort"], str)) and (not serviceParam["sourcePort"] is None): - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - if serviceParam["sourcePort"] is not None: - if serviceParam.has_key("sourcePortType"): - if (not serviceParam["sourcePortType"] == "eq") and (not serviceParam["sourcePortType"] == "gt") and (not serviceParam["sourcePortType"] == "lt") and (not serviceParam["sourcePortType"] == "range"): - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - if serviceParam.has_key("sourcePortType"): - raise IOError("Since serviceParame['sourcePort'] is None,serviceParam['sourcePortType'] should not be exist.") - if serviceParam.has_key("destinationPort"): - if (not isinstance(serviceParam["destinationPort"], str)) and (not serviceParam["destinationPort"] is None): - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - if not serviceParam["destinationPort"] is None: - if serviceParam.has_key("destinationPortType"): - if (not serviceParam["destinationPortType"] == "eq") and (not serviceParam["destinationPortType"] == "gt") and (not serviceParam["destinationPortType"] == "lt") and (not serviceParam["destinationPortType"] == "range"): - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - raise IOError("serviceParam's formate is incorrect.plase use help(createSecurityPolicy) to see details.") - else: - if serviceParam.has_key("destinationPortType"): - raise IOError("Since serviceParame['destinationPort'] is None,serviceParam['destinationPortType'] should not be exist.") - # Check the service section. - if serviceParam["sourcePort"] is None: - sourceSection = "" - else: - if serviceParam["sourcePortType"] == "range": - if not re.search("^[0-9]+\-[0-9]+$", serviceParam["sourcePort"]): - raise IOError("sourcePort's format of serviceParam is incorrect.") - portA, portB = serviceParam["sourcePort"].split("-") - sourceSection = "source range {portA} {portB}".format(portA=portA, portB=portB) - else: - if not re.search("^[0-9]+$", serviceParam["sourcePort"]): - raise IOError("sourcePort's format of serviceParam is incorrect.") - sourceSection = "source {sourcePortType} {port}".format(sourcePortType=serviceParam["sourcePortType"], port=serviceParam["sourcePort"]) - if serviceParam["destinationPort"] is None: - destinationSection = "" - else: - if serviceParam["destinationPortType"] == "range": - if not re.search("^[0-9]+\-[0-9]+$", serviceParam["destinationPort"]): - raise IOError("destinationPort's format of serviceParam is incorrect.") - portA, portB = serviceParam["destinationPort"].split("-") - destinationSection = "destination range {portA} {portB}".format(portA=portA, portB=portB) - else: - if not re.search("^[0-9]+$", serviceParam["destinationPort"]): - raise IOError("destinationPort's format of serviceParam is incorrect.") - destinationSection = "destination {destinationPortType} {port}".format(destinationPortType=serviceParam["destinationPortType"], port=serviceParam["destinationPort"]) - configuration = "0 service {protocol} {sourceSection} {destinationSection}".format(protocol=serviceParam["protocol"], sourceSection=sourceSection, destinationSection=destinationSection) - # Check whether the object-policy is exist. - tmp = self.isExistObjectPolicyIP(policyName) - if not tmp["status"]: - return tmp - ruleID = tmp["content"] - result = self.isExistObjectGroupIPAddress(sourceHost) - # Create object-group-ip-address of sourceHost if the object-group is not exist. - if result["status"] is True: - sourceObjectGroupIPName = result["content"] - else: - tmp = self.createObjectGroupIPAddress(sourceHost) - if tmp["status"] is False: - return tmp - sourceObjectGroupIPName = tmp["content"] - result = self.isExistObjectGroupIPAddress(destinationHost) - # Create object-group-ip-address of destinationHost if the object-group is not exist. - if result["status"] is True: - destinationObjectGroupIPName = result["content"] - else: - tmp = self.createObjectGroupIPAddress(destinationHost) - if tmp["status"] is False: - return tmp - destinationObjectGroupIPName = tmp["content"] - tmp = self.isExistObjectGroupService(configuration) - serviceName = time.strftime("%Y_%m_%d_%H_%M_%S", time.localtime()) + "." + str(random.randint(100000, 999999)) - if not tmp["status"]: - # Create object-group-service if that is not exist. - tmp = self.createObjectGroupService(configuration, serviceName) - if not tmp["status"]: - return tmp - configurationB = "rule {ruleID} pass source-ip {sourceObjectGroupIPName} destination-ip {destinationObjectGroupIPName} service {serviceName} counting ".format(ruleID=ruleID, sourceObjectGroupIPName=sourceObjectGroupIPName, destinationObjectGroupIPName=destinationObjectGroupIPName, serviceName=serviceName) - comment = "rule {ruleID} comment {comment}".format(comment=comment, ruleID=ruleID) - tmp = self.addObjectPolicyIP(policyName, configurationB, comment) - if tmp["status"] is True: - tmp = self.commit() - return tmp - - def showRun(self): - cmd = "display current-configuration" - tmp = self.generalMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+> ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\r\n".join(njInfo["content"].split("\r\r\n")[1:-1]) - return njInfo diff --git a/lib/forward/devclass/baseHuawei.py b/lib/forward/devclass/baseHuawei.py index 0fcaaab..459c0f7 100644 --- a/lib/forward/devclass/baseHuawei.py +++ b/lib/forward/devclass/baseHuawei.py @@ -1,720 +1,20 @@ -# coding:utf-8 +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Base device class for huawei basic device method, by using paramiko module. +Author: Cheung Kei-Chuen, Wangzhe """ import re -import logging from forward.devclass.baseSSHV2 import BASESSHV2 from forward.utils.forwardError import ForwardError -from forward.utils.paraCheck import checkIP class BASEHUAWEI(BASESSHV2): """This is a manufacturer of huawei, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - tmp = self.generalMode() - if not tmp["status"]: - # Switch failure. - return tmp - # Excute a command. - tmp = self.command("save", - prompt={"success": "Are you sure to continue\?\[Y/N\] ?$", - "error": "Error:Incomplete command[\s\S]+"}) - if tmp["state"] == "success": - continueCommandResult = self.command("Y", prompt={"success": "successfully[\s\S]+[\r\n]+\S+> ?$"}) - if continueCommandResult["state"] == "success": - # Successfully. - result["status"] = True - else: - # Failed. - result["errLog"] = "Failed save configuration,\ - relate-information: [{content}]".format(content=continueCommandResult["content"]) - result["status"] = False - elif tmp["state"] == "error": - result["errLog"] = "The command failed to execute.info: [{content}]".format(content=tmp["content"]) - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=tmp["content"], errLog=tmp["errLog"]) - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def generalMode(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position before switch to general mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode > 1: - tmp = self.command("return", prompt={"success": "[\r\n]+\S+> ?$"}) - if tmp["state"] == "success": - result["status"] = True - self.mode = 1 - return result - else: - result["errLog"] = tmp["errLog"] - return result - else: - result["status"] = True - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - toGeneralModeResult = self.generalMode() - if toGeneralModeResult["status"] is False: - result["errLog"] = "Demoted from hight-mode to general-mode failed." - return result - # else,go into privilege-mode. - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnableResult = self.command("system-view", prompt={"success": "[\r\n]+\S+\] ?$", - "error": "[\r\n]+\S+> ?$"}) - if sendEnableResult["state"] == "success": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnableResult["state"] == "error": - result["errLog"] = "Failed to switch to privilege mode, \ - related information: [{errLog}],[{content}]".format(errLog=sendEnableResult["errLog"], - content=sendEnableResult["content"]) - return result - else: - return sendEnableResult - - def showLog(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "display current-configuration | i log" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("loghost ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "dis version" - prompt = { - "success": "[\s\S]+[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("software.*version(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - # Gets the NTP server address of the device - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "dis current-configuration | i ntp" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp-service unicast-server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Gets the SNMP server address of the device - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "dis current-configuration | i snmp" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("udp-domain ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display vlan" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - currentSection = "vlanName" - isContinueLine = False - for _vlanInfo in result["content"].split("\r\n"): - if re.search("\-\-\-\-", _vlanInfo): - continue - if re.search("^[0-9]", _vlanInfo) and currentSection == "vlanName": - isContinueLine = True - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - tmp = re.search("([0-9]+)\s+(\S+)[\s\S]+:(.*)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["type"] = tmp.group(2) - if tmp.lastindex == 3: - lineInfo["interface"] = tmp.group(3).split() - njInfo["content"].append(lineInfo) - else: - # Vlan has not yet configured interfaces. - tmp = re.search("([0-9]+)\s+([a-z]+)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["type"] = tmp.group(2) - njInfo["content"].append(lineInfo) - elif isContinueLine is True and not re.search("VID Status", - _vlanInfo) and currentSection == "vlanName": - for _interface in _vlanInfo.split(): - lineInfo = njInfo["content"].pop() - lineInfo["interface"].append(_interface.strip()) - njInfo["content"].append(lineInfo) - continue - else: - isContinueLine = False - if re.search("VID Status", _vlanInfo): - currentSection = "vlanType" - continue - if currentSection == "vlanType": - if re.search("^[0-9]", _vlanInfo.strip()): - tmp = re.search("([0-9]+)[ \t]+([a-z]+).*", _vlanInfo) - if tmp: - vlanID = tmp.group(1) - vlanStatus = tmp.group(2) - vlanDescription = tmp.group().split()[-1].strip() - i = 0 - for _vlan in njInfo["content"]: - if vlanID == _vlan["id"]: - njInfo["content"][i]["status"] = vlanStatus - njInfo["content"][i]["description"] = vlanDescription - i += 1 - - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display ip routing-table" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - # record the route table. - lineInfo = {"net": "", - "mask": "", - "metric": "", - "description": "", - "type": "", - "interface": "", - "via": ""} - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})\s+(\S+)\s+\ - \S+\s+\S+\s+\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)\s+(\S+)", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["type"] = tmp.group(3) - lineInfo["via"] = tmp.group(4) - lineInfo["interface"] = tmp.group(5) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display interface" - # There are Special characters in some descriptions. - prompt = { - "success": "\r\n\r\n\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.findall(".*current state[\s\S]+?Output bandwidth utilization :.*", - result["content"]) - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "mac": "", - "ip": ""} - # Get name of the interface. - lineInfo['interfaceName'] = re.search("(.*)current state", _interfaceInfo).group(1).strip() - # Get state of the interface and remove extra character. - lineInfo['interfaceState'] = re.search("current state :(.*)", _interfaceInfo).group(1).strip() - # Get state of line protocol of the interface and remove extra character. - lineInfo['lineState'] = re.search("Line protocol current state :(.*)", _interfaceInfo).group(1).strip() - # Get description of the interface. - lineInfo['description'] = re.search("Description:(.*)", _interfaceInfo).group(1).strip() - # Get MUT of the interface. - tmpMTU = re.search("The Maximum Transmit Unit is ([0-9]+)", _interfaceInfo) - if tmpMTU: - lineInfo["mtu"] = tmpMTU.group(1) - else: - lineInfo["mtu"] = "" - # Get speed of the interface. - tmp = re.search("Speed : ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["speed"] = int(tmp.group(1)) - else: - lineInfo["speed"] = "" - # Get duplex of the interface. - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo, flags=re.IGNORECASE) - if tmp: - lineInfo["duplex"] = tmp.group(1) - else: - lineInfo["duplex"] = "" - # Get duplex of the interface for s9312 - tmp = re.search("Duplex: ([a-z]+)", _interfaceInfo, flags=re.IGNORECASE) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Get ip of the interface. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - else: - lineInfo["ip"] = "" - # Get mac of the interface. - tmpMAC = re.search("Hardware address is (.*)", _interfaceInfo) - if tmpMAC: - lineInfo["mac"] = tmpMAC.group(1).strip() - else: - lineInfo["mac"] = "" - # Get port type of the interface. - tmpPortType = re.search("Physical is (\S+)", _interfaceInfo) - if tmpPortType: - lineInfo["type"] = tmpPortType.group(1).strip().strip(",") - else: - lineInfo["type"] = "" - # Last 300 seconds input rate - tmp = re.search("Last 300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - else: - lineInfo["inputRate"] = "" - tmp = re.search("Last 300 seconds output rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - else: - lineInfo["outputRate"] = "" - # CRC: - tmp = re.search("CRC:.*([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["crc"] = tmp.group(1) - else: - lineInfo["crc"] = "" - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, name=None): - """ - @param vlan_id: vlan-id, - @param description: description of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - if name is None: - cmd = "vlan {vlan_id}".format(vlan_id=vlan_id) - else: - cmd = "vlan {vlan_id}\rname {name}".format(vlan_id=vlan_id, name=name) - prompt = { - "success": "[\r\n]+\S+vlan{vlan_id}\] ?$".format(vlan_id=vlan_id), - "error": "Error:[\s\S]+", - } - # runing command of vlan. - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success" and not re.search(prompt["error"], tmp["content"]): - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - self.deleteVlan(vlan_id) - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Deleting vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "undo vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "{cmd}[\r\n]+\S+\] ?$".format(vlan_id=vlan_id, cmd=cmd), - "error": "(Error):[\s\S]+", - } - tmp = self.command(cmd, prompt=prompt) - logging.debug("runing command result:" + str(tmp)) - if tmp["state"] == "success": - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted[{content},{errLog}].".format(vlan_id=vlan_id, - content=tmp["content"], - errLog=tmp["errLog"]) - return result - - def interfaceVlanExist(self, vlan_id): - # parameter vlan_id: Vlan123 - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameter - vlan_id = str(vlan_id).strip() - if re.search("^[0-9]+$", vlan_id): - vlan_id = "Vlanif" + vlan_id - for line in self.showInterface()["content"]: - if vlan_id == line["interfaceName"]: - result["status"] = True - return result - result["errLog"] = "The interface-vlan {vlan_id} does not exist.".format(vlan_id=vlan_id) - return result - - def deleteInterfaceVlan(self, vlan_id): - # Deleting virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter privilege-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "undo interface vlanif {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+(\]|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.interfaceVlanExist(vlan_id)["status"]: - # The interface-vlan was deleted successfuly. - result["content"] = "The interface-vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The interface-vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def createInterfaceVlan(self, vlan_id, ip=None, mask=None, description="None"): - # Creating virtual vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Checking parameters. - if ip is None or mask is None: - result["errLog"] = "parameter of ip and mask can not be None." - return result - elif checkIP(ip) is False: - result["errLog"] = "Illegal IP address." - return result - elif checkIP(mask) is False: - result["errLog"] = "Illegal net mask." - return result - # Enter privilege-mode. - tmp = self.privilegeMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd1 = "interface vlanif {vlan_id}".format(vlan_id=vlan_id) - cmd2 = "description {description}".format(description=description) - cmd3 = "ip address {ip} {mask}".format(ip=ip, mask=mask) - # Forward need to check if The vlan exists,before creating. - if not self.vlanExist(vlan_id)["status"]: - # no exists. - result["errLog"] = "The vlan({vlan_id}) does not exists,\ -thus can't create interface-vlan.".format(vlan_id=vlan_id) - return result - prompt1 = { - "success": "[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id), - "error": "[\r\n]+\S+\] ?$", - # "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt2 = { - "success": "{cmd2}[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id, cmd2=cmd2), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - prompt3 = { - "success": "{cmd3}[\r\n]+\S+Vlanif{vlan_id}\] ?$".format(vlan_id=vlan_id, cmd3=cmd3), - "error": "(Invalid|Error|Illegal|marker|Incomplete)[\s\S]+", - } - # Running cmd1. - tmp = self.command(cmd1, prompt=prompt1) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd2 - tmp = self.command(cmd2, prompt=prompt2) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Running cmd3 - tmp = self.command(cmd3, prompt=prompt3) - if not tmp["state"] == "success": - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - # Checking... - if self.interfaceVlanExist(vlan_id)["status"]: - result["conent"] = "The configuration was created by Forwarder." - result["status"] = True - else: - # The configuration was not created and rolled back. - self.deleteInterfaceVlan(vlan_id) - result["errLog"] = tmp["errLog"] - return result - - def basicInfo(self, cmd="display version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" uptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) years?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) weeks?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) days?", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showOSPF(self, cmd="display ospf peer brief"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - dataLine = re.findall("[0-9]{1,3}.*", result["content"]) - if len(dataLine) == 0: - return njInfo - for line in dataLine: - line = line.split() - if len(line) == 4: - njInfo["content"].append({ - "neighbor-id": line[2], - "pri": "", - "state": line[3], - "uptime": "", - "address": line[0], - "deadTime": "", - "interface": line[1]}, - ) - else: - # The line does not matched data of expection. - continue - return njInfo - - def showRun(self): - cmd = "display current-configuration" - tmp = self.generalMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+> ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseJuniper.py b/lib/forward/devclass/baseJuniper.py index 76323d9..bfd7da5 100644 --- a/lib/forward/devclass/baseJuniper.py +++ b/lib/forward/devclass/baseJuniper.py @@ -1,20 +1,5 @@ +#!/usr/bin/evn python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - """ It applies only to models of network equipment mx960 See the detailed comments mx960.py """ @@ -25,12 +10,8 @@ class BASEJUNIPER(BASETELNET): """This is a manufacturer of juniper, using the - telnet version of the protocol, so it is integrated with BASETELNET library. + telnet version of the protocol, so it is integrated with BASELTELNET library. """ - def __init__(self, *args, **kws): - BASETELNET.__init__(self, *args, **kws) - self.basePrompt = r"(>|#) *$" - def _recv(self, _prompt): """The user receives the message returned by the device. """ @@ -48,730 +29,3 @@ def _recv(self, _prompt): except ForwardError, e: data['errLog'] = str(e) return data - - def addUser(self, username, password, admin=False): - """Create a user on the device. - """ - # Separate commands to create administrator accounts and common accounts. - if admin: - command = "set system login user {username} class read-only\n".format(username=username) - else: - command = "set system login user {username} class ABC\n".format(username=username) - data = {"status": False, - "content": "", - "errLog": ""} - try: - if not username or not password: - # Specify a user name and password parameters here. - raise ForwardError('Please specify the username = your-username and password = your-password') - checkPermission = self._configMode() # swith to config terminal mode. - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # check terminal status - if self.isConfigMode: - # adduser - self.channel.write(command) - # recv result - data = self._recv(self.prompt) - if not data['status']: - # break - raise ForwardError(data['errLog']) - # execute useradd command - self.channel.write('set system login user {username} \ - authentication plain-text-password\n'.format(username=username)) - i = self.channel.expect([r"New password:", r"%s" % self.prompt], timeout=self.timeout) - result = i[-1] - if re.search('error|invalid', result, flags=re.IGNORECASE): - # command failure - raise ForwardError(result) - # Enter password - self.channel.write("{password}\n".format(password=password)) - # check password - i = self.channel.expect([r"Retype new password:", r"%s" % self.prompt], timeout=self.timeout) - # repassword - if i[0] == 0: - self.channel.write("{password}\n".format(password=password)) - # check password - i = self.channel.expect([r"%s" % self.prompt], timeout=self.timeout) - if i[0] == 0: - result = i[-1] - if re.search('error|invalid', result, flags=re.IGNORECASE): - raise ForwardError(result) - else: - # set password is successed. - data = self._commit() - # exit config terminal mode. - self._exitConfigMode() - elif i[0] == -1: - raise ForwardError('Error: receive timeout') - elif i[0] == 1: - # password wrong - raise ForwardError(i[-1]) - elif i[0] == -1: - # timeout - raise ForwardError('Error: receive timeout') - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def deleteUser(self, username): - """Delete a user on the device - """ - data = {"status": False, - "content": "", - "errLog": ""} - try: - if not username: - raise ForwardError('Please specify a username') - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # check terminal status - if self.isConfigMode: - # delete user - self.channel.write('delete system login user {username}\n'.format(username=username)) - i = self.channel.expect([r"%s" % self.prompt], timeout=self.timeout) - result = i[-1] - if re.search('error|invalid', result, flags=re.IGNORECASE): - # command failure - raise ForwardError(result) - else: - # Save - data = self._commit() - # exit config terminal mode. - self._exitConfigMode() - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def changePassword(self, username, password): - """Modify the password for the device account. - """ - data = {"status": False, - "content": "", - "errLog": ""} - try: - if not username or not password: - # Specify a user name and password parameters here. - raise ForwardError('Please specify the username = your-username and password = your-password') - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # check terminal status - if self.isConfigMode: - # execute useradd command - self.channel.write('set system login user {username} \ - authentication plain-text-password\n'.format(username=username)) - i = self.channel.expect([r"New password:", r"%s" % self.prompt], timeout=self.timeout) - result = i[-1] - if re.search('error|invalid', result, flags=re.IGNORECASE): - # command failure - raise ForwardError(result) - # Enter password - self.channel.write("{password}\n".format(password=password)) - # check password - i = self.channel.expect([r"Retype new password:", r"%s" % self.prompt], timeout=self.timeout) - if i[0] == 0: - # repassword - self.channel.write("{password}\n".format(password=password)) - # check password - i = self.channel.expect([r"%s" % self.prompt], timeout=self.timeout) - if i[0] == 0: - # Get result. - result = i[-1] - if re.search('error|invalid', result, flags=re.IGNORECASE): - raise ForwardError(result) - else: - # change password is successed. - data = self._commit() - # exit config terminal mode. - self._exitConfigMode() - elif i[0] == -1: - raise ForwardError('Error: receive timeout') - elif i[0] == 1: - # password wrong - raise ForwardError(i[-1]) - elif i[0] == -1: - # timeout - raise ForwardError('Error: receive timeout') - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - # def bindBandwidth(self, ip='', bandwidth=''): - # njInfo = {"status": False, - # "content": "", - # "errLog": ""} - # mx960Bandwidth = Bandwidth(ip=ip, bandwidth=bandwidth, shell=self) - # njInfo = mx960Bandwidth.bindBandwidth() - # return njInfo - # - # def deleteBindIPAndBandwidth(self, ip='', bandwidth=''): - # njInfo = {"status": False, - # "content": "", - # "errLog": ""} - # mx960Bandwidth = Bandwidth(ip=ip, bandwidth=bandwidth, shell=self) - # njInfo = mx960Bandwidth.deleteBindIPAndBandwidth() - # return njInfo - def generalMode(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position before switch to general mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode > 1: - tmp = self.command("quit", prompt={"success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+"}) - if tmp["state"] == "success": - result["status"] = True - self.mode = 1 - return result - else: - result["errLog"] = tmp["errLog"] - return result - else: - result["status"] = True - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # devices of Juniper have no config-mode. - self.mode = 2 - result["status"] = True - return result - - def configMode(self): - # Switch to config mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("configure", prompt={"success": "[\r\n]+\S+# ?$", - "error": "unknown command[\s\S]+\S+> ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.configMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("commit", - prompt={"success": "complete[\s\S]+[\r\n]+\S+# ?$", - "error": "unknown command[\s\S]+"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - else: - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def showVersion(self): - # All the show commands must be done in general mode. - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - cmd = "show version" - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Base OS boot (\S+)", result["content"]) - if tmp: - njInfo["content"] = tmp.group(1).strip("[]") - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - # Get the interface information - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - cmd = "show interfaces extensive" - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall("[\S\s]+?\r\n\r\n", result["content"]) - for line in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - tmp = re.search("interface:? (\S+)", line) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip(",") - else: - continue - # Get line state of the interface. - tmp = re.search("link is (.*)", line) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip().lower() - # Get the admin state of the interface. - tmp = re.search(", (.+), Physical", line) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip().lower() - # Get mtu of the interface. - tmp = re.search("MTU: (\d+)", line) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search("Hardware address: (.*)", line) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get the type of the interface. - tmp = re.search("Link-level type: ([A-Za-z]+)", line) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - # Get input rate of the interface. - tmp = re.search("Input rate : (.*)", line) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Get output rate of the interface. - tmp = re.search("Output rate : +(.*)", line) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - # Get description of the interface. - tmp = re.search("Description: (.*)", line) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # Get duplex of therface. - tmp = re.search("([A-Za-z]+)\-duplex", line) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Get speed of the interface. - tmp = re.search("Speed: (\S+),", line) - if tmp: - lineInfo["speed"] = tmp.group(1) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - cmd = "show route" - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - # Get name of routes. - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = result["content"].split("\r\n")[1:-1] - for line in allLine: - tmp = re.search("(\d+\.\d+\.\d+\.\d+)/(\d{1,2}).*\[([A-Za-z]+)/.*\]", line) - if tmp: - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": ""} - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["type"] = tmp.group(3).lower() - njInfo["content"].append(lineInfo) - tmp = re.findall("(\d+\.\d+\.\d+\.\d+)? ?via (.*)", line) - if tmp: - lineInfo = njInfo["content"][-1] - lineInfo["via"] = tmp[0][0] - lineInfo["interface"] = tmp[0][1] - if njInfo["content"][-1]["via"] == "": - njInfo["content"][-1] = lineInfo - else: - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Get SNMP informatinos. - njInfo = { - "status": False, - # [{"ip:"10.1.1.1","port":"456"}] - "content": [], - "errLog": "" - } - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command("show configuration snmp ", prompt=prompt) - if result["state"] == "success": - # Separate information from each configuration section - allSection = re.findall("trap-group[\s\S]+?\r\n\}", result["content"]) - # everyone of configuration. - for section in allSection: - # Get port of the snmp server. - tmp = re.search("destination-port (\d+)", section) - if tmp: - port = tmp.group(1) - else: - port = "" - # Get ip of the snmp server. - ip = re.findall("\d+\.\d+\.\d+\.\d+", section) - for address in ip: - lineInfo = {"ip": address, "port": port} - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show configuration | display set | match ntp" - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show configuration | display set | match syslog" - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("syslog host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = list(set(sorted(tmp))) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show configuration | display set | match vlan-id " - # Before you execute the show command, you must go into general mode - tmp = self.generalMode() - if tmp["status"] is False: - return tmp - prompt = { - "success": "[\r\n]+\S+> ?$", - "error": "unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _vlanInfo in result["content"].split("\r\n"): - tmp = re.search("vlan-id ([0-9]+)", _vlanInfo) - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - # Get id of the vlan. - if tmp: - lineInfo["id"] = tmp.group(1) - if lineInfo in njInfo["content"]: - # If the record already exists in njinfo, it is ignored - continue - else: - njInfo["content"].append(lineInfo) - continue - # Get range of the vlans. - vlanGroup = re.search("vlan-id-list (\d+)\-(\d+)", _vlanInfo) - if vlanGroup: - # The starting id of the vlan. - startVlan = int(vlanGroup.group(1)) - # The ending id of the vlan. - endVlan = int(vlanGroup.group(2)) - for vlanId in range(startVlan, endVlan + 1): - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - lineInfo["id"] = str(vlanId) - if lineInfo in njInfo["content"]: - # If the record already exists in njinfo, it is ignored - continue - else: - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show system uptime"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Unrecognized command|Invalid command|unknown command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" up .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showVRRP(self, cmd="show vrrp"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - for line in result["content"].split("\r\n"): - dataLine = line.split() - try: - if len(dataLine) == 2: - njInfo["content"][-1]["type"] += "/" + dataLine[0] - njInfo["content"][-1]["address"] += "/" + dataLine[1] - continue - njInfo["content"].append({ - "vr-state": dataLine[3], - "vr-mode": dataLine[4], - "timer": dataLine[5] + dataLine[6], - "type": dataLine[7], - "interface": dataLine[0], - "group": dataLine[2], - "prio": "", - "p": "", - "state": dataLine[1], - "active": "", - "standby-addr": "", - "group-addr": "", - "address": dataLine[8]} - ) - - except Exception: - pass - return njInfo - - def showBGP(self, cmd="show bgp neighbor"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "[\r\n]+\S+(>|\]|#) ?$", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd, prompt) - for dataLine in re.findall("Peer[\s\S]+?Queue", result["content"]): - data = {"description": "", - "state": "", - "type": "", - "last-error": "", - "last-state": "", - "last-event": "", - "peer-id": "", - "local-id": "", - "keepalive-interval": "", - "local": "", - "peer": ""} - tmp = re.search(" Description: (.*)", dataLine) - if tmp: - data["description"] = tmp.group(1).strip() - tmp = re.search(" State: ([\S]+)", dataLine) - if tmp: - data["state"] = tmp.group(1).strip() - tmp = re.search(" Type: ([\S]+)", dataLine) - if tmp: - data["type"] = tmp.group(1).strip() - tmp = re.search(" Last Error: ([\S]+)", dataLine) - if tmp: - data["last-error"] = tmp.group(1).strip() - tmp = re.search(" Last State: ([\S]+)", dataLine) - if tmp: - data["last-state"] = tmp.group(1).strip() - tmp = re.search("Last Event: (.*)", dataLine) - if tmp: - data["last-event"] = tmp.group(1).strip() - tmp = re.search("Peer: ([\S]+)", dataLine) - if tmp: - data["peer"] = tmp.group(1).strip() - tmp = re.search(" Local: ([\S]+)", dataLine) - if tmp: - data["local"] = tmp.group(1).strip() - tmp = re.search(" Peer ID: ([\S]+)", dataLine) - if tmp: - data["peer-id"] = tmp.group(1).strip() - tmp = re.search(" Local ID: ([\S]+)", dataLine) - if tmp: - data["local-id"] = tmp.group(1).strip() - tmp = re.search(" Keepalive Interval: ([0-9]+)", dataLine) - if tmp: - data["keepalive-interval"] = tmp.group(1).strip() - njInfo["content"].append(data) - return njInfo - - def showRun(self): - cmd = " show configuration" - tmp = self.generalMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+(#|>|\]) ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo diff --git a/lib/forward/devclass/baseLinux.py b/lib/forward/devclass/baseLinux.py index 520c329..49dab84 100644 --- a/lib/forward/devclass/baseLinux.py +++ b/lib/forward/devclass/baseLinux.py @@ -1,23 +1,12 @@ -# coding:utf-8 +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Base device class for sshv2 method, by using paramiko module. +Author: Wangzhe """ import re @@ -29,163 +18,4 @@ class BASELINUX(BASESSHV2): """This is a manufacturer of linux, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def privilegeMode(self): - """Used to switch from normal mode to privileged mode for command line mode. - Does not apply to other modes to switch to privileged mode. - """ - result = { - 'status': True, - 'content': '', - 'errLog': '' - } - return result - - def addUser(self, username, password, **kwargs): - """Create a user on the device. - """ - # Extra parameters - group = kwargs['group'] if 'group' in kwargs else username - commandAdduser = 'adduser %s' % username if group == username else 'adduser --gid %s %s' % (group, username) - commandPw = 'passwd %s\n' % username - - result = { - "status": False, - "content": "", - "errLog": "" - } - try: - # legal check - if not group: - raise ForwardError("[Add User Error]: %s: Group could NOT be blank." % self.ip) - if not username or not password: - raise ForwardError("[Add User Error]: %s: Username or Password could NOT be blank." % self.ip) - - if self.isLogin: - # execute adduser - addUserResult = self.execute(commandAdduser) - if addUserResult['status']: - dirExtPattern = '(目录已经存在|home directory already exists)' - - if not addUserResult['content']: - # success - pass - elif re.search(dirExtPattern, addUserResult['content']): - # success, but homedir already exist - pass - else: - # other errors - raise ForwardError("[Add User Error]: %s: %s" % (self.ip, addUserResult['content'])) - - # set passwd - self.shell.send(commandPw) - buff = '' - while not (re.search(self.basePrompt, buff) or re.search('New password:', buff)): - buff += self.shell.recv(256) - if re.search('New password:', buff): - # send password - self.shell.send(password + '\n') - buff = '' - while not (re.search(self.basePrompt, buff) or re.search('Retype new password:', buff)): - buff += self.shell.recv(256) - if re.search('Retype new password:', buff): - # Confirm password - self.shell.send(password + '\n') - buff = '' - while not re.search(self.prompt, buff): - buff += self.shell.recv(256) - # successed. - if re.search('updated successfully', buff): - result['status'] = True - return result - - # error somewhere, raise - raise ForwardError("[Set Password Error]: %s: %s" % (self.ip, buff)) - else: - raise ForwardError("[Add User Error]: %s: %s" % (self.ip, addUserResult['errLog'])) - else: - raise ForwardError("[Add User Error]: %s: Not login yet." % self.ip) - except ForwardError, e: - result['status'] = False - result['errLog'] = str(e) - return result - - def deleteUser(self, username): - """Delete a user on the device - """ - # set command - commandDelUser = 'userdel %s' % username - result = { - "status": False, - "content": "", - "errLog": "" - } - try: - if not username: - raise ForwardError("[Delete User Error]: %s: Username could NOT be blank." % self.ip) - # Login status check. - if self.isLogin: - # send command. - delUserResult = self.execute(commandDelUser) - if delUserResult['status']: - if not delUserResult['content']: - # success - pass - else: - # failed. - raise ForwardError("[Delete User Error]: %s: %s" % (self.ip, delUserResult['content'])) - result['status'] = True - return result - else: - raise ForwardError("[Delete User Error]: %s: %s" % (self.ip, delUserResult['errLog'])) - else: - raise ForwardError("[Delete User Error]: %s: Not login yet." % self.ip) - except ForwardError, e: - result['status'] = False - result['errLog'] = str(e) - return result - - def basicInfo(self, cmd="uptime"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(command not found|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - runningDate = -1 - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" up .+(day|year|week).*", result["content"], flags=re.IGNORECASE) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - return njInfo + pass diff --git a/lib/forward/devclass/baseMaipu.py b/lib/forward/devclass/baseMaipu.py index 9fc1765..a84df35 100644 --- a/lib/forward/devclass/baseMaipu.py +++ b/lib/forward/devclass/baseMaipu.py @@ -1,466 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Maipu. +Author: Cheung Kei-chuen """ from forward.devclass.baseSSHV1 import BASESSHV1 -import re class BASEMAIPU(BASESSHV1): """This is a manufacturer of maipu, using the SSHV1 version of the protocol, so it is integrated with BASESSHV1 library. """ - def __init__(self, *args, **kws): - """Since the device's host prompt is different from BASESSHV1, - the basic prompt for the device is overwritten here. - """ - BASESSHV1.__init__(self, *args, **kws) - self.moreFlag = re.escape('....press ENTER to next \ -line, Q to quit, other key to next page....') - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$", - "eror": "Unrecognized[\s\S]+"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def configMode(self): - # Switch to config mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$", - "error": "Unrecognized[\s\S]+"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - else: - result["errLog"] = sendConfig["errLog"] - return result - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - prompt = { - "success": "are you sure\(y/n\)\? \[n\]", - "error": "Unrecognized[\s\S]+", - } - # Excute a command. - data = self.command("write running-config startup-config", prompt=prompt) - if data["state"] == "success": - data = self.command("y", prompt={"success": "successfully[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+"}) - if data["state"] == "success": - result["content"] = "The configuration was saved successfully.[%s]" % data["content"] - result["status"] = True - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], - errLog=data["errLog"]) - - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - return result - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Software Version(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.split("show VLAN information", result["content"]) - for line in allLine: - lineInfo = {"id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - "state": ""} - # Get id of the vlan. - tmp = re.search("VLAN ID : (\d+)", line) - if tmp: - lineInfo["id"] = tmp.group(1) - else: - continue - # Get stats of the vlan. - tmp = re.search("VLAN status : ([a-zA-Z]+)", line) - if tmp: - lineInfo["status"] = tmp.group(1) - # Get interfaces of the vlan. - tmp = re.search("VLAN member : (\S+)", line) - if tmp: - # Separate each set of ports with a `,` - _interfaces = tmp.group(1).strip(".").split(",") - for tmpInterface in _interfaces: - _interface = tmpInterface.split("-") - # ['e0/1/2','e0/1/7'] - if len(_interface) == 1: - # e0/1/2 --> 2 --> 3 - tmp = int(_interface[0].split("/")[-1]) + 1 - # e0/1/2 --> e0/1/3 - tmp = "/".join(_interface[0].split("/")[0:-1]) + "/" + str(tmp) - # ['e0/1/2'] -- >['e0/1/2','e0/1/3'] - _interface.append(tmp) - else: - # e0/1/2 --> 2 --> 3 - tmp = int(_interface[-1].split("/")[-1]) + 1 - # e0/1/2 --> e0/1/3 - tmp = "/".join(_interface[0].split("/")[0:-1]) + "/" + str(tmp) - # ['e0/1/2','e0/1/3'] -- >['e0/1/2','e0/1/4'] - _interface[-1] = tmp - # Intercepts the prefix symbol of the port and generates the completed port range - interfacePrefix = "/".join(_interface[0].split("/")[:-1]) - portRange = [int(p.split("/")[-1]) for p in _interface] - for i in range(*portRange): - tmp = interfacePrefix + "/" + str(i) - lineInfo["interface"].append(tmp) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Get SNMP informatinos. - njInfo = { - "status": False, - # [{"ip:"10.1.1.1","port":"456"}] - "content": [], - "errLog": "" - } - result = self.command("show run snmp", prompt={"success": "[\r\n]+\S+(#|>) ?$", - "eror": "Unrecognized[\s\S]+"}) - if result["state"] == "success": - tmp = re.findall("snmp-server host (\d+\.\d+\.\d+\.\d+).*?udp-port (\d+)", - result["content"], flags=re.DOTALL) - """ - snmp-server host ip1 version 2c xxx udp-port 612 notify-ty - snmp-server host ip2 version 2c xxx udp-port 621 notify-ty - """ - if tmp.__len__() > 0: - njInfo["content"] = [{"ip": group[0], "port": group[-1]} for group in tmp] - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - # record the route table. - if re.search("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/[0-9]{1,2}", _interfaceInfo): - lineInfo = { - "net": "", - "mask": "", - "via": "", - "metric": "", - "type": "", - "via": "", - } - # Get net of the routing. - lineInfo["net"] = _interfaceInfo.split("/")[0] - # Get mask of net of the route. - lineInfo["mask"] = _interfaceInfo.split()[0].split("/")[-1] - lineInfo["via"] = _interfaceInfo.split()[1] - lineInfo["interface"] = re.search("[a-zA-z]+.*", _interfaceInfo.split()[-3]).group() - lineInfo["metric"] = re.search("\d+", _interfaceInfo.split()[-2]).group() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - # Get syslog's servers informatinos. - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - result = self.command("show run syslog", prompt={"success": "[\r\n]+\S+(#|>) ?$", - "eror": "Unrecognized[\s\S]+"}) - if result["state"] == "success": - tmp = re.findall("logging (\d+\.\d+\.\d+\.\d+)", - result["content"]) - if tmp.__len__() > 0: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - # Get the interfaces information - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall(".*current state[\s\S]+?unicasts", result["content"]) - for line in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - tmp = re.search("(.*)current state", line) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - # Get line state of the interface. - tmp = re.search("port link is (.*)", line) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - # Get the admin state of the interface. - tmp = re.search("current state:(.*),", line) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search("Hardware address is (.*)", line) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get the type of the interface. - tmp = re.search("Current port type: (\S+)", line) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - # Get the speed of the interface. - tmp = re.search("ActualSpeed is (\S+),", line) - if tmp: - lineInfo["speed"] = tmp.group(1) - # Get duplex of the interface. - tmp = re.search("Duplex mode is (\S+)", line) - if tmp: - lineInfo['duplex'] = tmp.group(1).strip() - # Get input rate of the interface. - tmp = re.search("Input : (.*)", line) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Get output rate of the interface. - tmp = re.search("Output : (.*)", line) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - # Gets the NTP server address of the device - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config | include ntp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server.*([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "([Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search("[Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseRaisecom.py b/lib/forward/devclass/baseRaisecom.py index b46f239..8b230e6 100644 --- a/lib/forward/devclass/baseRaisecom.py +++ b/lib/forward/devclass/baseRaisecom.py @@ -1,422 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Raisecom. +Author: Cheung Kei-Chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -import re class BASERAISECOM(BASESSHV2): """This is a manufacturer of raisecom, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write", - prompt={"success": "successfully[\s\S]+[\r\n]+# ?$"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - else: - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def configMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config | include ntp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show running-config | include log''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("logging host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include "snmp-server host"''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[vV]ersion[\s\S]+[\r\n]+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("(software|system).*version:?(.*)", result["content"], flags=re.IGNORECASE) - if tmp.lastindex == 2: - njInfo["content"] = tmp.group(2).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Error input[\s\S]+", - } - """ - State Status Priority Member-Ports VLAN Name - ------------------------------------------------------------------------------- - 160 active static -- P 49-50 VLAN0160 - 164 active static -- P 1-36,49-50 VLAN0164 - """ - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - if re.search("\-\-\-\-", _interfaceInfo): - continue - if re.search("^[0-9]", _interfaceInfo): - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - "state": "", - } - tmp = re.search("[0-9]+", _interfaceInfo) - if tmp: - _line = _interfaceInfo.split() - lineInfo["id"] = _line[0] - lineInfo["state"] = _line[1] - lineInfo["status"] = _line[2] - # Example: "1-2,49-50,60" - for i in _line[5].split(","): - seg = i.split("-") - seg = [int(x) for x in seg] - if len(seg) == 1: - seg.append(seg[-1] + 1) - else: - seg[-1] = seg[-1] + 1 - # [1,2,49,50,60] - lineInfo["interface"].extend(range(*seg)) - lineInfo["description"] = _line[6] - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config | include route" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Error input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - # record the route table. - if re.search("[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+", _interfaceInfo): - '''try: - """Store the previously acquired routing information - before processing the new routing information""" - njInfo["content"].append(lineInfo) - except Exception: - pass''' - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - # Get net of the route. - lineInfo["net"] = _interfaceInfo.split()[2] - # Get mask of net of the route. - lineInfo["mask"] = _interfaceInfo.split()[3] - lineInfo["via"] = _interfaceInfo.split()[4] - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show running-config | include interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Error input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in result["content"].split("\r\n"): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface - tmp = re.search("interface port ([0-9]+)", _interfaceInfo) - if not tmp: - continue - port = tmp.group(1) - lineInfo["interfaceName"] = port - # Get the interface used to get the details of the interface. - detail = self.command(cmd="show interface port-list {port}".format(port=port), prompt=prompt) - # Obtain rows with detailed information. - tmp = re.search("P{port}.*".format(port=port), detail["content"]) - if tmp: - _line = tmp.group().split() - lineInfo["adminState"] = _line[1] - lineInfo["spped"] = _line[3] - lineInfo["duplex"] = _line[4] - lineInfo["lineState"] = _line[6] - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "([Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search("[Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseRuijie.py b/lib/forward/devclass/baseRuijie.py index fa2d450..7ec92b4 100644 --- a/lib/forward/devclass/baseRuijie.py +++ b/lib/forward/devclass/baseRuijie.py @@ -1,22 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for Ruijie. +Author: Cheung Kei-Chuen """ import re from forward.devclass.baseSSHV2 import BASESSHV2 @@ -27,550 +15,20 @@ class BASERUIJIE(BASESSHV2): """This is a manufacturer of maipu, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def __init__(self, *args, **kws): - """Since the device's host prompt is different from BASESSHV2, - the basic prompt for the device is overwritten here. - """ - BASESSHV2.__init__(self, *args, **kws) - self.basePrompt = r'(>|#) *$' - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write", - prompt={"success": "\[OK\][\s\S]+[\r\n]+\S+(>|#) ?$", - "error": "Unknown command[\s\S]+[\r\n]+\S+(>|#).*(>|#) ?$"}) - if data["state"] == "success": - result["content"] = "The configuration was saved successfully." - result["status"] = True - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - return result - - def configMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", - prompt={"success": "[\r\n]+\S+\(config\)# ?$", - "error": "Unknown command[\s\S]+[\r\n]+\S+(>|#) ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - else: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "(#|>)"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+(#|>|\]|\$) ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = sendEnable["errLog"] - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+(#|>|\]|\$) ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include ntp''' - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include logging''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = result["content"].split("\r\n") - for line in allLine: - if re.search("logging server", line): - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if len(tmp) > 0: - njInfo["content"].extend(tmp) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include snmp''' - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Software version : (.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(>|#|\$) *$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - currentSection = "vlanName" - isContinueLine = False - for _vlanInfo in result["content"].split("\r\n"): - _vlanInfo = _vlanInfo.strip() - if re.search("\-\-\-\-", _vlanInfo): - continue - if re.search("^[0-9]", _vlanInfo) and currentSection == "vlanName": - isContinueLine = True - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - tmp = re.search("([0-9]+)\s+(\S+)\s+(\S+)(.*)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["description"] = tmp.group(2) - lineInfo["status"] = tmp.group(3) - if tmp.lastindex == 4: - lineInfo["interface"] = tmp.group(4).split(", ") - njInfo["content"].append(lineInfo) - elif isContinueLine is True: - for _interface in _vlanInfo.split(", "): - lineInfo = njInfo["content"].pop() - lineInfo["interface"].append(_interface.strip()) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - via = re.search("via ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", _interfaceInfo) - if via: - lineInfo["via"] = via.group(1) - # Match the route table - tmp = re.search("([A-Za-z0-9])\*? +([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - if tmp: - _type = tmp.group(1) - if _type == "C": - _type = "connected" - elif _type == "S": - _type = "static" - elif _type == "R": - _type = "rip" - elif _type == "O": - _type = "ospf" - elif _type == "K": - _type = "kernel" - elif _type == "I": - _type = "isis" - elif _type == "B": - _type = "bgp" - elif _type == "G": - _type == "guard" - elif _type == "*": - _type = "fib" - else: - _type = "default" - lineInfo["type"] = _type - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("========================== ", result["content"])[1::] - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - lineInfo['interfaceName'] = re.search("(.*) ========================", _interfaceInfo).group(1) - tmp = re.search("\d+(/\d+)? is (.*), line protocol", _interfaceInfo) - if tmp: - if tmp.lastindex == 1: - lineInfo["interfaceState"] = tmp.group(1).strip() - else: - lineInfo["interfaceState"] = tmp.group(2).strip() - tmp = re.search("Interface address is:(.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).strip() - tmp = re.search("line protocol is (.*)", _interfaceInfo) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - tmp = re.search("MTU (\d+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - tmp = re.search("Port-type: (.*)", _interfaceInfo) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - tmp = re.search("input rate (\d+)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - tmp = re.search("output rate (\d+)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - tmp = re.search("duplex is (.*)", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1).strip() - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - tmp = re.search("oper speed is (.*)", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo def cleanBuffer(self): """Because the device USES the cleanBuffer method in different details, it can be rewritten to modify the function. """ if self.shell.recv_ready(): - self.shell.recv(4096).decode() - # Ruijie equipment does not support sending line, must sent some space characters to device. + self.shell.recv(4096) + # Ruijie equipment does not support sending line, must be sent to some characters self.shell.send(' \n') buff = '' # When after switching mode, the prompt will change, it should be based on basePrompt to check and at last line while not re.search(self.basePrompt, buff.split('\n')[-1]): try: # Accumulative results - buff += self.shell.recv(1024).decode() + buff += self.shell.recv(1024) except Exception: raise ForwardError('[Clean Buffer Error]: %s: Receive timeout [%s]' % (self.ip, buff)) - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} doest not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, name="None"): - """ - @param vlan_id: vlan-id, - @param name: name of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "vlan {vlan_id}\rname {name}".format(vlan_id=vlan_id, name=name) - prompt = { - "success": "[\r\n]+\S+config\-vlan\)(#|>) ?$", - "error": "Invalid[\s\S]+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success": - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Delete vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "no vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.vlanExist(vlan_id)["status"]: - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid input|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search("[Uu]ptime +: +([0-9]+).*", result["content"]) - if dataLine is not None: - runningDate = int(dataLine.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo diff --git a/lib/forward/devclass/baseRuijieV1.py b/lib/forward/devclass/baseRuijieV1.py deleted file mode 100644 index b703242..0000000 --- a/lib/forward/devclass/baseRuijieV1.py +++ /dev/null @@ -1,577 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Device class for Ruijie. -""" -import re -import pexpect -from forward.devclass.baseSSHV1 import BASESSHV1 -from forward.utils.forwardError import ForwardError - - -class BASERUIJIE(BASESSHV1): - """This is a manufacturer of maipu, using the - SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. - """ - - def __init__(self, *args, **kws): - """Since the device's host prompt is different from BASESSHV2, - the basic prompt for the device is overwritten here. - """ - BASESSHV1.__init__(self, *args, **kws) - self.basePrompt = r'(>|#) *$' - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write", - prompt={"success": "\[OK\][\s\S]+[\r\n]+\S+(>|#) ?$", - "error": "Unknown command[\s\S]+[\r\n]+\S+(>|#).*(>|#) ?$"}) - if data["state"] == "success": - result["content"] = "The configuration was saved successfully." - result["status"] = True - else: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - return result - - def configMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", - prompt={"success": "[\r\n]+\S+\(config\)# ?$", - "error": "Unknown command[\s\S]+[\r\n]+\S+(>|#) ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - else: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "(#|>)"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+(#|>|\]|\$) ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+(#|>|\]|\$) ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include ntp''' - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("ntp server ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include logging''' - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = result["content"].split("\r\n") - for line in allLine: - if re.search("logging server", line): - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - if len(tmp) > 0: - njInfo["content"].extend(tmp) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = '''show run | include snmp''' - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVersion(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("Software version : (.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(>|#|\$) *$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - currentSection = "vlanName" - isContinueLine = False - for _vlanInfo in result["content"].split("\r\n"): - _vlanInfo = _vlanInfo.strip() - if re.search("\-\-\-\-", _vlanInfo): - continue - if re.search("^[0-9]", _vlanInfo) and currentSection == "vlanName": - isContinueLine = True - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - tmp = re.search("([0-9]+)\s+(\S+)\s+(\S+)(.*)", _vlanInfo) - if tmp: - lineInfo["id"] = tmp.group(1) - lineInfo["description"] = tmp.group(2) - lineInfo["status"] = tmp.group(3) - if tmp.lastindex == 4: - lineInfo["interface"] = tmp.group(4).split(", ") - njInfo["content"].append(lineInfo) - elif isContinueLine is True: - for _interface in _vlanInfo.split(", "): - lineInfo = njInfo["content"].pop() - lineInfo["interface"].append(_interface.strip()) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - tmp = re.search("([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - if tmp: - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - via = re.search("via ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", _interfaceInfo) - if via: - lineInfo["via"] = via.group(1) - # Match the route table - tmp = re.search("([A-Za-z0-9])\*? +([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - if tmp: - _type = tmp.group(1) - if _type == "C": - _type = "connected" - elif _type == "S": - _type = "static" - elif _type == "R": - _type = "rip" - elif _type == "O": - _type = "ospf" - elif _type == "K": - _type = "kernel" - elif _type == "I": - _type = "isis" - elif _type == "B": - _type = "bgp" - elif _type == "G": - _type == "guard" - elif _type == "*": - _type = "fib" - else: - _type = "default" - lineInfo["type"] = _type - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>|\]) ?$", - "error": "Unrecognized[\s\S]+", - } - # Before you execute the show command, you must go into privilege mode - tmp = self.privilegeMode() - if tmp["status"] is False: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - interfacesFullInfo = re.split("========================== ", result["content"])[1::] - for _interfaceInfo in interfacesFullInfo: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - lineInfo['interfaceName'] = re.search("(.*) ========================", _interfaceInfo).group(1) - tmp = re.search("\d+(/\d+)? is (.*), line protocol", _interfaceInfo) - if tmp: - if tmp.lastindex == 1: - lineInfo["interfaceState"] = tmp.group(1).strip() - else: - lineInfo["interfaceState"] = tmp.group(2).strip() - tmp = re.search("Interface address is:(.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).strip() - tmp = re.search("line protocol is (.*)", _interfaceInfo) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - tmp = re.search("MTU (\d+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - tmp = re.search("Port-type: (.*)", _interfaceInfo) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - tmp = re.search("input rate (\d+)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - tmp = re.search("output rate (\d+)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - tmp = re.search("duplex is (.*)", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1).strip() - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - tmp = re.search("oper speed is (.*)", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def cleanBuffer(self): - """Because the device USES the cleanBuffer method in different details, - it can be rewritten to modify the function. - """ - # Ruijie equipment does not support sending line, must sent some space characters to device. - self.channel.send('\n') - try: - """When after switching mode, the prompt will change, it should be based - on basePrompt to check and at last line - """ - return self.channel.expect(self.basePrompt, timeout=self.timeout) - except pexpect.TIMEOUT: - # No legacy data. - return '' - - def vlanExist(self, vlan_id): - # Check if the vlan exists. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - vlan_list = self.showVlan() - # check - if not vlan_list["status"]: - return vlan_list - for line in vlan_list["content"]: - if vlan_id == line["id"]: - result["status"] = True - return result - result["errLog"] = "Vlan {vlan_id} doest not exist.".format(vlan_id=vlan_id) - return result - - def createVlan(self, vlan_id, description="None"): - """ - @param vlan_id: vlan-id, - @param description: description of vlan. - - """ - # Crate vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - vlan_id = str(vlan_id) - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "vlan {vlan_id}\rname {description}".format(vlan_id=vlan_id, description=description) - prompt = { - "success": "[\r\n]+\S+config\-vlan\)(#|>) ?$", - "error": "Invalid[\s\S]+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if tmp["state"] == "success": - # The vlan was created successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was created.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = tmp["content"] - return result - - def deleteVlan(self, vlan_id): - # Delete vlan. - result = { - "status": False, - "content": {}, - "errLog": "" - } - # Enter config-mode. - tmp = self.configMode() - if not tmp["status"]: - # Failed to enter configuration mode - return tmp - cmd = "no vlan {vlan_id}".format(vlan_id=vlan_id) - prompt = { - "success": "[\r\n]+\S+config\)(#|>) ?$", - } - tmp = self.command(cmd, prompt=prompt) - if not self.vlanExist(vlan_id)["status"]: - # The vlan was deleted successfuly, then to save configration if save is True. - result["content"] = "The vlan {vlan_id} was deleted.".format(vlan_id=vlan_id) - result["status"] = True - return result - else: - result["errLog"] = "The vlan {vlan_id} was not deleted.".format(vlan_id=vlan_id) - return result - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Invalid input|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search("[Uu]ptime +: +([0-9]+).*", result["content"]) - if dataLine is not None: - runningDate = int(dataLine.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo diff --git a/lib/forward/devclass/baseSSHV1.py b/lib/forward/devclass/baseSSHV1.py index 90911b8..d43d6ef 100644 --- a/lib/forward/devclass/baseSSHV1.py +++ b/lib/forward/devclass/baseSSHV1.py @@ -1,20 +1,7 @@ +#!/usr/bin/evn python # coding:utf-8 # -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# +# (c) 2017, Azrael """ -----Introduction----- @@ -44,12 +31,9 @@ def __init__(self, ip, username, password, **kwargs): self.channel = '' self.shell = '' - # self.basePrompt = r'(>|#|\]|\$|\)) *$' - # Multiple identical characters may appear - self.basePrompt = r"(>|#|\]|\$) *$" + self.basePrompt = r'(>|#|\]|\$|\)) *$' self.prompt = '' - self.moreFlag = '(< *)?(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+( *>)?|\(Q to quit\)' - self.mode = 1 + self.moreFlag = '(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+' """ - parameter ip: device's ip @@ -109,7 +93,7 @@ def logout(self): # Modify login status to False. self.isLogin = False result['status'] = True - except Exception as e: + except Exception, e: # If the close fails, set the login status to False and record the failure message result['status'] = False result['errLog'] = str(e) @@ -127,7 +111,7 @@ def execute(self, cmd): # Remove legacy data from the SSH before executing the command. self.cleanBuffer() # dataPattern = re.escape(cmd)+'.*\r\n([\s\S]*)\r\n'+self.prompt - dataPattern = '[\r\n]+([\s\S]*)[\r\n]+(\x1b\[m)?' + dataPattern = '[\r\n]+([\s\S]*)[\r\n]+' # SSHV1 pexpect not have self.prompt end data = {'status': False, 'content': '', @@ -159,10 +143,8 @@ def execute(self, cmd): tmp = re.search(dataPattern, data['content']).group(1) # Delete special characters caused by More split screen. tmp = re.sub("<--- More --->\\r +\\r", "", tmp) - tmp = re.sub('(\x00|\x08){0,}', "", tmp) - tmp = re.sub(re.escape("--More(CTRL+Cbreak)--"), "", tmp) data['content'] = tmp - except Exception as e: + except Exception, e: # Unable to find the host prompt, command execution failed. data['status'] = False data['errLog'] = data['errLog'] + "not fond host prompt:Error(%s)" % str(e) @@ -232,7 +214,6 @@ def getPrompt(self): """ if self.isLogin: # login status True - self.cleanBuffer() self.channel.send('\n') """The host base prompt is the end of the received flag, and if the data is not received at the set time, the timeout is exceeded. @@ -244,15 +225,9 @@ def getPrompt(self): # [ex]'[localhost@labstill019~]' # self.prompt=self.prompt[1:-1] # [ex]'\\[localhost\\@labstill019\\~\\]$' - self.prompt = self.channel.before.split('\n')[-1] + self.channel.after + self.prompt = self.channel.before.split('\n')[-1] + "(>|#|\$|\]|\)) *$" else: raise ForwardError('[Get Prompt Error]: %s: Not login yet.' % self.ip) - if re.search("> ?$", self.prompt): - # If last character of host prompt of the device ens in '>', the command line of device in gneral mode. - self.mode = 1 - elif re.search("(#|\]) ?$", self.prompt): - # If last character of host prompt of the device ens in '#', the command line of device in enable mode. - self.mode = 2 return self.prompt def cleanBuffer(self): @@ -263,7 +238,7 @@ def cleanBuffer(self): """When after switching mode, the prompt will change, it should be based on basePrompt to check and at last line """ - return self.channel.expect(self.basePrompt, timeout=self.timeout) + return self.channel.expect(self.prompt, timeout=self.timeout) except pexpect.TIMEOUT: # No legacy data. return '' @@ -272,78 +247,70 @@ def command(self, cmd=None, prompt=None, timeout=30): """execute a command line, powerful and suitable for any scene, but need to define whole prompt dict list """ - # regx compile - """_promptKey = prompt.keys() - for key in _promptKey: - prompt[key] = re.compile(prompt[key]) - In SSHV1, regular expressions cannot be compiled - """ result = { - 'status': False, + 'status': True, 'content': '', 'errLog': '', "state": None } - if self.isLogin is False: - result['errLog'] = '[Execute Error]: device not login.' # Parameters check - parameterFormat = { - "success": "regular-expression-success", - "error": "regular-expression-error" - } - if (cmd is None) or (not isinstance(prompt, dict)) or (not isinstance(timeout, int)): - raise ForwardError("You should given a parameter for prompt such as: %s" % (str(parameterFormat))) + if (cmd is None) or (not isinstance(prompt, list)) or (not isinstance(timeout, int)): + raise ForwardError("""You should pass such a form of argument: \ +CMD = 'Your command', prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}] ,\ +timeout=30""") + for section in prompt: + if not isinstance(section.values(), list): + raise ForwardError("""you should pass such a form of argument:\ +prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}]""") try: - # send a command self.channel.send("{cmd}\r".format(cmd=cmd)) - except Exception: - # break, if faild - result["errLog"] = "Forward had sent a command failure." - return result - - while True: - i = self.channel.expect([r'%s' % self.moreFlag, - # prompt-1 - r"%s" % prompt.items()[0][1], - # prompt-2 - r"%s" % prompt.items()[1][1], - pexpect.TIMEOUT], timeout=timeout) - result["content"] += self.channel.before - if i == 3: - """The host prompt is not finished with the traditional # $ > - and you need to set it like that. - """ - result["errLog"] = '[Forward Error]: receive timeout,prompt is invalid.' - return result - if i == 1: - # Find the prompt-1 - result["state"] = prompt.items()[0][0] - # Matching page break - if re.search(self.moreFlag, result["content"].split("\r\n")[-1]): - continue - else: - break - if i == 2: - # Find the prompt-2 - result["state"] = prompt.items()[1][0] - # Matching page break - if re.search(self.moreFlag, result["content"].split("\r\n")[-1]): - continue - else: - break - if i == 0: - # Get More then result - self.channel.send(" ") - result["status"] = True - # Replenish prompt - result["content"] += self.channel.after - # Delete page break - result["content"] = re.sub("\r\n.*?\r *?\r", "\r\n", result["content"]) - # Delete special characters caused by More split screen. - result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) - # remove the More charactor - result["content"] = re.sub(' \-\-More\(CTRL\+C break\)\-\- (\x00|\x08){0,} +(\x00|\x08){0,}', "", - result["content"]) - # remove the space key - result["content"] = re.sub("(\x08)+ +", "", result["content"]) + try: + info = '' + while True: + """ First, the program accepts the return message based on the base prompt, and if program + accept it directly from the specified prompt, there will be many times out of time in the + middle,resulting in reduced efficiency""" + i = self.channel.expect([r'%s' % self.moreFlag, r"%s" % self.basePrompt, + pexpect.TIMEOUT], timeout=timeout) + if i == 2: + """The host prompt is not finished with the traditional # $ > + and you need to set it like that. + """ + raise ForwardError('Error: base prompt receive timeout') + if i == 0: + info += self.channel.before + # Get More then result + tmp = self.newGetMore(prompt, timeout) + info += tmp[0] + result["state"] = tmp[1] + # To complete the receiving + break + else: + # To complete the receiving + info += self.channel.before + # read base prompt + info += self.channel.after + for section in prompt: + # section.values() is : [ [p1,p2,p3] ] + for _prompt in section.values()[0]: + if re.search(_prompt, info.split("\n")[-1]): + result["state"] = section.keys()[0] + break + # Find the specified state type + if not result["state"] is None: + break + # Find the specified state type,exit + if not result["state"] is None: + break + result['content'] += info + # Delete special characters caused by More split screen. + result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) + except Exception, e: + # If program accept a timeout, cancel SSH + self.logout() + raise ForwardError(str(e)) + except Exception, e: + # Program run failed + result["errLog"] = str(e) + result["status"] = False return result diff --git a/lib/forward/devclass/baseSSHV2.py b/lib/forward/devclass/baseSSHV2.py index 02054fb..a95c0f8 100644 --- a/lib/forward/devclass/baseSSHV2.py +++ b/lib/forward/devclass/baseSSHV2.py @@ -1,20 +1,7 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- # +# (c) 2017, Azrael """ -----Introduction----- @@ -44,12 +31,9 @@ def __init__(self, ip, username, password, **kwargs): self.channel = '' self.shell = '' - # self.basePrompt = r'(>|#|\]|\$|\)) *$' - # Multiple identical characters may appear - self.basePrompt = "(>|#|\]|\$) *$" + self.basePrompt = r'(>|#|\]|\$|\)) *$' self.prompt = '' - self.moreFlag = '(< *)?(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+( *>)?|\(Q to quit\)' - self.mode = 1 + self.moreFlag = '(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+' """ - parameter ip: device's ip @@ -86,11 +70,11 @@ def login(self): while ( not re.search(self.basePrompt, tmpBuffer.split('\n')[-1]) ) and ( - not re.search('(new +password)|(password.*change)', tmpBuffer.split('\n')[-1], flags=re.IGNORECASE) + not re.search('new +password', tmpBuffer.split('\n')[-1], flags=re.IGNORECASE) ): tmpBuffer += self.shell.recv(1024) # if prompt is 'New Password' ,raise Error. - if re.search('(new +password)|(password.*change)', tmpBuffer.split('\n')[-1], flags=re.IGNORECASE): + if re.search('new +password', tmpBuffer.split('\n')[-1], flags=re.IGNORECASE): raise ForwardError( '[Login Error]: %s: Password expired, needed to be updated!' % self.ip ) @@ -131,7 +115,7 @@ def execute(self, cmd): the prompt is equal before and after execution """ result = { - 'status': False, + 'status': True, 'content': '', 'errLog': '' } @@ -141,7 +125,7 @@ def execute(self, cmd): # [ex] when send('ls\r'),get 'ls\r\nroot base etc \r\n[wangzhe@cloudlab100 ~]$ ' # [ex] data should be 'root base etc ' self.shell.send(cmd + "\r") - resultPattern = re.compile('[\r\n]+([\s\S]*)[\r\n]+(\x1b\[m)?' + self.prompt) + resultPattern = '[\r\n]+([\s\S]*)[\r\n]+' + self.prompt try: while not re.search(self.prompt, result['content'].split('\n')[-1]): self.getMore(result['content']) @@ -150,16 +134,11 @@ def execute(self, cmd): tmp = re.search(resultPattern, result['content']).group(1) # Delete special characters caused by More split screen. tmp = re.sub("<--- More --->\\r +\\r", "", tmp) - tmp = re.sub(" *---- More ----\x1b\[42D \x1b\[42D", "", tmp) - # remove the More charactor - tmp = re.sub(' \-\-More\(CTRL\+C break\)\-\- (\x00|\x08){0,} +(\x00|\x08){0,}', "", tmp) - # remove the space key - tmp = re.sub("(\x08)+ +", "", tmp) result['content'] = tmp - result["status"] = True except Exception as e: # pattern not match result['status'] = False + result['content'] = result['content'] result['errLog'] = str(e) else: # not login @@ -171,71 +150,46 @@ def command(self, cmd=None, prompt=None, timeout=30): """execute a command line, powerful and suitable for any scene, but need to define whole prompt dict list """ - # regx compile - _promptKey = prompt.keys() - for key in _promptKey: - prompt[key] = re.compile(prompt[key]) result = { - 'status': False, + 'status': True, 'content': '', 'errLog': '', "state": None } - if self.isLogin is False: - result['errLog'] = '[Execute Error]: device not login.' - return result - # Setting timeout. - self.shell.settimeout(timeout) # Parameters check - parameterFormat = { - "success": "regular-expression-success", - "error": "regular-expression-error" - } - if (cmd is None) or (not isinstance(prompt, dict)) or (not isinstance(timeout, int)): - raise ForwardError("You should given a parameter for prompt such as: %s" % (str(parameterFormat))) - # Clean buffer data. - while self.shell.recv_ready(): - self.shell.recv(1024) + if (cmd is None) or (not isinstance(prompt, list)) or (not isinstance(timeout, int)): + raise ForwardError("""You should pass such a form of argument: \ +CMD = 'Your command', prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}]""") + for section in prompt: + if not isinstance(section.values(), list): + raise ForwardError("""you should pass such a form of argument:\ +prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}]""") try: - # send a command self.shell.send("{cmd}\r".format(cmd=cmd)) - except Exception: - # break, if faild - result["errLog"] = "That forwarder has sent a command is failed." - return result - isBreak = False - while True: - # Remove special characters. - result["content"] = re.sub("", "", result["content"]) - self.getMore(result["content"]) try: - result["content"] += self.shell.recv(204800) - except Exception: - result["errLog"] = "Forward had recived data timeout. [%s]" % result["content"] - return result - # Mathing specify key - for key in prompt: - if re.search(prompt[key], re.sub(self.moreFlag, "", result["content"])): - # Found it - result["state"] = key - isBreak = True - break - # Keywords have been captured. - if isBreak is True: - break - # Delete page break - result["content"] = re.sub("\r\n.*?\r +?\r", "\r\n", result["content"]) - # Clearing special characters - result["content"] = re.sub(" *---- More ----\x1b\[42D \x1b\[42D", - "", - result["content"]) - result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) - # remove the More charactor - result["content"] = re.sub(' \-\-More\(CTRL\+C break\)\-\- (\x00|\x08){0,} +(\x00|\x08){0,}', "", - result["content"]) - # remove the space key - result["content"] = re.sub("(\x08)+ +", "", result["content"]) - result["status"] = True + while True: + self.getMore(result['content']) + result["content"] += self.shell.recv(1024) + for section in prompt: + # section.values() is : [ [p1,p2,p3] ] + for _prompt in section.values()[0]: + if re.search(_prompt, result["content"].split("\n")[-1]): + result["state"] = section.keys()[0] + break + # Find the specified state type + if not result["state"] is None: + break + # Find the specified state type,exit + if not result["state"] is None: + break + result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) + # If you accept a timeout, cancel SSH + except Exception, e: + self.logout() + raise ForwardError(str(e)) + except Exception, e: + result["errLog"] = str(e) + result["status"] = False return result def getPrompt(self): @@ -258,14 +212,6 @@ def getPrompt(self): # [ex]'[localhost@labstill019~]' # self.prompt=self.prompt[1:-1] # [ex]'\\[localhost\\@labstill019\\~\\]$' - if re.search("> ?$", self.prompt): - # If last character of host prompt of the device ens in '>', - # the command line of device in gneral mode. - self.mode = 1 - elif re.search("(#|\]) ?$", self.prompt): - # If last character of host prompt of the device ens in '#', - # the command line of device in enable mode. - self.mode = 2 self.prompt = re.escape(self.prompt) return self.prompt else: @@ -279,7 +225,7 @@ def getMore(self, bufferData): """Automatically get more echo infos by sending a blank symbol """ # if check buffer data has 'more' flag, at last line. - if re.search(self.moreFlag, bufferData.split('\n')[-1].strip("\x00")): + if re.search(self.moreFlag, bufferData.split('\n')[-1]): # can't used to \n and ' \r' ,because product enter character self.shell.send(' ') diff --git a/lib/forward/devclass/baseTELNET.py b/lib/forward/devclass/baseTELNET.py index 17e5c65..50664ee 100644 --- a/lib/forward/devclass/baseTELNET.py +++ b/lib/forward/devclass/baseTELNET.py @@ -1,24 +1,12 @@ +#!/usr/bin/evn python # coding:utf-8 # -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Base device class for telnet method, by using telnetlib module. +Author: Azrael, Cheung Kei-Chuen """ import re from forward.utils.telnet import telnet @@ -42,12 +30,9 @@ def __init__(self, ip, username, password, **kwargs): self.channel = '' self.shell = '' - # self.basePrompt = r'(>|#|\]|\$|\)) *$' - # Multiple identical characters may appear - self.basePrompt = r"(>|#|\]|\$) *$" + self.basePrompt = r'(>|#|\]|\$|\)) *$' self.prompt = '' - self.moreFlag = '(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+|\(Q to quit\)' - self.mode = 1 + self.moreFlag = '(\-)+( |\()?[Mm]ore.*(\)| )?(\-)+' """ - parameter ip: device's ip @@ -103,7 +88,7 @@ def logout(self): # Modify login status to False. self.isLogin = False result['status'] = True - except Exception as e: + except Exception, e: result['status'] = False result['content'] = str(e) return result @@ -112,7 +97,7 @@ def execute(self, cmd): """execute a command line, only suitable for the scene when the prompt is equal before and after execution """ - dataPattern = '[\r\n]+([\s\S]*)[\r\n]+(\x1b\[m)?' + self.prompt + dataPattern = '[\r\n]+([\s\S]*)[\r\n]+' + self.prompt # Spaces will produce special characters and re.escape('show ver') --> show \\ ver data = {'status': False, 'content': '', @@ -139,14 +124,12 @@ def execute(self, cmd): tmp = re.search(dataPattern, data['content']).group(1) # Delete special characters caused by More split screen. tmp = re.sub("<--- More --->\\r +\\r", "", tmp) - tmp = re.sub('(\x00|\x08){0,}', "", tmp) - tmp = re.sub(re.escape("--More(CTRL+Cbreak)--"), "", tmp) data['content'] = tmp data['status'] = True - except Exception as e: + except Exception, e: # Not found host prompt raise ForwardError('not found host prompt Errorr(%s)' % str(e)) - except Exception as e: + except Exception, e: # Not found host prompt data['status'] = False data['errLog'] = data['errLog'] + 'not found host prompt Errorr(%s)' % str(e) @@ -220,14 +203,7 @@ def getPrompt(self): # [ex]'[localhost@labstill019~]' # self.prompt=self.prompt[1:-1] # [ex]'\\[localhost\\@labstill019\\~\\]$' - self.prompt = i[-1].split('\n')[-1] - if re.search("> ?$", self.prompt): - # If last character of host prompt of the device ens in '>', the command line of device in gneral mode. - self.mode = 1 - elif re.search("(#|\]) ?$", self.prompt): - # If last character of host prompt of the device ens in '#', the command line of device in enable mode. - self.mode = 2 - self.prompt = re.escape(self.prompt) + self.prompt = re.escape(i[-1].split('\n')[-1]) return self.prompt def cleanBuffer(self): @@ -242,72 +218,58 @@ def command(self, cmd=None, prompt=None, timeout=30): """execute a command line, powerful and suitable for any scene, but need to define whole prompt dict list """ - # regx compile - """ - _promptKey = prompt.keys() - for key in _promptKey: - prompt[key] = re.compile(prompt[key]) - In Telnet, regular expressions cannot be compiled - """ result = { - 'status': False, + 'status': True, 'content': '', 'errLog': '', "state": None } - if self.isLogin is False: - result['errLog'] = '[Execute Error]: device not login.' # Parameters check - parameterFormat = { - "success": "regular-expression-success", - "error": "regular-expression-error" - } - if (cmd is None) or (not isinstance(prompt, dict)) or (not isinstance(timeout, int)): - raise ForwardError("You should given a parameter for prompt such as: %s" % (str(parameterFormat))) + if (cmd is None) or (not isinstance(prompt, list)) or (not isinstance(timeout, int)): + raise ForwardError("""You should pass such a form of argument: \ +CMD = 'Your command', prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}] ,\ +timeout=30""") + for section in prompt: + if not isinstance(section.values(), list): + raise ForwardError("""you should pass such a form of argument:\ +prompt = [{" success ": ['prompt1', 'prompt2']}, {" error" : ['prompt3', 'prompt4']}]""") try: - # send a command self.channel.write("{cmd}\r".format(cmd=cmd)) - except Exception: - # break, if faild - result["errLog"] = "Forward had sent a command failure." - return result - while True: - i = self.channel.expect([r'%s' % self.moreFlag, - # prompt-1 - r"%s" % prompt.items()[0][1], - # prompt-2 - r"%s" % prompt.items()[1][1]], timeout=timeout) - result["content"] += i[-1] - if i[0] == 0: - # Get more - self.channel.write(" ".format(cmd=cmd)) - elif i[0] == 1: - # Find the prompt-1 - result["state"] = prompt.items()[0][0] - # Matching page break - if re.search(self.moreFlag, result["content"].split("\r\n")[-1]): - continue - else: - break - elif i[0] == 2: - # Find the prompt-2 - result["state"] = prompt.items()[1][0] - # Matching page break - if re.search(self.moreFlag, result["content"].split("\r\n")[-1]): - continue - else: - break - elif i[0] == -1: - # Timeout - result["errLog"] = '[Forward Error]: receive timeout,prompt is invalid.' - return result - result["status"] = True - # Delete page break - result["content"] = re.sub("\r\n.*?\r *?\r", "\r\n", result["content"]) - result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) - # remove the More charactor - result["content"] = re.sub(' \-\-More\(CTRL\+C break\)\-\- (\x00|\x08){0,} +(\x00|\x08){0,}', "", - result["content"]) - # remove the space key - result["content"] = re.sub("(\x08)+ +", "", result["content"]) + try: + info = '' + while True: + """ First, the program accepts the return message based on the base prompt, and if you accept + it directly from the specified prompt, there will be many times out of time in the middle, + resulting in reduced efficiency""" + i = self.channel.expect([r'%s' % self.moreFlag, r"%s" % self.basePrompt], timeout=timeout) + info += i[-1] + if i[0] == 0: + tmp = self.newGetMore(prompt, timeout) + info += tmp[0] + result["state"] = tmp[1] + break + elif i[0] == -1: + raise ForwardError('Error: receive timeout ') + else: + for section in prompt: + # section.values() is : [ [p1,p2,p3] ] + for _prompt in section.values()[0]: + if re.search(_prompt, info.split("\n")[-1]): + result["state"] = section.keys()[0] + break + # Find the specified state type + if not result["state"] is None: + break + # Find the specified state type,exit + if not result["state"] is None: + break + result['content'] += info + result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) + # If you accept a timeout, cancel SSH + except Exception, e: + self.logout() + raise ForwardError(str(e)) + except Exception, e: + result["errLog"] = str(e) + result["status"] = False return result diff --git a/lib/forward/devclass/baseVenustech.py b/lib/forward/devclass/baseVenustech.py index 59deb11..bfd1f0a 100644 --- a/lib/forward/devclass/baseVenustech.py +++ b/lib/forward/devclass/baseVenustech.py @@ -1,476 +1,16 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for Venustech. +Author: Cheung Kei-chuen """ from forward.devclass.baseTELNET import BASETELNET -import re class BASEVENUSTECH(BASETELNET): """This is a manufacturer of venustech, using the telnet version of the protocol, so it is integrated with BASETELNET library. """ - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$", - "error": "Unknown command[\s\S]+"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write file", - prompt={"success": "Current[\s\S]+[\r\n]+\S+# ?$", - "error": "Unknow[\s\S]+"}) - - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - elif data["state"] == "error": - result["content"] = data["content"] - else: - result["content"] = "The configuration was saved successfully.[%s]" % data["content"] - result["status"] = True - return result - - def configMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$", - "error": "Unknown command[\s\S]+"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("VSOS :(.*)", result["content"], flags=re.IGNORECASE) - if tmp: - njInfo["content"] = tmp.group(1).strip() - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - # Get the interface information - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+# ?$", - "error": "Unknown command[\s\S]+", - } - # Swtich to privilege-mode before getting the information of the interfaces. - tmp = self.privilegeMode() - if tmp["status"] is False: - njInfo["errLog"] = tmp["errLog"] - return njInfo - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall(".*Link[\s\S]+?TX rate.*", result["content"]) - for line in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - tmp = re.search("(.*)Link status", line) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - # Get line state of the interface. - tmp = re.search("Link status is (.*),", line) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - # Get the admin state of the interface. - tmp = re.search("Admin status is(.*)", line) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # Get mtu of the interface. - tmp = re.search("mtu (\d+)", line) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search("HWaddr: (.*)", line) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get the type of the interface. - tmp = re.search("media type: (\S+)", line) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - # Get the speed of the interface. - tmp = re.search("speed: (\S+)", line) - if tmp: - lineInfo["speed"] = tmp.group(1) - # Get duplex of the interface. - tmp = re.search("duplex:(\S+)", line) - if tmp: - lineInfo['duplex'] = tmp.group(1) - # Get metric of the interface. - tmp = re.search("Metric:(\d+)", line) - if tmp: - lineInfo["metric"] = tmp.group(1) - # Get input rate of the interface. - tmp = re.search("RX rate: (.*)", line) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Get output rate of the interface. - tmp = re.search("TX rate:(.*)", line) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ntp config" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - # Swtich to privilege-mode before getting the ntp informations. - tmp = self.privilegeMode() - if tmp["status"] is False: - njInfo["errLog"] = tmp["errLog"] - return njInfo - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", result["content"], flags=re.IGNORECASE) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show run snmp" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - # Swtich to privilege-mode before getting the snmp informations. - tmp = self.privilegeMode() - if tmp["status"] is False: - njInfo["errLog"] = tmp["errLog"] - return njInfo - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", result["content"], flags=re.IGNORECASE) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show run syslog" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - # Swtich to privilege-mode before getting the snmp informations. - tmp = self.privilegeMode() - if tmp["status"] is False: - njInfo["errLog"] = tmp["errLog"] - return njInfo - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - # Intercept the line containing the server address - tmp = re.search("log server addr.*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", result["content"]) - if tmp: - tmp = re.findall("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", tmp.group(), flags=re.IGNORECASE) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip route" - prompt = { - "success": "[\r\n]+\S+# ?$", - "error": "Unknown command[\s\S]+", - } - # Swtich to privilege-mode before getting the routing informations. - tmp = self.privilegeMode() - if tmp["status"] is False: - njInfo["errLog"] = tmp["errLog"] - return njInfo - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _interfaceInfo in result["content"].split("\r\n"): - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": "", - } - if re.search("\S?>\* [0-9]", _interfaceInfo): - tmp = re.search(">\* ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/([0-9]{1,2})", _interfaceInfo) - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - via = re.search("via ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)", _interfaceInfo) - if via: - lineInfo["via"] = via.group(1) - # Match the route table - tmp = re.search("([A-Z])>\*", _interfaceInfo) - if tmp: - _type = tmp.group(1) - if _type == "C": - _type = "connected" - elif _type == "S": - _type = "static" - elif _type == "R": - _type = "rip" - elif _type == "O": - _type = "ospf" - elif _type == "K": - _type = "kernel" - elif _type == "I": - _type = "isis" - elif _type == "B": - _type = "bgp" - elif _type == "G": - _type == "guard" - elif _type == "*": - _type = "fib" - else: - _type == "select" - lineInfo["type"] = _type - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show system uptime"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" runtime .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showOSPF(self, cmd="show ip ospf neighbor"): - njInfo = { - "status": True, - "content": [], - "errLog": "" - } - - prompt = { - "success": "[\r\n]+\S+(>|#) ?$", - "error": "(Invalid Input|Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - if tmp["status"] is False: - return njInfo - result = self.command(cmd, prompt) - dataLine = re.findall("[0-9]{1,3}.*", result["content"]) - if len(dataLine) == 0: - return njInfo - for line in dataLine: - line = line.split() - if len(line) == 8: - njInfo["content"].append({ - "neighbor-id": line[0], - "pri": line[1], - "state": line[2] + line[3], - "uptime": "", - "address": line[5], - "interface": line[6], - "deadTime": line[4]} - ) - else: - # The line does not matched data of expection. - continue - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/baseZte.py b/lib/forward/devclass/baseZte.py index aa3e254..8ca8b00 100644 --- a/lib/forward/devclass/baseZte.py +++ b/lib/forward/devclass/baseZte.py @@ -1,431 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for zte,zhong-xing. +Author: Cheung Kei-Chuen """ from forward.devclass.baseSSHV2 import BASESSHV2 -import re class BASEZTE(BASESSHV2): """This is a manufacturer of zte, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def commit(self): - result = { - "status": False, - "content": "", - "errLog": "" - } - # Switch to privilege-mode. - result = self.privilegeMode() - if not result["status"]: - # Switch failure. - return result - # Excute a command. - data = self.command("write", - prompt={"success": "OK[\s\S]+[\r\n]+\S+# ?$"}) - if data["state"] is None: - result["errLog"] = "Failed save configuration, \ - Info: [{content}] , [{errLog}]".format(content=data["content"], errLog=data["errLog"]) - else: - result["content"] = "The configuration was saved successfully." - result["status"] = True - return result - - def configMode(self): - # Switch to config mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Program need to go from privileged mode to configuration mode anyway,Becauseof - # you might be in interface mode, but you don't have a marks value of the mode - _result = self.privilegeMode() - if _result["status"] is False: - # "enter to privilege-mode failed." - result["status"] = False - return result - else: - # If value of the mode is 2,start switching to configure-mode. - sendConfig = self.command("config term", prompt={"success": "[\r\n]+\S+\(config\)# ?$"}) - if sendConfig["state"] == "success": - # switch to config-mode was successful. - result["status"] = True - self.mode = 3 - return result - elif sendConfig["state"] is None: - result["errLog"] = sendConfig["errLog"] - return result - - def privilegeMode(self): - # Switch to privilege mode. - result = { - "status": False, - "content": "", - "errLog": "" - } - # Get the current position Before switch to privileged mode. - # Demotion,If device currently mode-level greater than 2, It only need to execute `end`. - if self.mode >= 2: - exitResult = self.command("end", prompt={"success": "[\r\n]+\S+# ?$"}) - if not exitResult["state"] == "success": - result["errLog"] = "Demoted from configuration-mode to privilege-mode failed." - return result - else: - # Switch is successful. - self.mode = 2 - result["status"] = True - return result - # else, command line of the device is in general-mode. - # Start switching to privilege-mode. - sendEnable = self.command("enable", prompt={"password": "[pP]assword.*", "noPassword": "[\r\n]+\S+# ?$"}) - if sendEnable["state"] == "noPassword": - # The device not required a password,thus switch is successful. - result["status"] = True - self.mode = 2 - return result - elif sendEnable["state"] is None: - result["errLog"] = "Unknow error." - return result - # If device required a password,then send a password to device. - sendPassword = self.command(self.privilegePw, prompt={"password": "[pP]assword.*", - "noPassword": "[\r\n]+\S+# ?$"}) - if sendPassword["state"] == "password": - # Password error,switch is failed. - result["errLog"] = "Password of the privilege mode is wrong." - return result - elif sendPassword["state"] == "noPassword": - # switch is successful. - result["status"] = True - self.mode = 2 - return result - else: - result["errLog"] = "Unknown error." - return result - - def showVersion(self): - njInfo = { - 'status': False, - 'content': "", - 'errLog': '' - } - cmd = "show version" - prompt = { - "success": "[vV]ersion[\s\S]+[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.search("(software|system).*version ?:? ?(\S+)", result["content"], flags=re.IGNORECASE) - if tmp.lastindex == 2: - njInfo["content"] = tmp.group(2).strip(",") - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showNtp(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ntp status" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showSnmp(self): - # Get SNMP informatinos. - njInfo = { - "status": False, - # [{"ip:"10.1.1.1","port":"456"}] - "content": [], - "errLog": "" - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command("show snmp config", prompt=prompt) - if result["state"] == "success": - tmp = re.findall("snmp-server host.*(\d+\.\d+\.\d+\.\d+).*?udp-port (\d+)", - result["content"]) - """ - snmp-server host vrf mng 192.168.1.1 trap version 2c xxx udp-port 163 - snmp-server host vrf mng 192.168.2.1 trap version 2c xxxxx udp-port 162 - """ - if tmp.__len__() > 0: - njInfo["content"] = [{"ip": group[0], "port": group[-1]} for group in tmp] - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show vlan" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - for _vlanInfo in result["content"].split("\r\n"): - tmp = re.search("^([0-9]+)", _vlanInfo) - # Get the line of vlan. - lineInfo = { - "id": "", - "description": "", - "status": "", - "interface": [], - "type": "", - } - if tmp: - lineInfo["id"] = tmp.group(1) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showInterface(self): - # Get the interface information - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allLine = re.findall(".*line protocol[\s\S]+?output", result["content"]) - for line in allLine: - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - "ip": ""} - # Get name of the interface. - tmp = re.search("(.*?) is.*,", line) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - # Get line state of the interface. - tmp = re.search("line protocol is (.*),", line) - if tmp: - lineInfo["lineState"] = tmp.group(1).strip() - # Get the admin state of the interface. - tmp = re.search(".+ is (.*),", line) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # Get mtu of the interface. - tmp = re.search("[\r\n]+\s+MTU (\d+)", line) - if tmp: - lineInfo["mtu"] = tmp.group(1).strip() - # Get mac of the interface. - tmp = re.search(" Hardware.*address is (.*)", line) - if tmp: - lineInfo["mac"] = tmp.group(1).strip() - # Get the type of the interface. - tmp = re.search("The port is (\S+)", line) - if tmp: - lineInfo["type"] = tmp.group(1).strip() - # Get duplex of the interface. - tmp = re.search("Duplex (\S+)", line) - if tmp: - lineInfo['duplex'] = tmp.group(1).strip() - # Get input rate of the interface. - tmp = re.search("input\s+(\S+)", line) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Get output rate of the interface. - tmp = re.search("ouput\s+(\S+)", line) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - # Get description of the interface. - tmp = re.search("Description is (.*)", line) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # Get ip of the interface. - tmp = re.search("Internet address is (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", line) - if tmp: - lineInfo["ip"] = tmp.group(1) - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showLog(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show logging configuration" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - tmp = re.findall("syslog-server.*?([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", - result["content"]) - njInfo["content"] = tmp - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRoute(self,): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show ip vrf brief" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid input[\s\S]+", - } - # Get name of routes. - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - allRouteList = [] - for line in result["content"].split("\r\n"): - name = re.search("^\s+(\S+)", line) - if name: - allRouteList.append(name.group(1)) - for name in allRouteList: - # Get relevant information according to the name of the route. - cmd = "show ip protocol routing vrf {name}".format(name=name) - result = self.command(cmd=cmd, prompt=prompt) - if not result["state"] == "success": - continue - for line in result["content"].split("\r\n"): - tmp = re.search("(\d+\.\d+\.\d+\.\d+)/(\d{1,2})\s+(\d+\.\d+\.\d+\.\d+).*\s+(\S+)", line) - if tmp: - lineInfo = { - "net": "", - "mask": "", - "metric": "", - "type": "", - "description": "", - "interface": "", - "via": ""} - lineInfo["net"] = tmp.group(1) - lineInfo["mask"] = tmp.group(2) - lineInfo["via"] = tmp.group(3) - lineInfo["type"] = tmp.group(4).lower() - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self, cmd="show version"): - njInfo = {"status": True, - "content": {"noRestart": {"status": None, "content": ""}, - "systemTime": {"status": None, "content": ""}, - "cpuLow": {"status": None, "content": ""}, - "memLow": {"status": None, "content": ""}, - "boardCard": {"status": None, "content": ""}, - "tempLow": {"status": None, "content": ""}, - "firewallConnection": {"status": None, "content": ""}}, - "errLog": ""} - prompt = { - "success": "[\r\n]+\S+(>|\]|#) ?$", - "error": "(Bad command|[Uu]nknown command|Unrecognized command|Invalid command)[\s\S]+", - } - tmp = self.privilegeMode() - runningDate = -1 - if tmp["status"]: - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - dataLine = re.search(" [Uu]ptime:? .+(day|year|week).*", result["content"]) - if dataLine is not None: - tmp = re.search("([0-9]+) year", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 365 - tmp = re.search("([0-9]+) week", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) * 7 - tmp = re.search("([0-9]+) day", dataLine.group()) - if tmp: - runningDate += int(tmp.group(1)) - # Weather running-time of the device is more than 7 days - if runningDate > 7: - njInfo["content"]["noRestart"]["status"] = True - elif runningDate == -1: - pass - else: - njInfo["content"]["noRestart"]["status"] = False - # Return detail to Forward. - njInfo["content"]["noRestart"]["content"] = dataLine.group().strip() - else: - # Forward did't find the uptime of the device. - pass - else: - # That forwarder execute the command is failed. - result["status"] = False - return result - else: - return tmp - return njInfo - - def showRun(self): - cmd = "show run" - tmp = self.privilegeMode() - if not tmp["status"]: - # Switch failure. - return tmp - njInfo = self.command(cmd, prompt={"success": "[\r\n]+\S+# ?$"}) - if not njInfo["state"] == "success": - njInfo["status"] = False - else: - njInfo["content"] = "\r\n".join(njInfo["content"].split("\r\n")[1:-1]) - return njInfo + pass diff --git a/lib/forward/devclass/bclinux7.py b/lib/forward/devclass/bclinux7.py index ff793fa..b313c30 100644 --- a/lib/forward/devclass/bclinux7.py +++ b/lib/forward/devclass/bclinux7.py @@ -1,24 +1,12 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- # +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Device class for bclinux7. +Author: Cheung Kei-Chuen """ from forward.devclass.baseLinux import BASELINUX diff --git a/lib/forward/devclass/c2960.py b/lib/forward/devclass/c2960.py index 27d57ce..1bb1180 100644 --- a/lib/forward/devclass/c2960.py +++ b/lib/forward/devclass/c2960.py @@ -1,145 +1,17 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. - -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for c2960. +Author: Cheung Kei-chuen """ from forward.devclass.baseCisco import BASECISCO -import re class C2960(BASECISCO): """This is a manufacturer of cisco, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - - def addUser(self, username, password): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in deleting user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in re.findall(".*is[\s\S]+?swapped out", result["content"]): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - if i == 0: - _interfaceInfo = _interfaceInfo.split("\r\r\n")[1] - tmp = re.search("(.*) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - continue - else: - tmp = re.search("(.*?) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search(", address: ([\S]+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def basicInfo(self): - return BASECISCO.basicInfo(self, "show version") + pass diff --git a/lib/forward/devclass/c4510.py b/lib/forward/devclass/c4510.py index fa565dd..f24116d 100644 --- a/lib/forward/devclass/c4510.py +++ b/lib/forward/devclass/c4510.py @@ -1,140 +1,17 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for c4510. +Author: Cheung kei-chuen """ from forward.devclass.baseCisco import BASECISCO -import re class C4510(BASECISCO): """This is a manufacturer of cisco, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - def addUser(self, username, password): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in deleting user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in re.findall(".*is[\s\S]+?swapped out", result["content"]): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - if i == 0: - _interfaceInfo = _interfaceInfo.split("\r\r\n")[1] - tmp = re.search("(.*) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - continue - else: - tmp = re.search("(.*?) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search(", address: ([\S]+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo + pass diff --git a/lib/forward/devclass/c6506.py b/lib/forward/devclass/c6506.py index 678e121..f21cc84 100644 --- a/lib/forward/devclass/c6506.py +++ b/lib/forward/devclass/c6506.py @@ -1,123 +1,17 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for c6506. +Author: Cheung Kei-chuen """ from forward.devclass.baseCisco import BASECISCO -import re class C6506(BASECISCO): """This is a manufacturer of cisco, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in re.findall(".*is[\s\S]+?swapped out", result["content"]): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - if i == 0: - _interfaceInfo = _interfaceInfo.split("\r\r\n")[1] - tmp = re.search("(.*) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - continue - else: - tmp = re.search("(.*?) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search(", address: ([\S]+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo + pass diff --git a/lib/forward/devclass/c6509.py b/lib/forward/devclass/c6509.py index 3c790ce..0aa9f9a 100644 --- a/lib/forward/devclass/c6509.py +++ b/lib/forward/devclass/c6509.py @@ -1,141 +1,17 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for c6509. +Author: Cheung Kei-chuen """ from forward.devclass.baseCisco import BASECISCO -import re class C6509(BASECISCO): """This is a manufacturer of cisco, using the SSHV2 version of the protocol, so it is integrated with BASESSHV2 library. """ - - def addUser(self, username, password): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in deleting user parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='username {username} secret {password}\n') - - def showInterface(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "show interface" - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - tmp = self.privilegeMode() - if not tmp["status"]: - return tmp - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - i = 0 - for _interfaceInfo in re.findall(".*is[\s\S]+?swapped out", result["content"]): - i += 1 - lineInfo = {"interfaceName": "", - "members": [], - "lineState": "", - "adminState": "", - "description": "", - "speed": "", - "type": "", - "duplex": "", - "inputRate": "", - "outputRate": "", - "crc": "", - "linkFlap": "", - "mtu": "", - } - # Get name of the interface - if i == 0: - _interfaceInfo = _interfaceInfo.split("\r\r\n")[1] - tmp = re.search("(.*) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - njInfo["content"].append(lineInfo) - continue - else: - tmp = re.search("(.*?) is", _interfaceInfo) - if tmp: - lineInfo["interfaceName"] = tmp.group(1).strip() - else: - continue - tmp = re.search("admin state is (.*)", _interfaceInfo) - if tmp: - lineInfo["adminState"] = tmp.group(1).strip() - # MTU - tmp = re.search("MTU ([0-9]+)", _interfaceInfo) - if tmp: - lineInfo["mtu"] = tmp.group(1) - # description - tmp = re.search("Description: (.*)", _interfaceInfo) - if tmp: - lineInfo["description"] = tmp.group(1).strip() - # duplex - tmp = re.search("([a-z]+)\-duplex", _interfaceInfo) - if tmp: - lineInfo["duplex"] = tmp.group(1) - # Speed. - tmp = re.search("\-duplex, (.*),?", _interfaceInfo) - if tmp: - lineInfo["speed"] = tmp.group(1) - # ip. - tmp = re.search("Internet Address is (.*)", _interfaceInfo) - if tmp: - lineInfo["ip"] = tmp.group(1).split("/")[0] - # mac. - tmp = re.search(", address: ([\S]+)", _interfaceInfo) - if tmp: - lineInfo["mac"] = tmp.group(1) - # Last link flapped - tmp = re.search("Last link flapped (.*)", _interfaceInfo) - if tmp: - lineInfo["linkFlap"] = tmp.group(1).strip() - # Inpute rate. - tmp = re.search("300 seconds input rate (.*)", _interfaceInfo) - if tmp: - lineInfo["inputRate"] = tmp.group(1).strip() - # Output rate. - tmp = re.search("300 seconds ouput rate (.*)", _interfaceInfo) - if tmp: - lineInfo["outputRate"] = tmp.group(1).strip() - - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo + pass diff --git a/lib/forward/devclass/ce12812.py b/lib/forward/devclass/ce12812.py deleted file mode 100644 index 4d545b9..0000000 --- a/lib/forward/devclass/ce12812.py +++ /dev/null @@ -1,28 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Device class for ce12812. -""" -from forward.devclass.baseHuawei import BASEHUAWEI - - -class CE12812(BASEHUAWEI): - """This is a manufacturer of huawei, so it is integrated with BASEHUAWEI library. - """ - pass diff --git a/lib/forward/devclass/e1000e.py b/lib/forward/devclass/e1000e.py index e589e5c..2e20d6f 100644 --- a/lib/forward/devclass/e1000e.py +++ b/lib/forward/devclass/e1000e.py @@ -1,22 +1,9 @@ +#!/usr/bin/evn python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for E1000E. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI @@ -24,5 +11,4 @@ class E1000E(BASEHUAWEI): """This is a manufacturer of huawei, it is integrated with BASEHUAWEI library. """ - pass diff --git a/lib/forward/devclass/e8000e.py b/lib/forward/devclass/e8000e.py index cb972b8..b16823a 100644 --- a/lib/forward/devclass/e8000e.py +++ b/lib/forward/devclass/e8000e.py @@ -1,879 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for E8000E. +Author: Cheung Kei-chuen """ from forward.devclass.baseHuawei import BASEHUAWEI -import re -import string class E8000E(BASEHUAWEI): """This is a manufacturer of huawei, it is integrated with BASEHUAWEI library. """ - def showVlan(self): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - cmd = "display vlan" - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - result = self.command(cmd=cmd, prompt=prompt) - if result["state"] == "success": - # When encountered '------' characters, start statistics. - isBegin = False - for _vlanInfo in result["content"].split("\r\n"): - if re.search("\-\-\-\-\-\-\-", _vlanInfo): - isBegin = True - continue - if isBegin is False: - continue - """ - VLAN ID Type Status MAC Learning Broadcast/Multicast/Unicast Property - -------------------------------------------------------------------------------- - 12 common enable enable forward forward forward default - """ - # Get the line of vlan. - tmp = re.search("([0-9]+)\s+(\S+)\s+(\S+)", _vlanInfo) - if tmp: - lineInfo = { - "id": tmp.group(1), - "description": "", - "type": tmp.group(2), - "interface": [], - "status": tmp.group(3), - } - njInfo["content"].append(lineInfo) - njInfo["status"] = True - else: - njInfo["errLog"] = result["errLog"] - return njInfo - - def showRun(self): - """show the system config - Returns: - the system config of the device - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Invalid command[\s\S]+", - } - cmd = 'dis cur' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status']: - njInfo['errLog'] = result['errLog'] - return njInfo - if result['state'] == 'success': - njInfo['status'] = True - njInfo['content'] = result['content'] - return njInfo - - def showHostname(self): - '''show hostname - Return: - device hostname - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cmd = 'display current-configuration | include sysname' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status']: - njInfo['errLog'] = result['errLog'] - return njInfo - if result['state'] == 'success': - njInfo['content'] = re.findall('sysname (\S+)', result['content'])[0] - njInfo['status'] = True - return njInfo - njInfo['errLog'] = result['errLog'] - return njInfo - - def showSystemUptime(self): - '''display version - Return: - days_of_uptime - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cmd = 'display version ' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status']: - njInfo['errLog'] = result['errLog'] - return njInfo - if result['state'] == 'success': - # line=result['content'].split('\n') - # line.pop(0) - # line.pop(-1) - daysUptime = re.findall('is\s+(\d+)\s+days', result['content']) - njInfo['status'] = True - njInfo['content'] = 'days: ' + daysUptime[0] - return njInfo - else: - njInfo['errLog'] = result['errLog'] - return njInfo - - def showSystemClock(self): - '''show the system clock - Return: - system clock of the device - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cmd = 'display clock' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status']: - njInfo['errLog'] = result['errLog'] - return njInfo - if result['state'] == 'success': - njInfo['status'] = True - njInfo['content'] = result['content'] - return njInfo - else: - njInfo['errLog'] = result['errLog'] - return njInfo - - def showHardware(self): - """show temperature,fan,power status - Returns: - as above - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - tResult = self.command(cmd='display temperature', prompt=prompt) - if not tResult['status'] or tResult['state'] != 'success': - njInfo['errLog'] = tResult['errLog'] - return njInfo - - usefulList = [] - dashLine = 0 - emptyLine = 0 - mystr = tResult['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('----------', line): - dashLine = 1 - emptyLine = 0 - continue - if (line == '\r') or (re.findall('Power monitor cable state', line)): - dashLine = 0 - emptyLine = 1 - continue - if (dashLine == 1) and (emptyLine == 0): - usefulList.append(line) - temperatureResult = usefulList - errorDevice = [] - for line in temperatureResult: - if not re.findall('NORMAL', line): - errorDevice.append(line) - pResult = self.command(cmd='display power', prompt=prompt) - if not pResult['status'] or pResult['state'] != 'success': - njInfo['errLog'] = pResult['errLog'] - return njInfo - usefulList = [] - dashLine = 0 - emptyLine = 0 - mystr = pResult['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('----------', line): - dashLine = 1 - emptyLine = 0 - continue - if (line == '\r') or (re.findall('Power monitor cable state', line)): - dashLine = 0 - emptyLine = 1 - continue - if (dashLine == 1) and (emptyLine == 0): - usefulList.append(line) - powerResult = usefulList - for line in powerResult: - if not re.findall('Normal', line): - errorDevice.append(line) - fResult = self.command(cmd='display fan', prompt=prompt) - if not fResult['status'] or fResult['state'] != 'success': - njInfo['errLog'] = fResult['errLog'] - return njInfo - fResult = fResult['content'].split('\n') - fResult.pop(0) - fResult.pop(-1) - for line in fResult: - if re.findall('Registered', line): - if not re.findall('YES', line): - errorDevice.append('fan') - if not errorDevice: - njInfo['status'] = True - njInfo['content'] = 'check pass' - return njInfo - else: - njInfo['status'] = True - njInfo['content'] = errorDevice - return njInfo - - def showCpu(self): - """show cpu usage - Returns: - the device memory used - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cpuEnough = True - cmd = 'display health' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - dashCount = 1 - contentMatch = False - usefulList = [] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('CPU Usage', line): - contentMatch = True - continue - if contentMatch is False: - continue - if re.findall('----------', line): - dashCount = dashCount - 1 - continue - if dashCount < 1: - usefulList.append(line) - result = usefulList - cpuResult = [] - for line in result: - try: - value = re.findall('(\d+%)', line.split()[2])[0] - cpuResult.append(value) - # for debug print 'cpu===',value - if float(value[:-1]) > 60: - # cpu load >60% means overload - cpuEnough = False - except Exception: - pass - njInfo['status'] = True - njInfo['content'] = cpuEnough, cpuResult - return njInfo - - def showMemory(self): - """show Memory usage - Returns: - the device memory used - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - memoryEnough = True - cmd = 'display health' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - dashCount = 1 - contentMatch = False - usefulList = [] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('CPU Usage', line): - contentMatch = True - continue - if contentMatch is False: - continue - if re.findall('----------', line): - dashCount = dashCount - 1 - continue - if dashCount < 1: - usefulList.append(line) - mResult = usefulList - memoryResult = [] - for line in mResult: - try: - value = re.findall('(\d+%)', line.split()[3])[0] - memoryResult.append(value) - if float(value[:-1]) > 80: - memoryEnough = False - except Exception: - pass - njInfo['status'] = True - njInfo['content'] = memoryEnough, memoryResult - return njInfo - - def showIpObject(self, ip=None, mask=None): - '''show ip whether defind - Argv: - ip: ip address - msak: ip address mask - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if ip is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the ip." - return njInfo - if mask is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the mask." - return njInfo - cmd = 'display ip address-set address %s mask %s type object' % (ip, mask) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - if re.search('Item\(s\)\:\r\n address \d+ %s mask %s' % (ip, mask), result): - njInfo['status'] = True - njInfo['content'] = re.findall('Address-set: (.*%s)' % ip, result)[0] - return njInfo - - def showIpRangeObject(self, sIP=None, eIP=None): - '''show ip range whether defind - Argv: - sIP: start ip address - eIP: start ip address - msak: ip address mask - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if sIP is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the sIP." - return njInfo - if eIP is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the eIP." - return njInfo - preIP = re.search('(\d+\.\d+\.\d+\.)(\d+)', sIP) - lastIP = re.search('\d+\.\d+\.\d+\.(\d+)', eIP) - if not preIP or not lastIP: - njInfo['errLog'] = 'Not correct ip.' - return njInfo - else: - preIP = preIP.groups() - lastIP = lastIP.groups() - multiIP = preIP[0] + '[' + preIP[1] + '_' + lastIP[0] + ']' - cmd = 'display ip address-set address range %s %s type object' % (sIP, eIP) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - if multiIP in result['content']: - njInfo['status'] = True - njInfo['content'] = re.findall('Address-set: ([a-z|\_]+%s)' % re.escape(multiIP), result['content'])[0] - return njInfo - - def showPortObject(self, pType, port): - '''show port whether defind - Argv: - pType: tcp or udp - port: port - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if pType is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pType." - return njInfo - if port is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the port." - return njInfo - cmd = 'display ip service-set verbose %s_any_%s item' % (pType, port) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - if re.search('protocol %s source-port 0-65535 destination-port %s' % (pType, port), result['conent']): - njInfo['status'] = True - njInfo['content'] = re.findall('Service-set Name: (.*)\r', result['conent'])[0] - return njInfo - - def showPortRangeObject(self, pType, pStart, pEnd): - '''show port range whether defind - Argv: - pStart: start port address - pEnd: start port address - pType: tcp or udp - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if pType is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pType." - return njInfo - if pStart is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pStart." - return njInfo - if pEnd is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pEnd." - return njInfo - cmd = 'display ip service-set verbose %s_any_[%s_%s] item' % (pType, pStart, pEnd) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - if result == '': - return njInfo - if re.search('protocol %s source-port 0-65535 destination-port %s-%s' % (pType, - pStart, pEnd), result['content']): - njInfo['status'] = True - njInfo['content'] = re.findall('Service-set Name: (.*)\r', result['content'])[0] - return njInfo - - def showPolicy(self, sZone, dZone, bound, sourceAddress, destAddress, service): - '''show port range whether defind - Argv: - port_start: start port address - port_end: start port address - port_type: tcp or udp - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if sZone is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the sZone." - return njInfo - if dZone is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the dZone." - return njInfo - if bound is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the bound." - return njInfo - if sourceAddress is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the sourceAddress." - return njInfo - if destAddress is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the destAddress." - return njInfo - if service is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the service." - return njInfo - cmd = 'display policy interzone %s \ -%s %s source address-set %s destination \ -address-set %s service-set %s' % (sZone, dZone, bound, sourceAddress, destAddress, service) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - if result["state"] == "success": - if re.search(re.escape(sourceAddress), result['content']) and\ - re.search(re.escape(destAddress), result['content']) and \ - re.search(re.escape(service), result['content']): - njInfo["content"] = result['content'] - njInfo["status"] = True - else: - njInfo['errLog'] = result['errLog'] - return njInfo - - def createIpObject(self, ip, mask, description): - '''config ip object - Argv: - ip: ip address - msak: ip address mask - location: core or dmz or test - nettype: gl or yw - system:this ip belong system - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if ip is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the ip." - return njInfo - if mask is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the mask." - return njInfo - if description is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the description." - return njInfo - pMode = self.privilegeMode() - if not pMode['status']: - njInfo['errLog'] = pMode['errLog'] - return njInfo - cmd1 = 'ip address-set %s_%s type object' % (description, ip) - cmd2 = 'address 0 %s mask %s' % (ip, mask) - resultIP = self.command(cmd=cmd1, prompt=prompt) - if not resultIP['status'] or resultIP['state'] != 'success': - njInfo['errLog'] = resultIP['errLog'] - return njInfo - resultMask = self.command(cmd=cmd2, prompt=prompt) - if not resultMask['status'] or resultMask['state'] != 'success': - njInfo['errLog'] = resultMask['errLog'] - return njInfo - result = re.findall('\d+:\d+:\d+', resultMask['content']) - if resultIP['status'] and resultMask['status'] and len(result) > 0: - njInfo['status'] = True - njInfo['content'] = 'create ip success' - return njInfo - - def createIpRangeObject(self, startIP, endIP, description): - '''config ip range - Argv: - startIP: start ip address - endIP: start ip addressi - msak: ip address mask - location: core or dmz or test - nettype: gl or yw - system:this ip belong system - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if startIP is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the startIP." - return njInfo - if endIP is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the endIP." - return njInfo - if description is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the description." - return njInfo - pMode = self.privilegeMode() - if not pMode['status']: - njInfo['errLog'] = pMode['errLog'] - return njInfo - fIP = re.findall('\d+.\d+.\d+', startIP)[0] - sIP = re.findall('\d+.\d+.\d+', endIP)[0] - if fIP == sIP: - tIP = re.findall('\d+', startIP)[3] - lIP = re.findall('\d+', endIP)[3] - pointIP = fIP + '.[' + tIP + '_' + lIP + ']' - else: - njInfo["errLog"] = "ip start is not same segment as the end ip" - return njInfo - cmd1 = 'ip address-set %s_%s type object' % (description, pointIP) - cmd2 = 'address 0 range %s %s' % (startIP, endIP) - resultIP = self.command(cmd=cmd1, prompt=prompt) - if not resultIP['status'] or resultIP['state'] != 'success': - njInfo['errLog'] = resultIP['errLog'] - return njInfo - resultMask = self.command(cmd=cmd2, prompt=prompt) - if not resultMask['status'] or resultMask['state'] != 'success': - njInfo['errLog'] = resultMask['errLog'] - return njInfo - result = re.findall('\d+:\d+:\d+', resultMask['content']) - if resultIP['status'] and resultMask['status'] and len(result) > 0: - njInfo['status'] = True - njInfo['content'] = 'ip create success' - return njInfo - - def createPortObject(self, pType, port): - '''config port - Argv: - pType: tcp or udp - port: port - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if pType is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pType." - return njInfo - if port is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the port." - return njInfo - pMode = self.privilegeMode() - if not pMode['status']: - njInfo['errLog'] = pMode['errLog'] - return njInfo - cmd1 = 'ip service-set %s_any_%s type object' % (pType, port) - cmd2 = 'service 0 protocol %s source-port 0 to 65535 destination-port %s' % (pType, port) - - resultIP = self.command(cmd=cmd1, prompt=prompt) - if not resultIP['status'] or resultIP['state'] != 'success': - njInfo['errLog'] = resultIP['errLog'] - return njInfo - resultPort = self.command(cmd=cmd2, prompt=prompt) - if not resultPort['status'] or resultPort['state'] != 'success': - njInfo['errLog'] = resultPort['errLog'] - return njInfo - result = re.findall('\d+:\d+:\d+', resultPort['content']) - if resultIP['status'] and resultPort['status'] and len(result) > 0: - njInfo['status'] = True - njInfo['content'] = 'port create success' - return njInfo - - def createPortRangeObject(self, pType, portStart, portEnd): - '''config port range - Argv: - portStart: start port address - portEnd: start port address - pType: tcp or udp - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if pType is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the pType." - return njInfo - if portStart is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the portStart." - return njInfo - if portEnd is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the portEnd." - return njInfo - pMode = self.privilegeMode() - if not pMode['status']: - njInfo['errLog'] = pMode['errLog'] - return njInfo - cmd1 = 'ip service-set %s_any_[%s_%s] type object' % (pType, portStart, portEnd) - cmd2 = 'service 0 protocol %s source-port 0 to 65535 destination-port %s to %s' % (pType, - portStart, - portEnd) - resultIP = self.command(cmd=cmd1, prompt=prompt) - if not resultIP['status'] or resultIP['state'] != 'success': - njInfo['errLog'] = resultIP['errLog'] - return njInfo - resultPort = self.command(cmd=cmd2, prompt=prompt) - if not resultPort['status'] or resultPort['state'] != 'success': - njInfo['errLog'] = resultPort['errLog'] - return njInfo - result = re.findall('\d+:\d+:\d+', resultPort['content']) - - if resultIP['status'] and resultPort['status'] and len(result) > 0: - njInfo['status'] = True - njInfo['content'] = 'port create success' - return njInfo - - def createSecurityPolicy(self, sZone, dZone, srcAddress, descAddress, portService, description): - '''show port range whether defind - Argv: - port_start: start port address - port_end: start port address - port_type: tcp or udp - Return: - True or False - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Unrecognized command[\s\S]+", - } - if sZone is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the sZone." - return njInfo - if dZone is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the dZone." - return njInfo - if srcAddress is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the srcAddress." - return njInfo - if descAddress is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the descAddress." - return njInfo - if portService is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the portService." - return njInfo - if description is None: - njInfo["errLog"] = "[Forward Error] Please specify a parameter for the description." - return njInfo - pMode = self.privilegeMode() - if not pMode['status']: - njInfo['errLog'] = pMode['errLog'] - return njInfo - if sZone == 'trust' and dZone == 'trust': - njInfo["errLog"] = 'source_address and destination_address all belong to core, need not open policy' - return njInfo - elif sZone == 'trust' and dZone != 'trust' or sZone == 'dmz' and dZone == 'untrust': - directin = 'outbound' - elif sZone != 'trust' and dZone == 'trust' or sZone == 'untrust' and dZone == 'dmz': - directin = 'inbound' - elif sZone != 'trust' and dZone != 'trust': - njInfo['errLog'] = 'this policy not access in this firewall,please check the script' - return njInfo - cmdZone = 'policy interzone %s %s %s' % (sZone, dZone, directin) - while True: - resultZone = self.command(cmd=cmdZone, prompt=prompt) - if resultZone['status']: - break - if not resultZone['status'] or resultZone['state'] != 'success': - njInfo['errLog'] = resultZone['errLog'] - return njInfo - - cmdSearch = 'display policy interzone %s %s %s' % (sZone, dZone, directin) - resultSearch = self.command(cmd=cmdSearch, prompt=prompt) - if not resultSearch['status'] or resultSearch['state'] != 'success': - njInfo['errLog'] = resultSearch['errLog'] - return njInfo - - policyNum = max(list(map(int, re.findall('policy (\d+) ', resultSearch['content'])))) + 1 - # policyNum = int(re.findall('policy (\d+) ', result)[-1]) + 1 - cmdNum = 'policy %s' % str(policyNum) - resultNum = self.command(cmd=cmdNum, prompt=prompt) - if not resultNum['status'] or resultNum['state'] != 'success': - njInfo['errLog'] = resultNum['errLog'] - return njInfo - - cmdDesc = 'description %s' % description - resultDesc = self.command(cmd=cmdDesc, prompt=prompt) - if not resultDesc['status'] or resultDesc['state'] != 'success': - njInfo['errLog'] = resultDesc['errLog'] - return njInfo - - cmdPermit = 'action permit' - resultPermit = self.command(cmd=cmdPermit, prompt=prompt) - if not resultPermit['status'] or resultPermit['state'] != 'success': - njInfo['errLog'] = resultPermit['errLog'] - return njInfo - - for service in portService: - cmd = 'policy service service-set %s' % service - result = self.command(cmd=cmd, promt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - for sAddr in srcAddress: - cmd = 'policy source address-set %s' % sAddr - result = self.command(cmd=cmd, promt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - for descAddr in descAddress: - cmd = 'policy destination address-set %s' % descAddr - result = self.command(cmd=cmd, promt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - njInfo['status'] = True - njInfo['content'] = 'Policy create success!' - return njInfo + pass diff --git a/lib/forward/devclass/e8160e.py b/lib/forward/devclass/e8160e.py index 8fd41e4..3ac174c 100644 --- a/lib/forward/devclass/e8160e.py +++ b/lib/forward/devclass/e8160e.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for e8160e. +Author: Cheung Kei-chuen """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/f1000.py b/lib/forward/devclass/f1000.py index 1d7de6d..deaafa8 100644 --- a/lib/forward/devclass/f1000.py +++ b/lib/forward/devclass/f1000.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for f1000. +Author: Cheung Kei-chuen """ from forward.devclass.baseDepp import BASEDEPP @@ -25,12 +12,4 @@ class F1000(BASEDEPP): """This is a manufacturer of depp, it is integrated with BASEDEPP library. """ - def showLog(self): - # Firewall has no syslog configuration - njInfo = { - "status": False, - "content": [], - "errLog": "" - } - njInfo["status"] = True - return njInfo + pass diff --git a/lib/forward/devclass/f510000.py b/lib/forward/devclass/f510000.py index dec2af5..dd3d61d 100644 --- a/lib/forward/devclass/f510000.py +++ b/lib/forward/devclass/f510000.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for F510000. +Author: Cheung Kei-chuen """ from forward.devclass.baseF5 import BASEF5 @@ -25,20 +12,4 @@ class F510000(BASEF5): """This is a manufacturer of F5, it is integrated with BASEF5 library. """ - - def addUser(self, username, password): - """Because the device of this model is different from the other F5 - devices in creating user parameters, it is rewritten. - """ - return BASEF5.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - - def _commit(self): - """Because the device of this model is different from the other - F5 devices in deleting user parameters, it is rewritten. - """ - return BASEF5._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') + pass diff --git a/lib/forward/devclass/fg1240.py b/lib/forward/devclass/fg1240.py index 53b223a..979b2a0 100644 --- a/lib/forward/devclass/fg1240.py +++ b/lib/forward/devclass/fg1240.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for fg1240. +Author: Cheung Kei-chuen """ from forward.devclass.baseFortinet import BASEFORTINET diff --git a/lib/forward/devclass/fg3040.py b/lib/forward/devclass/fg3040.py index 3f6131e..c18654b 100644 --- a/lib/forward/devclass/fg3040.py +++ b/lib/forward/devclass/fg3040.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for fg3040. +Author: wangzhe """ from forward.devclass.baseFortinet import BASEFORTINET diff --git a/lib/forward/devclass/fg3950.py b/lib/forward/devclass/fg3950.py index 35284f9..156de31 100644 --- a/lib/forward/devclass/fg3950.py +++ b/lib/forward/devclass/fg3950.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for fg3950. +Author: Cheung Kei-Chuen """ from forward.devclass.baseFortinet import BASEFORTINET diff --git a/lib/forward/devclass/m6000.py b/lib/forward/devclass/m6000.py index bde955b..42e9934 100644 --- a/lib/forward/devclass/m6000.py +++ b/lib/forward/devclass/m6000.py @@ -1,22 +1,9 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for m6000,zhong-xing. +Author: Cheung Kei-Chuen """ from forward.devclass.baseZte import BASEZTE diff --git a/lib/forward/devclass/m9006.py b/lib/forward/devclass/m9006.py deleted file mode 100644 index 7f918f8..0000000 --- a/lib/forward/devclass/m9006.py +++ /dev/null @@ -1,30 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Device class for M9006. -""" -from forward.devclass.baseH3C import BASEH3C -import re -import string - - -class M9006(BASEH3C): - """This is a manufacturer of h3c, it is integrated with BASEH3C library. - """ - pass \ No newline at end of file diff --git a/lib/forward/devclass/mx960.py b/lib/forward/devclass/mx960.py index b87bacd..4b3260c 100644 --- a/lib/forward/devclass/mx960.py +++ b/lib/forward/devclass/mx960.py @@ -1,24 +1,7 @@ +#!/usr/bin/evn python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -""" ------Introduction----- -[Core][forward] Device class for m6000,zhong-xing. -It applies only to models of network equipment mx960 -See the detailed comments mx960.py +""" It applies only to models of network equipment mx960 + See the detailed comments mx960.py """ from forward.devclass.baseJuniper import BASEJUNIPER diff --git a/lib/forward/devclass/n5548.py b/lib/forward/devclass/n5548.py index 0a5e52a..51d8d4b 100644 --- a/lib/forward/devclass/n5548.py +++ b/lib/forward/devclass/n5548.py @@ -1,64 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n5548. +Author: Cheung Kei-Chuen """ -import re from forward.devclass.baseCisco import BASECISCO class N5548(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # default is not admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - - def basicInfo(self): - return BASECISCO.basicInfo(self, "show version") + pass diff --git a/lib/forward/devclass/n5596.py b/lib/forward/devclass/n5596.py index 605056c..8b15761 100644 --- a/lib/forward/devclass/n5596.py +++ b/lib/forward/devclass/n5596.py @@ -1,64 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n5596. +Author: Cheung Kei-Chuen """ -import re from forward.devclass.baseCisco import BASECISCO class N5596(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # default is not admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - - def basicInfo(self): - return BASECISCO.basicInfo(self, "show version") + pass diff --git a/lib/forward/devclass/n7010.py b/lib/forward/devclass/n7010.py index 516c915..03ae941 100644 --- a/lib/forward/devclass/n7010.py +++ b/lib/forward/devclass/n7010.py @@ -1,63 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n7010. +Author: Cheung Kei-Chuen """ -import datetime -import time -import re from forward.devclass.baseCisco import BASECISCO class N7010(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # param admin: defualt is not admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') + pass diff --git a/lib/forward/devclass/n7018.py b/lib/forward/devclass/n7018.py index 5a4a74a..f657829 100644 --- a/lib/forward/devclass/n7018.py +++ b/lib/forward/devclass/n7018.py @@ -1,61 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n7018. +Author: Cheung Kei-Chuen """ -import re from forward.devclass.baseCisco import BASECISCO class N7018(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # default not is Admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') + pass diff --git a/lib/forward/devclass/n7710.py b/lib/forward/devclass/n7710.py index f6dca0a..66bf2ea 100644 --- a/lib/forward/devclass/n7710.py +++ b/lib/forward/devclass/n7710.py @@ -1,22 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for n7018. +Author: Cheung Kei-Chuen """ from forward.devclass.baseCisco import BASECISCO @@ -24,36 +12,4 @@ class N7710(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # default not is Admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') + pass diff --git a/lib/forward/devclass/n7718.py b/lib/forward/devclass/n7718.py index ef73fac..783d10a 100644 --- a/lib/forward/devclass/n7718.py +++ b/lib/forward/devclass/n7718.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n7018. +Author: Cheung Kei-Chuen """ from forward.devclass.baseCisco import BASECISCO @@ -25,36 +12,4 @@ class N7718(BASECISCO): """This is a manufacturer of cisco, so it is integrated with BASECISCO library. """ - - def addUser(self, username, password, admin=False): - """Because the device of this model is different from the other Cisco - devices in creating user parameters, it is rewritten. - """ - # default not is Admin - if admin: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') - else: - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role priv-1\n') - - def _commit(self): - """Because the device of this model is different from the other - Cisco devices in commit parameters, it is rewritten. - """ - return BASECISCO._commit(self, - saveCommand='copy running-config startup-config', - exitCommand='end') - - def changePassword(self, username, password): - """Because the device of this model is different from the other - Cisco devices in change user's password parameters, it is rewritten. - """ - return BASECISCO.addUser(self, - username=username, - password=password, - addCommand='user {username} password {password} role network-admin\n') + pass diff --git a/lib/forward/devclass/ne40ex16.py b/lib/forward/devclass/ne40ex16.py index d87efc0..1d649a0 100644 --- a/lib/forward/devclass/ne40ex16.py +++ b/lib/forward/devclass/ne40ex16.py @@ -1,19 +1,6 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for ne40ex16. @@ -27,41 +14,6 @@ class NE40EX16(BASEHUAWEI): """This is a manufacturer of huawei, so it is integrated with BASEHUAWEI library. """ - def _commit(self): - """Because the device of this model is different from the other - huawei devices in commit parameters, it is rewritten. - """ - saveCommand = "save" - # exitCommand = "return" - data = {"status": False, - "content": "", - "errLog": ""} - try: - # Check the config mode status. - if self.isConfigMode: - self._exitConfigMode() - # exit config mode - self.shell.send('%s\n' % (saveCommand)) - # save setup to system - while not re.search(self.prompt, data['content'].split('\n')[-1]): - data['content'] += self.shell.recv(1024).decode() - # When prompted, reply Y,Search range at last line - if re.search(re.escape('Are you sure to continue?[Y/N]'), data['content'].split('\n')[-1]): - # interact,send y - self.shell.send("y\n") - """ - If the program finds information like ‘success’, etc. - in the received information, it indicates that the save configuration is successful. - """ - if re.search(re.escape('Save the configuration successfully'), data['content'], flags=re.IGNORECASE): - data['status'] = True - else: - raise IOError('Error: The current state is not configuration mode') - except Exception as e: - data['errLog'] = str(e) - data['status'] = False - return data - def login(self): """Because the device of this model is different from the other huawei devices in commit parameters, it is rewritten. @@ -80,7 +32,7 @@ def login(self): self.shell = self.channel.invoke_shell(width=1000, height=1000) tmpBuffer = '' while not re.search(self.basePrompt, tmpBuffer.split('\n')[-1]): - tmpBuffer += self.shell.recv(1024).decode() + tmpBuffer += self.shell.recv(1024) # When prompted, reply N if re.search('\[Y/N\]:', tmpBuffer): self.shell.send('N\n') diff --git a/lib/forward/devclass/ne40ex3.py b/lib/forward/devclass/ne40ex3.py index dc71c40..87f708b 100644 --- a/lib/forward/devclass/ne40ex3.py +++ b/lib/forward/devclass/ne40ex3.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for ne40ex3. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/r3048g.py b/lib/forward/devclass/r3048g.py index f733ced..6e9409f 100644 --- a/lib/forward/devclass/r3048g.py +++ b/lib/forward/devclass/r3048g.py @@ -1,22 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for n7018. +Author: Cheung Kei-Chuen """ from forward.devclass.baseRaisecom import BASERAISECOM from forward.utils.forwardError import ForwardError diff --git a/lib/forward/devclass/rg5510.py b/lib/forward/devclass/rg5510.py index a839258..38c925b 100644 --- a/lib/forward/devclass/rg5510.py +++ b/lib/forward/devclass/rg5510.py @@ -1,27 +1,20 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- -[Core][forward] Device class for rg5510-sshv2. +[Core][forward] Device class for rg5510. +Author: Cheung Kei-Chuen """ from forward.devclass.baseRuijie import BASERUIJIE class RG5510(BASERUIJIE): - - pass + """This is a manufacturer of ruijie, so it is integrated with BASERUIJIE library. + """ + def __init__(self, *args, **kws): + """Since the device's host prompt is different from BASESSHV2, + the basic prompt for the device is overwritten here. + """ + BASERUIJIE.__init__(self, *args, **kws) + self.basePrompt = r'(>|#.*#|\]|\$|\)) *$' diff --git a/lib/forward/devclass/rg5510v1.py b/lib/forward/devclass/rg5510v1.py deleted file mode 100644 index 92b16c6..0000000 --- a/lib/forward/devclass/rg5510v1.py +++ /dev/null @@ -1,27 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Device class for rg5510-sshv1. -""" -from forward.devclass.baseRuijieV1 import BASERUIJIE - - -class RG5510V1(BASERUIJIE): - - pass diff --git a/lib/forward/devclass/s3300.py b/lib/forward/devclass/s3300.py index c7b1235..e9daf0a 100644 --- a/lib/forward/devclass/s3300.py +++ b/lib/forward/devclass/s3300.py @@ -1,22 +1,9 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s3300. +Author: Cheung Kei-Chuen """ import pexpect import re @@ -62,132 +49,3 @@ def _recv(self, _prompt): data['errLog'] = str(e) data['status'] = False return data - - def addUser(self, username, password, userLevel=1): - """Create a user on the device. - """ - data = {'status': False, - 'content': '', - 'errLog': ''} - try: - if not username or not password: - raise ForwardError('Please specify the username = your-username \ - and password = your-password') - # Specify a user name and password parameters here. - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - if self.isConfigMode: - # check terminal status - self.channel.send("""username {username} privilege {userLevel} \ - password 0 {password}\n""".format(username=username, - password=password, - userLevel=userLevel)) - # Get result. - _result = self._recv(self.prompt) - _tmp = re.search("""This command can be used by user "admin" only""", _result['content']) - # Permission denied - if _tmp: - raise ForwardError(_tmp.group()) - elif not _result['status']: - # Message acceptance failed - raise ForwardError(_result['errLog']) - # Send the command to create an account. - self.channel.send("""username {username} terminal ssh\n""".format(username=username, - password=password, - userLevel=userLevel)) - # Get result. - _result = self._recv(self.prompt) - if _result['status']: - # Save the configuration - data = self._commit() - else: - data = _result - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def deleteUser(self, username): - """Delete a user on the device - """ - data = {'status': False, - 'content': '', - 'errLog': ''} - try: - if not username: - raise ForwardError('Please specify a username') - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # Check config mode status. - if self.isConfigMode: - # check terminal status - self.channel.send("""no username {username}\n""".format(username=username)) - # Get result. - _result = self._recv(self.prompt) - # Permission denied - _tmp = re.search("""This command can be used by user "admin" only""", _result['content']) - if _tmp: - raise ForwardError(_tmp.group()) - elif not _result['status']: - # Message acceptance failed - raise ForwardError(_result['errLog']) - if re.search('error|invalid', data['content'], flags=re.IGNORECASE): - raise ForwardError(data['content']) - if _result['status']: - # Save the configuration - data = self._commit() - else: - data = _result - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def changePassword(self, username, password, userLevel=1): - """Modify the password for the device account. - """ - data = {'status': False, - 'content': '', - 'errLog': ''} - try: - if not username or not password: - # Specify a user name and password parameters here. - raise ForwardError('Please specify the username = your-username and password = your-password') - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # Check config mode stauts. - if self.isConfigMode: - # check terminal status - self.channel.send("""username {username} password 0 {password}\n""".format(username=username, - password=password, - userLevel=userLevel)) - # Get result. - _result = self._recv(self.prompt) - _tmp = re.search("""This command can be used by user "admin" only""", _result['content']) - # Permission denied - if _tmp: - raise ForwardError(_tmp.group()) - elif not _result['status']: - # Message acceptance failed - raise ForwardError(_result['errLog']) - if _result['status']: - # Save the configuration - data = self._commit() - else: - data = _result - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data diff --git a/lib/forward/devclass/s5328.py b/lib/forward/devclass/s5328.py index b0720aa..b493feb 100644 --- a/lib/forward/devclass/s5328.py +++ b/lib/forward/devclass/s5328.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s5328. +Author: wangzhe """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/s5352.py b/lib/forward/devclass/s5352.py index f32cfb7..a1c4d2f 100644 --- a/lib/forward/devclass/s5352.py +++ b/lib/forward/devclass/s5352.py @@ -1,22 +1,9 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s5352. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/s5800.py b/lib/forward/devclass/s5800.py index ac36148..c6f96fe 100644 --- a/lib/forward/devclass/s5800.py +++ b/lib/forward/devclass/s5800.py @@ -1,22 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for S5800. +Author: Cheung Kei-Chuen """ from forward.devclass.baseFenghuo import BASEFENGHUO from forward.utils.forwardError import ForwardError @@ -26,200 +14,4 @@ class S5800(BASEFENGHUO): """This is a manufacturer of fenghuo, so it is integrated with BASEFENGHUO library. """ - - def isVlanInPort(self, vlan=None, port=None): - """Check that the Vlan exists in the port. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # Parameters check. - if (vlan is None) or (port is None): - raise ForwardError('Specify the `vlan` and `port` parameters') - # Execute command. - info = self.execute("show run") - if not info["status"]: - raise ForwardError(info["errLog"]) - try: - # Keyword search - tmp = re.search("\![\r\n]+interface gigaethernet {port}[\s\S]*por\ -t link-type (access|trunk)[\s\S]*port .* vlan .*{vlan}".format(vlan=vlan, port=port), info["content"]) - if tmp: - # Vlan in the port, case 1 - if tmp.group(1) == "access": - raise ForwardError("Configuration found, but port link - type is 'access', Not a trunk") - info["content"] = tmp.group().split("ABCDEFG") - info["status"] = True - else: - # No exists' - raise ForwardError('No exists') - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - return info - - def createVlanInPort(self, port=None, vlan=None): - """Create a vlan on the port. - """ - # Prameters check. - if (port is None) or (vlan is None): - raise ForwardError('Specify the `port` parameter') - info = {"status": False, - "content": "", - "errLog": ""} - try: - # switch to enable mode - tmp = self.privilegeMode() - if not tmp["status"]: - raise ForwardError(tmp['errLog']) - # else ,successed - # switch to config mode - tmp = self._configMode() - if not tmp["status"]: - raise ForwardError(tmp['errLog']) - # else ,successed - # switch to port mode - info["content"] = "" - self.shell.send("interface gigaethernet {port}\n".format(port=port)) - # Host prompt is modified - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # release host prompt - self.getPrompt() - # Check the port mode - if not re.search('config.*-ge', self.prompt): - raise ForwardError('Switch to port mode is failed [%s]' % info["content"]) - # else successed. - tmp = self.execute("port link-type trunk") - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - tmp = self.execute("port trunk allow-pass vlan {vlan}".format(vlan=vlan)) - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - else: - # Check the returned 'tmp['content']', which indicates failure if it contains' Failed ' - if re.search('%Failed', tmp["content"]): - raise ForwardError('Execute the command "port trunk allow-pass vlan" is failed ,\ - result is [%s] ' % tmp["content"]) - # else successed - tmp = self.execute("no shutdown") - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # quit port mode - self.shell.send("quit\n") - info["content"] = "" - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - self.getPrompt() - # save configuration - tmp = self._commit() - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # Verify that it is correct - tmp = self.isVlanInPort(port=port, vlan=vlan) - if not tmp["status"]: - raise ForwardError("The configuration command has been executed,\ - but the check configuration does not exist! [%s]" % tmp["errLog"]) - else: - # successed - info["content"] = "successed" - info["status"] = True - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - return info - - def isTrunkInInterface(self, port=None, vlan=None): - """Check the relationship between interface and turnk. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # Prameters check. - if (vlan is None) or (port is None): - raise ForwardError('Specify the `vlan` and `port` parameters') - while True: - # Execute command. - info = self.execute("show run") - if not info["status"]: - raise ForwardError(info["errLog"]) - try: - # Keyword search. - tmp = re.search("interface eth-trunk {port}[\r\n]+ mode .*[\r\n]+ por\ - t .*[\r\n]+ port .* vlan .*{vlan}".format(port=port, vlan=vlan), info['content']) - if tmp: - # Exists. - info["status"] = True - break - elif re.search('Command is in use by', info["content"]): - # Rechecking... - continue - else: - info["errLog"] = info['errLog'] - break - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - break - return info - - def trunkOpenVlan(self, port=None, vlan=None): - """Create a vlan on turnk. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # Parameters check. - if (vlan is None) or (port is None): - raise ForwardError('Specify the `vlan` and `port` parameters') - try: - # switch to enable mode - tmp = self.privilegeMode() - if not tmp["status"]: - raise ForwardError(tmp['errLog']) - # else ,successed - # switch to config mode - tmp = self._configMode() - if not tmp["status"]: - raise ForwardError(tmp['errLog']) - # else ,successed - # switch to port mode - self.shell.send("interface eth-trunk {port}\n".format(port=port)) - # Host prompt is modified - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # release host prompt - self.getPrompt() - # Keyword search. - if not re.search("config.*-eth.*-trunk.*-{port}".format(port=port), self.prompt): - raise ForwardError('[trunkOpenVlan] Switch to port mode is failed [%s]' % info["content"]) - # Execute command. - tmp = self.execute("port trunk allow-pass vlan {vlan}".format(vlan=vlan)) - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - else: - # Check the returned 'tmp['content']', which indicates failure if it contains' Failed ' - if re.search('%Failed', tmp["content"]): - raise ForwardError('Execute the command "port trunk allow-pass vlan" is failed ,\ - result is [%s] ' % tmp["content"]) - # quit port mode - self.shell.send("quit\n") - info["content"] = "" - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # save configuration - self.getPrompt() - # Save the configuration. - tmp = self._commit() - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # Verify that it is correct - tmp = self.isTrunkInInterface(port=port, vlan=vlan) - if not tmp["status"]: - raise ForwardError("The configuration command has been executed,\ - but the check configuration does not exist! [%s]" % tmp['errLog']) - info["status"] = True - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - return info + pass diff --git a/lib/forward/devclass/s8512.py b/lib/forward/devclass/s8512.py index debb1b8..db93d63 100644 --- a/lib/forward/devclass/s8512.py +++ b/lib/forward/devclass/s8512.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s8512. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/s9303.py b/lib/forward/devclass/s9303.py index 9cc5431..e1b9298 100644 --- a/lib/forward/devclass/s9303.py +++ b/lib/forward/devclass/s9303.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s9303. +Author: Cheung Kei-Cheun """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/s9306.py b/lib/forward/devclass/s9306.py index d61fefb..6a955c0 100644 --- a/lib/forward/devclass/s9306.py +++ b/lib/forward/devclass/s9306.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for s9306. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI diff --git a/lib/forward/devclass/s9312.py b/lib/forward/devclass/s9312.py index d86a36a..66a1217 100644 --- a/lib/forward/devclass/s9312.py +++ b/lib/forward/devclass/s9312.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for n7018. +Author: Cheung Kei-Chuen """ from forward.devclass.baseHuawei import BASEHUAWEI from forward.utils.forwardError import ForwardError @@ -27,753 +14,4 @@ class S9312(BASEHUAWEI): """This is a manufacturer of huawei, so it is integrated with BASEHUAWEI library. """ - def isVlan(self, vlan): - """Check if the Vlan exists. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # switch to enable mode. - tmp = self.privilegeMode() - if not tmp: - raise ForwardError(tmp["errLog"]) - tmp = self.execute("display vlan {vlan}".format(vlan=vlan)) - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # If the above fails, exit immediately - try: - if re.search("Error: The VLAN does not exist", tmp["content"]): - # vlan not is exitsts - info["status"] = False - else: - # vlan is exists - info["status"] = True - except Exception as e: - info["status"] = False - info["errLog"] = str(e) - return info - - def createVlan(self, vlan=None, ascription=None): - """Create a Vlan. - """ - info = {"status": False, - "content": "", - "errLog": ""} - if (vlan is None) or (ascription is None): - raise ForwardError("You must specify the `vlan` and `ascription` parameters") - """Warning: that vlan should be checked - by the 'self.isvlan(vlan) method - before setting up the vlan""" - # swith to config mode - info = self._configMode() - if not info["status"]: - raise ForwardError(info["errLog"]) - try: - # enter vlan - info["content"] = "" - self.shell.send("vlan {vlan}\n".format(vlan=vlan)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # Get host prompt - self.getPrompt() - if not re.search('.*-vlan', self.prompt): - raise ForwardError("Failed to enter vlan mode,command:vlan {vlan}".format(vlan=vlan)) - # set host's ascription - info["content"] = "" - # Send command. - self.shell.send("name {ascription}\n".format(ascription=ascription)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # Get host prompt. - self.getPrompt() - # save the configuration. - tmp = self._commit() - if not tmp["status"]: - raise ForwardError("The configuration command has been executed,\ - but the save configuration failed! [{info}]".format(info=info["content"])) - else: - if not self.isVlan(vlan)["status"]: - # check vlan - raise ForwardError("Vlan has been set and has been saved, but the final\ - check found no configuration, so failed.info:[%s]" % tmp["content"]) - else: - # create successed. exit config mode - info["status"] = True - except Exception as e: - info["status"] = False - info["errLog"] = str(e) - return info - - def isTrunkInInterface(self, port=None, vlan=None): - """Check the relationship between interface and turnk. - """ - info = {"status": False, - "content": "", - "errLog": ""} - if (vlan is None) or (port is None): - raise ForwardError('Specify the `vlan` and `port` parameters') - # switch to enable mode - tmp = self.privilegeMode() - if not tmp["status"]: - raise ForwardError(tmp['errLog']) - # else ,successed - while True: - tmp = self.execute("display current-configuration interface Eth-Trunk") - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - if re.search("Command is in use by", tmp["content"]): - # Recheck - continue - # Keyword search. - data = re.search("#[\r\n]+(interface Eth-Trunk{port}[\r\n]+[\s\S]*?)#".format(port=port), tmp["content"]) - if not data: - # No configuration found - raise ForwardError("Not found port(port) info".format(port=port)) - try: - if re.search("port trunk allow-pass vlan .*{vlan}".format(vlan=vlan), data.group(1)): - # found it. - info["status"] = True - else: - info["status"] = False - info["errLog"] = tmp["content"] - break - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - break - return info - - def trunkOpenVlan(self, port=None, vlan=None): - """Create a vlan on turnk. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # Parameter check. - if (vlan is None) or (port is None): - raise ForwardError('Specify the `vlan` and `port` parameters') - # get parameter - tmp = self.execute("display cur interface Eth-Trunk {port}".format(port=port)) - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # search parameter - data = re.search("#[\r\n]+(interface Eth-Trunk{port}[\r\n]+[\s\S]*?)#".format(port=port), tmp["content"]) - if not data: - raise ForwardError("Not found port(port) [{info}]".format(port=port, info=tmp["content"])) - else: - # Keyword search. - data = re.search("(port trunk allow-pass vlan.*)", data.group(1)) - if not data: - raise ForwardError("`Port turnk allow-pass vlan ...` is not found") - else: - # remove the end '\n' and '\r' - cmd = "{parameter} {vlan}".format(parameter=data.group(1).strip("\r\n"), vlan=vlan) - # switch to config mode - tmp = self._configMode() - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - try: - # switch to port mode - info["content"] = "" - # Send command. - self.shell.send("interface Eth-Trunk {port}\n".format(port=port)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # Get new host prompt. - self.getPrompt() - # Keyword search. - if not re.search('Trunk{port}'.format(port=port), self.prompt): - raise ForwardError("Failed to enter port mode,command:interface \ -Eth-Trunk {port} [{info}]".format(port=port, info=info["content"])) - # set vlan - info["content"] = "" - self.shell.send("{cmd}\n".format(cmd=cmd)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # Get new host prompt. - self.getPrompt() - # save configuration - tmp = self._commit() - if not tmp["status"]: - raise ForwardError("The configuration command has been executed,\ - but the save configuration failed! [{info}]".format(info=info["content"])) - # check configuration - tmp = self.isTrunkInInterface(port=port, vlan=vlan) - if not tmp["status"]: - raise ForwardError("Vlan has been set and has been saved, but the final\ - check found no configuration, so failed.info:[%s]" % tmp["errLog"]) - else: - info["status"] = True - except Exception as e: - info["errLog"] = str(e) - info["status"] = False - return info - - def isGateway(self, vlan): - """Check that the gateway exists. - """ - info = {"status": False, - "content": "", - "errLog": ""} - # switch to enable mode. - tmp = self.privilegeMode() - if not tmp: - raise ForwardError(tmp["errLog"]) - # Execute command. - tmp = self.execute("display current-configuration interface Vlanif {vlan}".format(vlan=vlan)) - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - # If the above fails, exit immediately - try: - if re.search("Error: Wrong parameter found at", tmp["content"]): - info["status"] = False - else: - info["status"] = True - except Exception as e: - info["status"] = False - info["errLog"] = str(e) - return info - - def setGateway(self, vlan=None, ascription=None, ip=None): - """Create a gateway - """ - info = {"status": False, - "content": "", - "errLog": ""} - # Parameters check. - if (vlan is None) or (ascription is None) or (ip is None): - raise ForwardError("You must specify `vlan` and `ascription` and `ip` parameters") - # Reset gateway ip address - ip = re.sub('[0-9]+$', '254', ip) - # switch to config mode - tmp = self._configMode() - if not tmp["status"]: - raise ForwardError(tmp["errLog"]) - try: - # switch to vlanif mode - info["content"] = "" - # Send command. - self.shell.send("interface Vlanif {vlan}\n".format(vlan=vlan)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode() - # Get new host prompt. - self.getPrompt() - if not re.search('Vlanif', self.prompt): - raise ForwardError("Failed to enter Vlanif mode,command:port Vlanif {vlan}".format(vlan=vlan)) - # set ascription - info["content"] = "" - self.shell.send("description {ascription}\n".format(ascription=ascription)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode - # Get new host prompt. - self.getPrompt() - # set ip - info["content"] = "" - # Send command. - self.shell.send("ip address {ip} 255.255.255.0\n".format(ip=ip)) - while not re.search(self.basePrompt, info['content'].split('\n')[-1]): - info['content'] += self.shell.recv(1024).decode - # Check - if re.search("Error: The specified IP address is invalid", info["content"]): - raise ForwardError("Error: The specified IP address is invalid,IP should be a network segment") - # Get new host prompt. - self.getPrompt() - # save the configuration - tmp = self._commit() - if not tmp["status"]: - raise ForwardError("The configuration command has been executed,\ - but the save configuration failed! [{info}]".format(info=info["content"])) - else: - # Check that the gateway configuration exists. - if not self.isGateway(vlan)["status"]: - # check vlan - raise ForwardError("Gateway has been set and has been saved, but the final\ - check found no configuration, so failed.info:[%s]" % tmp["content"]) - else: - # create successed. exit config mode - info["status"] = True - except Exception as e: - info["status"] = False - info["errLog"] = str(e) - return info - - def showInterfacePower(self, port): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - if port.startswith('XGi'): - port = re.findall('\d+\S+', port)[0] - cmd = 'display transceiver interface XGigabitEthernet ' + port + ' verbose ' - elif port.startswith('Gi'): - port = re.findall('\d+\S+',port)[0] - cmd = 'display transceiver interface GigabitEthernet ' + port + ' verbose ' - _result = self.command(cmd=cmd, prompt=prompt) - if not _result['status'] or _result['state'] != 'success': - njInfo['errLog'] = _result['errLog'] - return njInfo - info = re.findall(r'dBM.*:(.*)\r', _result['content']) - result = {} - if string.atof(info[0]) > string.atof(info[6]): - result['TX'] = 'HIGH' - elif string.atof(info[0]) < string.atof(info[7]): - result['TX'] = 'LOW' - else: - result['TX'] = 'normal' - - if string.atof(info[3]) > string.atof(info[8]): - result['RX'] = 'HIGH' - elif string.atof(info[3]) < string.atof(info[9]): - result['RX'] = 'LOW' - else: - result['RX'] = 'normal' - njInfo['status'] = True - njInfo['content'] = result - return njInfo - - def aclGet(self, acl_name='LOGIN', acl_ip='1.1.1.5'): - """show ip acl - - Returns: - the ip acl list - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - acl = {} - acl_name = re.sub(' *', '', acl_name) - cmd = "display current-configuration | begin user-interface" - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['status'] = result['errLog'] - return njInfo - acl_num = re.findall('acl (\d+)', result['content'])[0] - cmd = 'display acl %s | include %s' % (acl_num, acl_ip) - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['status'] = result['errLog'] - return njInfo - if len(re.findall(acl_ip, result['content'])) > 0: - njInfo['status'] = True - else: - njInfo['status'] = False - return njInfo - - def showSystemUptime(self): - '''display version - Return: - weeks_of_uptime,days_of_uptime - ''' - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cmd = 'display version ' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['status'] = result['errLog'] - uptime=re.search('Switch uptime is\s+(\d+)\s+weeks, (\d+)\s+days',result['content']) - weeksUptime = uptime.groups()[0] - daysUptime= uptime.groups()[1] - njInfo['status'] = True - njInfo['content'] = weeksUptime,daysUptime - return njInfo - - def usefulContent(self,mystr,matchContent): - ''' - Args: - matchContent - Return: - useful content between 2nd lines of '----' and 3rd line of '-----' - input like: - System memory usage at 2018-04-13 09:41:18 - ------------------------------------------------------------------------------- - Slot Total Memory(MB) Used Memory(MB) Used Percentage Upper Limit - ------------------------------------------------------------------------------- - 1 173 77 44% 85% - 2 173 77 44% 85% - 3 173 77 44% 85% - ------------------------------------------------------------------------------- - output: - 1 173 77 44% 85% - 2 173 77 44% 85% - 3 173 77 44% 85% - - ''' - dash_count=3 - content_match=False - usefulList=[] - mystr = mystr.split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall(matchContent, line): - content_match=True - continue - if content_match==False : - continue - if re.findall('----------',line): - dash_count=dash_count-1 - continue - if dash_count==1: - usefulList.append(line) #print line - continue - elif dash_count == 0 : - content_match=False - dash_count=3 - return usefulList - - def usefulContent2(self,mystr,matchContent): - ''' - Args: - matchContent - Return: - useful content between 1st lines of '----' and 2nd line of '-----' - input like: - PowerID Online Mode State Current(A) Voltage(V) RealPwr(W) - -------------------------------------------------------------------------- - PWR1 Present AC Supply 5.31 53.50 284.08 - PWR2 Present AC Supply 5.66 53.53 302.98 - ------------------------------------------------------------------------------- - output: - PWR1 Present AC Supply 5.31 53.50 284.08 - PWR2 Present AC Supply 5.66 53.53 302.98 - - ''' - dash_count=2 - content_match=False - usefulList=[] - mystr = mystr.split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall(matchContent, line): - content_match=True - continue - if content_match==False : - continue - if re.findall('----------',line) or re.findall('System Memory Usage Information:',line): - dash_count=dash_count-1 - continue - if dash_count==1: - usefulList.append(line) #print line - continue - elif dash_count == 0 : - content_match=False - dash_count=2 - return usefulList - - def showHardware(self): - """show hardware statu - Returns: - sensor,temperature,power,Fan status - True or False - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cmd='display health' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - - dashCount=2 - contentMatch=False - usefulList=[] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('Slot Card Sensor SensorName Status', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line) or re.findall('System Memory Usage Information:',line): - dashCount=dashCount-1 - continue - if dashCount==1: - usefulList.append(line) #print line - continue - elif dashCount == 0 : - contentMatch=False - dashCount=2 - resultSensor = usefulList - - dashCount=2 - contentMatch=False - usefulList=[] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('PowerID Online Mode State Current', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line) or re.findall('System Memory Usage Information:',line): - dashCount=dashCount-1 - continue - if dashCount==1: - usefulList.append(line) #print line - continue - elif dashCount == 0 : - contentMatch=False - dashCount=2 - reultTemperature = usefulList - - dashCount=2 - contentMatch=False - usefulList=[] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('PowerID Online Mode State Current', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line) or re.findall('System Memory Usage Information:',line): - dashCount=dashCount-1 - continue - if dashCount==1: - usefulList.append(line) #print line - continue - elif dashCount == 0 : - contentMatch=False - dashCount=2 - resultPower = usefulList - - dashCount=2 - contentMatch=False - usefulList=[] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('FanID FanNum Online Register', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line) or re.findall('System Memory Usage Information:',line): - dashCount=dashCount-1 - continue - if dashCount==1: - usefulList.append(line) #print line - continue - elif dashCount == 0 : - contentMatch=False - dashCount=2 - result_fan = usefulList - - sensorNormal=True - temperatureNormal=True - powerNormal=True - fanNormal=True - errorDevice = [] - for line in resultSensor: - if not re.findall('Normal', line): #health output for sensor: If a line include 'Normal', it is normal - sensorNormal=False - errorDevice.append(line) - for line in reultTemperature: - if not re.findall('Normal', line): #health output for temperature: If a line include 'Normal', it is normal - temperatureNormal=False - errorDevice.append(line) - for line in resultPower:#health output for power: If a line include 'Present' and 'Supply' together, it is normal - if re.findall('Present', line): - if not re.findall('Supply',line): - temperatureNormal=False - errorDevice.append(line) - if re.findall('FAN', line): - if not (re.findall('Registered', line)): - fanNormal = False - errorDevice.append(line) - if not errorDevice: - njInfo['content'] = 'check pass' - else: - njInfo['content'] = errorDevice - njInfo['status'] = True - return njInfo - - def showMemory(self): - """show memory used - Returns: - the device memory used - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - memoryEnough = True - cmd = 'display health | after 17 include System memory usage at' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - dashCount = 3 - contentMatch = False - usefulList = [] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('System memory usage at', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line): - dashCount = dashCount-1 - continue - if dashCount == 1: - usefulList.append(line) - continue - elif dashCount == 0 : - contentMatch = False - dashCount = 3 - resultMemory = usefulList - # resultMemory=self.usefulContent(result['content'],'System memory usage at') #strip off unuseful line - for line in resultMemory: - value = re.findall('(\d+)%', line) - if float(value[0]) >= float(value[1]): - memoryEnough = False - njInfo['status'] = True - njInfo['content'] = memoryEnough - return njInfo - - def showCpu(self): - """show cpu used - Returns: - the device memory used - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - cpu_enough = True - cmd = 'display health | after 17 include System cpu usage at' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - dashCount = 3 - contentMatch = False - usefulList = [] - mystr = result['content'].split('\n') - mystr.pop(0) - mystr.pop(-1) - for line in mystr: - if re.findall('System memory usage at', line): - contentMatch=True - continue - if contentMatch==False : - continue - if re.findall('----------',line): - dashCount = dashCount-1 - continue - if dashCount == 1: - usefulList.append(line) - continue - elif dashCount == 0 : - contentMatch = False - dashCount = 3 - resultMemory = usefulList - # result_cpu=self.usefulContent(result['content'],'System cpu usage at') #strip off unuseful line - for line in resultCPU: - value = re.findall('(\d+)%', line) - if float(value[0]) >= float(value[1]): - cpu_enough = False - njInfo['status'] = True - njInfo['content'] = cpu_enough,resultCPU - return njInfo - - def showSpanningTreeStatus(self): - """show spanning tree stat - judge if the root bridge ID equal local bridge ID ---S9312 must be root - Returns: - the spanning tree status - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(>|\]) ?$", - "error": "Invalid command[\s\S]+", - } - # cpu_enough=True - cmdLocla = 'display stp bridge local' - cmdRoot = 'display stp bridge root' - resultLocal = self.command(cmd=cmdLocla, prompt=prompt) - resultRoot = self.command(cmd=cmdRoot, prompt=prompt) - if not resultLocal['status'] or resultLocal['state'] != 'success': - njInfo['errLog'] = resultLocal['errLog'] - return njInfo - if not resultRoot['status'] or resultRoot['state'] != 'success': - njInfo['errLog'] = resultRoot['errLog'] - return njInfo - resultLocal = resultLocal['content'].split('\n') - resultRoot = resultRoot['content'].split('\n') - resultLocal.pop(0) - resultLocal.pop(-1) - resultRoot.pop(0) - resultRoot.pop(-1) - rootBridge = '' - spanning_tree_change = False - for i in range(len(resultRoot)): - if i <= 2: - continue - if rootBridge == '': - rootBridge = resultRoot[i].split()[1] - continue - if not resultRoot[i].split()[1] == rootBridge: - spanning_tree_change = True - else: - pass - for i in range(len(resultLocal)): - if i <= 2: - continue - if not resultLocal[i].split()[1] == rootBridge: - spanning_tree_change = True - else: - pass - njInfo['status'] = True - njInfo['content'] = rootBridge, spanning_tree_change - return njInfo + pass diff --git a/lib/forward/devclass/s9312e.py b/lib/forward/devclass/s9312e.py deleted file mode 100644 index 30eb5f0..0000000 --- a/lib/forward/devclass/s9312e.py +++ /dev/null @@ -1,30 +0,0 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -""" ------Introduction----- -[Core][forward] Device class for s9312e. -""" -import re - -from forward.devclass.baseHuawei import BASEHUAWEI - - -class S9312E(BASEHUAWEI): - """This is a manufacturer of huawei, so it is integrated with BASEHUAWEI library. - """ - pass diff --git a/lib/forward/devclass/sr7750.py b/lib/forward/devclass/sr7750.py index 166edb2..ece85bf 100644 --- a/lib/forward/devclass/sr7750.py +++ b/lib/forward/devclass/sr7750.py @@ -1,108 +1,14 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for sr7750. +Author: zhangqichuan """ from forward.devclass.baseBaer import BASEBAER -import string -import re class SR7750(BASEBAER): """This is a manufacturer of baer, so it is integrated with BASEBAER library.""" - def showInterfacePower(self, port): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - cmd = 'show port ' + port + ' detail | match dBm' - resultPower = self.command(cmd=cmd, prompt=prompt) - if not resultPower['status'] or resultPower['state'] != 'success': - njInfo['errLog'] = resultPower['errLog'] - return njInfo - result = {} - resultPower = resultPower['content'].split('\r\n') - resultPower.pop(0) - resultPower.pop(-1) - for line in resultPower: - power = line.strip().split() - if power[4] == 'dBm)': - _power = power[5] - _power_high = power[7] - _power_low = power[8] - else: - _power = power[4] - _power_high = power[6] - _power_low = power[7] - if string.atof(_power) > string.atof(_power_high): - result['TX'] = 'HIGH' - elif string.atof(_power) < string.atof(_power_low): - result['TX'] = 'LOW' - else: - result['TX'] = 'normal' - if string.atof(_power) > string.atof(_power_high): - result['RX'] = 'HIGH' - elif string.atof(_power) < string.atof(_power_low): - result['RX'] = 'LOW' - else: - result['RX'] = 'normal' - njInfo['status'] = True - njInfo['content'] = result - return njInfo - - def showSyslog(self): - """show the system syslog server and logbuffer - example cmd: - show log syslog - - Returns: - logbuffer level and syslog server level - """ - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+.+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - logInfo = { - 'status':True, - 'errLog':'', - 'content':{} - } - cmd = 'show log syslog' - result = self.command(cmd=cmd, prompt=prompt) - if not result['status'] or result['state'] != 'success': - njInfo['errLog'] = result['errLog'] - return njInfo - syslogList= re.findall('(\d+\.\d+\.\d+\.\d+)\s+\d+\s+(\w+)', result['content']) - logInfo['content']['syslog_server'] = {} - for serinfo in syslogList: - logInfo['content']['syslog_server'][serinfo[0]] = serinfo[1] - logInfo['content']['logbuffer'] = 'NULL' - njInfo['status'] = True - njInfo['content'] = logInfo - return njInfo + pass diff --git a/lib/forward/devclass/sr7950.py b/lib/forward/devclass/sr7950.py index 1ac8351..27ffbe4 100644 --- a/lib/forward/devclass/sr7950.py +++ b/lib/forward/devclass/sr7950.py @@ -1,115 +1,15 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for sr7950. +Author: zhangqichuan """ from forward.devclass.baseBaer import BASEBAER -import string class SR7950(BASEBAER): """This is a manufacturer of baer, so it is integrated with BASEBAER library. """ - def showInterfacePower(self, port): - njInfo = { - 'status': False, - 'content': [], - 'errLog': '' - } - prompt = { - "success": "[\r\n]+\S+(#|>) ?$", - "error": "Unknown command[\s\S]+", - } - portResult = port.split('/') - - if portResult[0] == '1' and portResult[1] == '1': - cmd = 'show port ' + port + ' detail | match +' - resultPower = self.command(cmd=cmd, prompt=prompt) - if not resultPower['status'] or resultPower['state'] != 'success': - njInfo['errLog'] = resultPower['errLog'] - return njInfo - powerLevel = {} - resultPower = resultPower['content'].split('\r\n') - resultPower.pop(0) - resultPower.pop(-1) - for line in resultPower: - power = line.strip().split() - if power[0] == '1': - result['TX_1'] = power[3] - result['RX_1'] = power[4] - elif power[0] == '2': - result['TX_2'] = power[3] - result['RX_2'] = power[4] - elif power[0] == '3': - result['TX_3'] = power[3] - result['RX_3'] = power[4] - elif power[0] == '4': - result['TX_4'] = power[3] - result['RX_4'] = power[4] - if result['TX_1'] < '-4.80' or result['TX_2'] < '-4.80' or result['TX_3'] < '-4.80' or result['TX_4'] < '-4.80': - powerLevel['TX'] = 'LOW' - elif result['TX_1'] > '5.00' or result['TX_2'] > '5.00' or result['TX_3'] > '5.00' or result['TX_4'] > '5.00': - powerLevel['TX'] = 'HIGH' - else: - powerLevel['TX'] = 'normal' - if result['RX_1'] < '-12.10' or result['RX_2'] < '-12.10' or result['RX_3'] < '-12.10' or result['RX_4'] < '-12.10': - powerLevel['RX'] = 'LOW' - elif result['RX_1'] > '5.00' or result['RX_2'] > '5.00' or result['RX_3'] > '5.00' or result['RX_4'] > '5.00': - powerLevel['RX'] = 'HIGH' - else: - powerLevel['RX'] = 'normal' - njInfo['status'] = True - njInfo['content'] = powerLevel - return njInfo - else: - cmd = 'show port ' + port + ' detail | match dBm' - resultPower = self.command(cmd=cmd, prompt=prompt) - if not resultPower['status'] or resultPower['state'] != 'success': - njInfo['errLog'] = resultPower['errLog'] - return njInfo - powerLevel = {} - resultPower = resultPower['content'].split('\r\n') - resultPower.pop(0) - resultPower.pop(-1) - result = {} - for line in resultPower: - power = line.strip().split() - if power[4] == 'dBm)': - per = power[5] - powerHight = power[7] - powerLow = power[8] - else: - per = power[4] - powerHight = power[6] - powerLow = power[7] - if string.atof(per) > string.atof(powerHight): - result['TX'] = 'HIGH' - elif string.atof(per) < string.atof(powerLow): - result['TX'] = 'LOW' - else: - result['TX'] = 'normal' - if string.atof(per) > string.atof(powerHight): - result['RX'] = 'HIGH' - elif string.atof(per) < string.atof(powerLow): - result['RX'] = 'LOW' - else: - result['RX'] = 'normal' - njInfo['status'] = True - njInfo['content'] = result - return njInfo + pass diff --git a/lib/forward/devclass/srx3400.py b/lib/forward/devclass/srx3400.py index 37e83a8..f267ae4 100644 --- a/lib/forward/devclass/srx3400.py +++ b/lib/forward/devclass/srx3400.py @@ -1,23 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for srx3400. +Author: Cheung Kei-Chuen """ from forward.devclass.baseJuniper import BASEJUNIPER diff --git a/lib/forward/devclass/unusable_command_interface.py b/lib/forward/devclass/unusable_command_interface.py deleted file mode 100644 index 9a189c8..0000000 --- a/lib/forward/devclass/unusable_command_interface.py +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - """def auto_execute(self): - # regx compile - _promptKey = prompt.keys() - for key in _promptKey: - prompt[key] = re.compile(prompt[key]) - result = { - 'status': False, - 'content': '', - 'errLog': '', - "state": None - } - if self.isLogin is False: - result['errLog'] = '[Execute Error]: device not login.' - return result - # Setting timeout. - self.shell.settimeout(timeout) - # Parameters check - parameterFormat = { - "success": "regular-expression-success", - "error": "regular-expression-error" - } - if (cmd is None) or (not isinstance(prompt, dict)) or (not isinstance(timeout, int)): - raise ForwardError("You should given a parameter for prompt such as: %s" % (str(parameterFormat))) - # Clean buffer data. - while self.shell.recv_ready(): - self.shell.recv(1024) - try: - # send a command - self.shell.send("{cmd}\r".format(cmd=cmd)) - except Exception: - # break, if faild - result["errLog"] = "That forwarder has sent a command is failed." - return result - isBreak = False - while True: - # Remove special characters. - result["content"] = re.sub("", "", result["content"]) - self.getMore(result["content"]) - try: - result["content"] += self.shell.recv(204800) - except Exception: - result["errLog"] = "Forward had recived data timeout. [%s]" % result["content"] - return result - # Check if all the command results have been returned - xPrompt = re.search(self.basePrompt, re.sub(self.moreFlag, "", result["content"].split("\r\n")[-1])) - if xPrompt: - xPrompt = xPrompt.group().strip(" ") - # The all command results may have been returned. - # Send a key of enter to reconfirm. - self.shell.send("\r") - tmp = self.shell.recv(512) - yPrompt = re.search(self.basePrompt, re.sub(self.moreFlag, "", tmp.split("\r\n")[-1])) - if yPrompt: - # Formate prompt. - yPrompt = yPrompt.group().strip(" ") - # Compare two host prompts for consistency - if xPrompt == yPrompt: - # Confirmed. - # [ex] GD-N7010-S2 # - # [ex] GD-N7010-S2 # - break - else: - # The all command results have been not returned yet,so continue - result["content"] += tmp - continue - else: - # The all command results have been not returned yet,so continue - result["content"] += tmp - continue - else: - # The all command results have been not returned yet,so continue - continue - # Mathing specify key - for key in prompt: - if re.search(prompt[key], re.sub(self.moreFlag, "", result["content"])): - # Found it - result["state"] = key - isBreak = True - break - # Delete page break - result["content"] = re.sub("\r\n.*?\r *?\r", "\r\n", result["content"]) - # Clearing special characters - result["content"] = re.sub(" *---- More ----\x1b\[42D \x1b\[42D", - "", - result["content"]) - result["content"] = re.sub("<--- More --->\\r +\\r", "", result["content"]) - # remove the More charactor - result["content"] = re.sub(' \-\-More\(CTRL\+C break\)\-\- (\x00|\x08){0,} +(\x00|\x08){0,}', "", - result["content"]) - # remove the space key - result["content"] = re.sub("(\x08)+ +", "", result["content"]) - result["status"] = True - return result""" - - def command(self, cmd=None, prompt={}, timeout=30): - """execute a command line, powerful and suitable for any scene, - but need to define whole prompt dict list - """ - # regx compile - _promptKey = prompt.keys() diff --git a/lib/forward/devclass/usg1000.py b/lib/forward/devclass/usg1000.py index 7781454..2febe3e 100644 --- a/lib/forward/devclass/usg1000.py +++ b/lib/forward/devclass/usg1000.py @@ -1,22 +1,9 @@ +#!/usr/bin/evn python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . """ -----Introduction----- [Core][forward] Device class for USG1000. +Author: Cheung Kei-Chuen """ import re from forward.devclass.baseVenustech import BASEVENUSTECH @@ -26,13 +13,6 @@ class USG1000(BASEVENUSTECH): """This is a manufacturer of venustech, so it is integrated with BASEVENUSTECH library. """ - def showVlan(self): - # No VLAN information for the model equipment. - data = {"status": False, - "content": [], - "errLog": ""} - data["status"] = True - return data def _recv(self, _prompt): # Gets the return message after the command is executed. @@ -52,90 +32,3 @@ def _recv(self, _prompt): except ForwardError, e: data['errLog'] = str(e) return data - - def addUser(self, username, password, admin=False): - """Create a user on the device. - """ - # Set command. - if admin: - command = """user administrator {username} local {password} \ - authorized-table admin\n""".format(username=username, password=password) - else: - command = """user administrator {username} local {password} \ - authorized-table admsee\n""".format(username=username, password=password) - data = {"status": False, - "content": "", - "errLog": ""} - try: - # parameters check. - if not username or not password: - # Spcify a user name and password parameters here. - raise ForwardError('Please specify the username = your-username and password = your-password') - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - if self.isConfigMode: - # check terminal status - self.channel.write(command) - # adduser - data = self._recv(self.prompt) - # recv result - if not data['status']: - # break - raise ForwardError(data['errLog']) - result = data['content'] - if re.search('error|invalid|assword', result, flags=re.IGNORECASE): - # command failure - raise ForwardError(result) - # set password is successed, save the configuration. - data = self._commit() - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def deleteUser(self, username): - """Delete a user on the device - """ - data = {"status": False, - "content": "", - "errLog": ""} - try: - # swith to config terminal mode. - checkPermission = self._configMode() - if not checkPermission['status']: - raise ForwardError(checkPermission['errLog']) - # Check config mode status. - if self.isConfigMode: - # check terminal status - # deleteUser - self.channel.write("""no user administrator {username}\n""".format(username=username)) - # recv result - data = self._recv(self.prompt) - if not data['status']: - # break - raise ForwardError(data['errLog']) - # Get result. - result = data['content'] - # Search for keywords to determine if the command execution is successful. - if re.search('error|invalid|assword', result, flags=re.IGNORECASE): - # command failure - raise ForwardError(result) - # delete user is successed, save the configuration. - data = self._commit() - else: - raise ForwardError('Has yet to enter configuration mode') - except ForwardError, e: - data['errLog'] = str(e) - data['status'] = False - return data - - def changePassword(self, username, password): - """Modify the password for the device account. - Because the password command to modify the account on the device is consistent with the creation - of the user's command, the interface to create the account is called. - """ - return self.addUser(username=username, password=password) diff --git a/lib/forward/devclass/vlb.py b/lib/forward/devclass/vlb.py index 6f23dbf..19b27b7 100644 --- a/lib/forward/devclass/vlb.py +++ b/lib/forward/devclass/vlb.py @@ -1,20 +1,7 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- # +# (c) 2017, Azrael """ -----Introduction----- @@ -29,73 +16,4 @@ class VLB(BASEBROCADE): """This is a manufacturer of brocade, so it is integrated with BASEBROCADE library. """ - def zcliMode(self): - """Execute the czli command and enter a new mode. - """ - # Flag zcli mode is False. - self.isZcliMode = False - # Set command. - cmd = "zcli\n" - # Set host prompt. - zcliPrompt = re.escape("admin@127.0.0.1 > ") - result = { - 'status': True, - 'content': '', - 'errLog': '' - } - # Clean buffer. - self.cleanBuffer() - # Login status check. - if self.isLogin: - self.shell.send(cmd) - try: - while not re.search(zcliPrompt, result["content"]): - result['content'] += self.shell.recv(1024).decode - # Save the host prompt before entering the zcli mode - self.oldPrompt = self.prompt - # update host prompt - self.prompt = zcliPrompt - # Flag zcli mode is True. - self.isZcliMode = True - result['status'] = True - except Exception as e: - # Error,flag zcli mode is False. - self.isZcliMode = False - result['status'] = False - result['errLog'] = '[ZCLI Error]: {info}'.format(info=str(e)) - else: - # not login - result['status'] = False - result['errLog'] = '[Execute Error]: device not login' - return result - - def exitZcli(self): - # Exit the zcli mode and return to normal mode. - cmd = "exit\n" - result = { - 'status': False, - 'content': '', - 'errLog': '' - } - # Login status check. - if self.isLogin: - if self.isZcliMode: - self.shell.send(cmd) - # Restore the host prompt - self.prompt = self.oldPrompt - try: - while not re.search(self.prompt, result["content"]): - result['content'] += self.shell.recv(1024).decode - # The switch mode status is False - self.isZcliMode = False - result['status'] = True - except Exception as e: - result['status'] = False - result['errLog'] = '[ZCLI Error]: {info}'.format(info=str(e)) - else: - result["errLog"] = "Error: The current state is not zcli mode" - else: - # not login - result['status'] = False - result['errLog'] = '[Execute Error]: device not login' - return result + pass diff --git a/lib/forward/devclass/vyoslinux.py b/lib/forward/devclass/vyoslinux.py index d441afc..43b4961 100644 --- a/lib/forward/devclass/vyoslinux.py +++ b/lib/forward/devclass/vyoslinux.py @@ -1,24 +1,12 @@ -# coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- # +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Device class for bclinux7. +Author: Cheung Kei-Chuen """ import re from forward.devclass.bclinux7 import BCLINUX7 @@ -43,7 +31,7 @@ def execute(self, cmd): """The result returned is similar to 'show version\r\n\x1b[?1h\x1b=\r Version: VyOS 1.1.7\x1b[m\r\nDescription: VyOS 1.1.7 (helium )\x1b[m\r\nCopyright: 0.29\x1b[m\r\n\x1b[m\r\n\r\x1b[K\x1b[?1l - \x1b>vyos@nxx-sdn-fwvm-253-153:~$ + \x1b>vyos@nfjd-sdn-fwvm-253-153:~$ Because of this type of device, special character information will be generated after executing the command, so delete it here. """ @@ -62,7 +50,7 @@ def execute(self, cmd): # Get more. self.getMore(result['content']) # Get result. - result['content'] += self.shell.recv(1024).decode + result['content'] += self.shell.recv(1024) # try to extract the return data try: # Intercepting the results of the command execution. diff --git a/lib/forward/devclass/zx5952.py b/lib/forward/devclass/zx5952.py index f8a1384..4370cc4 100644 --- a/lib/forward/devclass/zx5952.py +++ b/lib/forward/devclass/zx5952.py @@ -1,22 +1,10 @@ +#!/usr/bin/env python # coding:utf-8 -# -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . + """ -----Introduction----- [Core][forward] Device class for zx5952. +Author: Cheung Kei-Chuen """ from forward.devclass.baseZte import BASEZTE diff --git a/lib/forward/release.py b/lib/forward/release.py old mode 100755 new mode 100644 index 14dab58..4fdc33f --- a/lib/forward/release.py +++ b/lib/forward/release.py @@ -1,18 +1,8 @@ -# This file is part of Forward. +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael -__version__ = '3.2.0' -__author__ = 'Wang Zhe, Zhang Qi Chuan' +__version__ = '3.0.8' +__author__ = 'Azrael, Cheung Kei-Chuen' diff --git a/lib/forward/utils/__init__.py b/lib/forward/utils/__init__.py old mode 100755 new mode 100644 index 618b041..e69de29 --- a/lib/forward/utils/__init__.py +++ b/lib/forward/utils/__init__.py @@ -1,14 +0,0 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . diff --git a/lib/forward/utils/boolean.py b/lib/forward/utils/boolean.py deleted file mode 100755 index a0f475a..0000000 --- a/lib/forward/utils/boolean.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -BOOL_TRUE = frozenset(["true", "t", "y", "1", "yes", "on"]) - - -def boolean(value): - if value is None: - return False - val = str(value) - if val.lower() in BOOL_TRUE: - return True - else: - return False diff --git a/lib/forward/utils/deviceListSplit.py b/lib/forward/utils/deviceListSplit.py index bb60d5a..ace28b6 100644 --- a/lib/forward/utils/deviceListSplit.py +++ b/lib/forward/utils/deviceListSplit.py @@ -1,23 +1,11 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# coding:utf-8 """ -----Introduction----- [Core][Forward] Split deviceList. ['1.1.1.1','2.2.2.2-2.2.2.4'] -> ['1.1.1.1','2.2.2.2','2.2.2.3','2.2.2.4'] -Author: Skate from CSDN blog. Wang Zhe +Author: Skate from CSDN blog. Azrael """ diff --git a/lib/forward/utils/display.py b/lib/forward/utils/display.py deleted file mode 100755 index 6257cd1..0000000 --- a/lib/forward/utils/display.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -import sys -import errno - - -class Display(object): - ''' - Display messages on screen if necessary. - ''' - def __init__(self): - super(Display, self).__init__() - - def display(self, msg, stderr=False): - ''' display a message to the user ''' - if not msg.endswith(u'\n'): - msg += u'\n' - output = sys.stderr if stderr else sys.stdout - output.write(msg) - try: - output.flush() - except IOError as e: - if e.errno != errno.EPIPE: - raise diff --git a/lib/forward/utils/error.py b/lib/forward/utils/error.py deleted file mode 100755 index bee9083..0000000 --- a/lib/forward/utils/error.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - - -class ForwardError(Exception): - ''' - This is the base class for all errors raised from Forward code. - ''' - pass - - -class ForwardScriptError(ForwardError): - ''' - This is the user script error. - ''' - pass diff --git a/lib/forward/utils/forwardError.py b/lib/forward/utils/forwardError.py index 3f59a44..2e735ab 100644 --- a/lib/forward/utils/forwardError.py +++ b/lib/forward/utils/forwardError.py @@ -1,17 +1,5 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- """ #Author: Cheung Kei-Chuen diff --git a/lib/forward/utils/log.py b/lib/forward/utils/log.py deleted file mode 100755 index 5f371e8..0000000 --- a/lib/forward/utils/log.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -import os -import sys -import getpass -import logging -from logging.handlers import TimedRotatingFileHandler - -from forward import constants as C -from forward.utils.boolean import boolean -from forward.utils.error import ForwardError - -formatter = logging.Formatter(C.DEFAULT_LOG_FORMAT, C.DEFAULT_DATE_FORMAT) - -default_handler = logging.StreamHandler(sys.__stdout__) -default_handler.formatter = formatter -mypid = str(os.getpid()) -user = getpass.getuser() -logger = logging.getLogger("p=%s u=%s |" % (mypid, user)) -logger.addHandler(default_handler) -logger.setLevel(eval('logging.%s' % C.DEFAULT_LOGLEVEL)) - - -def check_loglevel(level): - ''' check log level legitimacy ''' - if isinstance(level, str): - if level.isalpha(): - level = level.upper() - if level in logging._levelNames: - level = logging._levelNames[level] - elif level.isdigit(): - level = int(level) - if not (isinstance(level, int) and level in logging._levelNames): - raise ForwardError('Unknown Loglevel.') - return level - - -def set_loglevel_only(level=C.DEFAULT_LOGLEVEL): - ''' set log level only ''' - try: - level = check_loglevel(level) - logger.setLevel(level) - except: - raise - return logger - - -def add_file_logger( - level=C.DEFAULT_LOGLEVEL, - file=C.DEFAULT_FORWARD_LOG_PATH, default=1): - ''' add a file logger ''' - # check file legitimacy - if file and ((os.path.exists(file) and os.access(file, os.W_OK)) or - os.access(os.path.dirname(file), os.W_OK)): - # add log file handler - handler = TimedRotatingFileHandler( - filename=file, when='d', backupCount=1) - # set log format - handler.formatter = formatter - logger.addHandler(handler) - if not boolean(default): - logger.removeHandler(default_handler) - # set log level - level = check_loglevel(level) - logger.setLevel(level) - else: - raise ForwardError('Log File Illegal.') - return logger diff --git a/lib/forward/utils/loginThread.py b/lib/forward/utils/loginThread.py index c386892..819ba51 100644 --- a/lib/forward/utils/loginThread.py +++ b/lib/forward/utils/loginThread.py @@ -1,30 +1,18 @@ -# This file is part of Forward. +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael """ -----Introduction----- [Core][Forward] Login method thread function, used for the initialize multithread step +Author: Azrael """ -import six - def loginThread(instance): # Login method thread function, used for the initialize multithread step if not instance.isLogin: result = instance.login() if not result['status']: - six.print_('[Login Error]: %s :%s' % (instance.ip, result['errLog'])) - # print '[Login Error]: %s :%s' % (instance.ip, result['errLog']) + print '[Login Error]: %s :%s' % (instance.ip, result['errLog']) diff --git a/lib/forward/utils/output.py b/lib/forward/utils/output.py deleted file mode 100755 index 0cc7745..0000000 --- a/lib/forward/utils/output.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -import os - -from forward import constants as C -from forward.utils.error import ForwardError -from forward.utils.display import Display - - -class Output: - - @staticmethod - def output(data, path, format): - ''' runs a child defined method using the ouput_ pattern ''' - if format not in C.DEFAULT_OUTPUT_TYPES: - raise ForwardError('Output Type Illegal.') - output_function = getattr(Output, "output_%s" % format) - if format == 'stdout': - return output_function(data) - if path and os.path.isdir(os.path.dirname(path)): - return output_function(data, path) - else: - raise ForwardError('Output Path Illegal.') - - @staticmethod - def output_stdout(data): - '''print data to standard output''' - data = to_string(data) - delta = 80 - display = Display() - display.display('\r\nOUTPUT%s' % ('-' * 74)) - for i in range(0, len(data), delta): - display.display(data[i:(i + delta)]) - i += delta - - @staticmethod - def output_txt(data, path): - '''write data to specified text file''' - data = to_string(data) - with open('%s.txt' % path, 'w') as f: - f.write(data) - - @staticmethod - def output_xls(data, path): - '''write data to specified excel''' - pass - - -def to_string(data): - try: - data = str(data) - return data - except: - raise ForwardError('Output FORMAT Illegal.') diff --git a/lib/forward/utils/paraCheck.py b/lib/forward/utils/paraCheck.py index 72d9c45..d4d1bcc 100644 --- a/lib/forward/utils/paraCheck.py +++ b/lib/forward/utils/paraCheck.py @@ -1,22 +1,12 @@ -# This file is part of Forward. +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael """ -----Introduction----- [Core][Forward] addTargets parameters legal check function -Author: Wang Zhe +Author: Azrael """ @@ -48,34 +38,3 @@ def paraCheck(targets): return bool_legal else: return False - - -def int_to_mask(mask_int): - # 24 --> 255.25.255.0 - bin_arr = ['0' for i in range(32)] - for i in range(mask_int): - bin_arr[i] = '1' - tmpmask = [''.join(bin_arr[i * 8:i * 8 + 8]) for i in range(4)] - tmpmask = [str(int(tmpstr, 2)) for tmpstr in tmpmask] - return '.'.join(tmpmask) - - -def mask_to_int(mask): - # 255.255.255.0 --> 24 - return sum(bin(int(i)).count('1') for i in mask.split('.')) - - -def checkIP(ip): - seg = ip.split(".") - if len(seg) != 4: - return False - else: - return True - for i in seg: - try: - i = int(i) - if i < 0 or i > 255: - return False - except Exception: - return False - return True diff --git a/lib/forward/utils/parse.py b/lib/forward/utils/parse.py deleted file mode 100755 index ed9b41a..0000000 --- a/lib/forward/utils/parse.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -import re - - -def is_quoted(data): - return len(data) > 1 and data[0] == data[-1] \ - and data[0] in ('"', "'") and data[-2] != '\\' - - -def unquote(data): - """ - removes first and last quotes from a string, - if the string starts and ends with the same quotes - """ - if is_quoted(data): - return data[1:-1] - return data - - -def check_ip_format(ip_str): - pattern_string = r""" - \b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. - (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. - (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\. - (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b - """ - pattern = re.compile(pattern_string, re.X) - if re.match(pattern, ip_str): - return True - else: - return False - - -def ip_to_num(ip): - ''' ip address transformat into binary ''' - ip = [int(x) for x in ip.split('.')] - return ip[0] << 24 | ip[1] << 16 | ip[2] << 8 | ip[3] - - -def num_to_ip(num): - ''' binary ip address transformat into x.x.x.x ''' - return '%s.%s.%s.%s' % ((num & 0xff000000) >> 24, - (num & 0x00ff0000) >> 16, - (num & 0x0000ff00) >> 8, - num & 0x000000ff) - - -def get_ip_in_range(ip_range): - """ - input 'x.x.x.x-y.y.y.y' or 'z.z.z.z' - output all ip within list belongs to 'x.x.x.x-y.y.y.y', - except '0.0.0.0' - """ - ip = [ip_to_num(x) for x in ip_range.split('-')] - return [num_to_ip(x) for x in range(ip[0], ip[-1] + 1) if x & 0xff] - - -def get_ip_list(inventory): - """ - input ['1.1.1.1','2.2.2.2-2.2.3.4'] - output all legal ip address within list - """ - ip_list = [] - for x in inventory: - ip_list.extend(get_ip_in_range(x)) - return ip_list diff --git a/lib/forward/utils/path.py b/lib/forward/utils/path.py deleted file mode 100755 index f3e4b6d..0000000 --- a/lib/forward/utils/path.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- -# -# (c) 2016, Leann Mak -# -# This file is part of Forward. - -import os -from errno import EEXIST - -from forward.utils.error import ForwardError - -__all__ = ['purepath', 'makedirs_safe'] - - -def purepath(path): - """ - returns a path that is free of symlinks, environment - variables, relative path traversals and symbols (~) - - example: - '$HOME/../../var/mail' becomes '/var/spool/mail' - """ - return os.path.normpath( - os.path.realpath(os.path.expanduser( - os.path.expandvars(path)))) - - -def makedirs_safe(path, mode=None): - """ safe way to create dirs in muliprocess/thread environments """ - path = purepath(path) - if not os.path.exists(path): - try: - if mode: - os.makedirs(path, mode) - else: - os.makedirs(path) - except OSError as e: - if e.errno != EEXIST: - raise ForwardError( - 'Unable to create local directories(%s): %s' - % (path, str(e))) diff --git a/lib/forward/utils/sshv1.py b/lib/forward/utils/sshv1.py index 8f26f62..a2bcd27 100644 --- a/lib/forward/utils/sshv1.py +++ b/lib/forward/utils/sshv1.py @@ -1,20 +1,9 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/python +# coding:utf-8 """ -----Introduction----- [Core][forward] Function for sshv1, by using pexpect module. +Author: Cheung Kei-Chuen,Wangzhe """ import os import sys @@ -29,10 +18,9 @@ def checkPassWord(ssh, password, P=False): "errLog": ""} # througt SSH chanel determine whether there is interaction password prompt if not P: - ssh.expect([r"[Pp]assword:", ".*"]) + ssh.expect([r"[Pp]assword", ".*"]) ssh.send(password + '\n') - # Multiple identical characters may appear - p = ssh.expect([r"[Pp]assword:", r"(>|#|\]|\$){1,}.*$"]) + p = ssh.expect([r"[Pp]assword", r"(>|#|\]|\$) *$"]) if p == 0: njInfo['errLog'] = "Username or Password wrong" # if expect characters is password,then the account password is wrong @@ -64,7 +52,7 @@ def __init__(self, def login(self, password=None): pexpect.spawn.__init__(self, 'ssh -p %d %s@%s' % (self.port, self.username, self.ip)) self.setwinsize(1000, 1000) - i = self.expect([r'[Pp]assword.*:.*', + i = self.expect([r'[Pp]assword', 'Are you sure you want to continue connecting (yes/no)?', 'Connection refused', pexpect.TIMEOUT], self.timeout) if i == 0: diff --git a/lib/forward/utils/sshv2.py b/lib/forward/utils/sshv2.py index 046c944..4da7857 100644 --- a/lib/forward/utils/sshv2.py +++ b/lib/forward/utils/sshv2.py @@ -1,22 +1,12 @@ -# This file is part of Forward. +#!/usr/bin/env python +# -*- coding:utf-8 -*- # -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# (c) 2017, Azrael """ -----Introduction----- [Core][forward] Function for sshv2, by using paramiko module. -Author: Cheung Kei-Chuen, Wang Zhe +Author: Cheung Kei-Chuen, Azrael """ import paramiko @@ -33,9 +23,9 @@ def sshv2(ip='', username='', password='', timeout=30, port=22): port = int(port) ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) - ssh.connect(ip, port, username, password, timeout=timeout, allow_agent=False, look_for_keys=False) + ssh.connect(ip, port, username, password, timeout=timeout) njInfo['content'] = ssh - except Exception as e: + except Exception, e: njInfo['status'] = False njInfo['errLog'] = str(e) return njInfo diff --git a/lib/forward/utils/telnet.py b/lib/forward/utils/telnet.py index 308bd60..17f8376 100644 --- a/lib/forward/utils/telnet.py +++ b/lib/forward/utils/telnet.py @@ -1,22 +1,10 @@ -# This file is part of Forward. -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# coding:utf-8 """ -----Introduction----- [Core][forward] Function for telnet, by using telnetlib module. -Author: Wang Zhe, Cheung Kei-Chuen +Author: Azrael, Cheung Kei-Chuen """ import telnetlib @@ -61,7 +49,7 @@ def login(self, username, password): njInfo['errLog'] = 'Username or Password wrong' else: njInfo['errLog'] = 'Login status is unknown' - except Exception as e: + except Exception, e: njInfo['errLog'] = str(e) return njInfo diff --git a/nosetests.ini b/nosetests.ini index 7781bce..2a9ec97 100644 --- a/nosetests.ini +++ b/nosetests.ini @@ -3,9 +3,9 @@ verbosity=3 where=unittests stop=1 with-xunit=1 -xunit-file=unittests/nosetests.xml +xunit-file=unittests/unittests/nosetests.xml with-coverage=1 cover-package=lib/forward cover-xml=1 -cover-xml-file=coverage.xml +cover-xml-file=unittests/unittests/coverage.xml exe=1 diff --git a/protocol/flake8 b/protocol/flake8 index ce1ca2c..c446e7e 100644 --- a/protocol/flake8 +++ b/protocol/flake8 @@ -1,4 +1,4 @@ [flake8] -exclude = unittests,build,tests,migrations,.git,.tox,docs,*egg,env,instance,callback -ignore = E402, E123, F401, W605, E501, W601 +exclude = unittests,build,tests,migrations,.git,.tox,docs,*egg,env,instance,callback,runScriptAdapter,runShellAdapter +ignore = E402, E123, F401 max-line-length = 120 diff --git a/requirements.txt b/requirements.txt old mode 100755 new mode 100644 index 8a2ec12..2dfe1f2 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,3 @@ flake8==2.4.1 mock==2.0.0 paramiko==1.16.0 pexpect>=4.2.0 -nose>=1.3.0 -coverage>=4.4.0 -six>=1.0.0 diff --git a/setup.py b/setup.py old mode 100755 new mode 100644 index 2ea4d91..3e3e422 --- a/setup.py +++ b/setup.py @@ -1,20 +1,3 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - """A setuptools based setup module. See: https://packaging.python.org/en/latest/distributing.html diff --git a/unittests/__init__.py b/unittests/__init__.py index 51df897..e69de29 100644 --- a/unittests/__init__.py +++ b/unittests/__init__.py @@ -1,16 +0,0 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . diff --git a/unittests/baseBaseBrocade.py b/unittests/baseBaseBrocade.py index b2cb9ab..5a7bb35 100644 --- a/unittests/baseBaseBrocade.py +++ b/unittests/baseBaseBrocade.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testAdx03100.py b/unittests/testAdx03100.py index 5363878..377029c 100644 --- a/unittests/testAdx03100.py +++ b/unittests/testAdx03100.py @@ -1,24 +1,10 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError -from forward.devclass.baseBrocade import BASEBROCADE +from forward.devclass.baseCisco import BASECISCO class deviceClassAdx03100(unittest.TestCase): @@ -62,4 +48,5 @@ def test_inherit_check(self): # Inherit from BASESSHV2 cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) - self.assertEquals(cls.__bases__[0], BASEBROCADE) + self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testAsa.py b/unittests/testAsa.py index d897173..73440c6 100644 --- a/unittests/testAsa.py +++ b/unittests/testAsa.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testAsr1006.py b/unittests/testAsr1006.py index f12954a..5a7b1b3 100644 --- a/unittests/testAsr1006.py +++ b/unittests/testAsr1006.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testBaseBaer.py b/unittests/testBaseBaer.py index 3fc7d43..d9e0b44 100644 --- a/unittests/testBaseBaer.py +++ b/unittests/testBaseBaer.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseCisco.py b/unittests/testBaseCisco.py index e732f14..ff5bb28 100644 --- a/unittests/testBaseCisco.py +++ b/unittests/testBaseCisco.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseDepp.py b/unittests/testBaseDepp.py index 21323a2..34ba10d 100644 --- a/unittests/testBaseDepp.py +++ b/unittests/testBaseDepp.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseF5.py b/unittests/testBaseF5.py index eed9f81..0511dfa 100644 --- a/unittests/testBaseF5.py +++ b/unittests/testBaseF5.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseFenghuo.py b/unittests/testBaseFenghuo.py index 8317732..f0e8aa5 100644 --- a/unittests/testBaseFenghuo.py +++ b/unittests/testBaseFenghuo.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseFortinet.py b/unittests/testBaseFortinet.py index d6c981e..7c9392f 100644 --- a/unittests/testBaseFortinet.py +++ b/unittests/testBaseFortinet.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseHuawei.py b/unittests/testBaseHuawei.py index 01772f5..c55b254 100644 --- a/unittests/testBaseHuawei.py +++ b/unittests/testBaseHuawei.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseJuniper.py b/unittests/testBaseJuniper.py index 9aff7d1..fe61070 100644 --- a/unittests/testBaseJuniper.py +++ b/unittests/testBaseJuniper.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASETELNET) + diff --git a/unittests/testBaseLinux.py b/unittests/testBaseLinux.py index 316c48e..1585746 100644 --- a/unittests/testBaseLinux.py +++ b/unittests/testBaseLinux.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASESSHV2) + diff --git a/unittests/testBaseMaipu.py b/unittests/testBaseMaipu.py index 01b2840..dab7925 100644 --- a/unittests/testBaseMaipu.py +++ b/unittests/testBaseMaipu.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseRaisecom.py b/unittests/testBaseRaisecom.py index cdfd870..e0512e9 100644 --- a/unittests/testBaseRaisecom.py +++ b/unittests/testBaseRaisecom.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASESSHV2) + diff --git a/unittests/testBaseSSHV1.py b/unittests/testBaseSSHV1.py index 923f4d1..5b722d5 100644 --- a/unittests/testBaseSSHV1.py +++ b/unittests/testBaseSSHV1.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseSSHV2.py b/unittests/testBaseSSHV2.py index 1b4944d..1b072ce 100644 --- a/unittests/testBaseSSHV2.py +++ b/unittests/testBaseSSHV2.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseTELNET.py b/unittests/testBaseTELNET.py index c80444c..441f87f 100644 --- a/unittests/testBaseTELNET.py +++ b/unittests/testBaseTELNET.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseVenustech.py b/unittests/testBaseVenustech.py index e423de2..953f61a 100644 --- a/unittests/testBaseVenustech.py +++ b/unittests/testBaseVenustech.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testBaseZte.py b/unittests/testBaseZte.py index d571c36..62f3479 100644 --- a/unittests/testBaseZte.py +++ b/unittests/testBaseZte.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testC2960.py b/unittests/testC2960.py index b97425a..dbb243a 100644 --- a/unittests/testC2960.py +++ b/unittests/testC2960.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testC4510.py b/unittests/testC4510.py index 30beca9..dc3999c 100644 --- a/unittests/testC4510.py +++ b/unittests/testC4510.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testC6506.py b/unittests/testC6506.py index 1a75135..0b232dd 100644 --- a/unittests/testC6506.py +++ b/unittests/testC6506.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testC6509.py b/unittests/testC6509.py index 7245e0b..fc2d616 100644 --- a/unittests/testC6509.py +++ b/unittests/testC6509.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,5 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + + diff --git a/unittests/testDevclassInit.py b/unittests/testDevclassInit.py index cede8f1..0df61d0 100644 --- a/unittests/testDevclassInit.py +++ b/unittests/testDevclassInit.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testE1000e.py b/unittests/testE1000e.py index 340afd6..c4b97e1 100644 --- a/unittests/testE1000e.py +++ b/unittests/testE1000e.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testE8000e.py b/unittests/testE8000e.py index 80c2580..a6a2ea3 100644 --- a/unittests/testE8000e.py +++ b/unittests/testE8000e.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testE8160e.py b/unittests/testE8160e.py index 0b238ac..3cca229 100644 --- a/unittests/testE8160e.py +++ b/unittests/testE8160e.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testF1000.py b/unittests/testF1000.py index 962f641..86e62a4 100644 --- a/unittests/testF1000.py +++ b/unittests/testF1000.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testF510000.py b/unittests/testF510000.py index 82dee13..c1295ec 100644 --- a/unittests/testF510000.py +++ b/unittests/testF510000.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testFg1240.py b/unittests/testFg1240.py index 201a385..08f1aa2 100644 --- a/unittests/testFg1240.py +++ b/unittests/testFg1240.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testFg3040.py b/unittests/testFg3040.py index d583444..be190b4 100644 --- a/unittests/testFg3040.py +++ b/unittests/testFg3040.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testFg3950.py b/unittests/testFg3950.py index ae1a28c..d33a8ee 100644 --- a/unittests/testFg3950.py +++ b/unittests/testFg3950.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testM6000.py b/unittests/testM6000.py index d1b2d6e..ca8dc88 100644 --- a/unittests/testM6000.py +++ b/unittests/testM6000.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testMainClass.py b/unittests/testMainClass.py index ad99b59..f2b27d2 100644 --- a/unittests/testMainClass.py +++ b/unittests/testMainClass.py @@ -1,19 +1,5 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +#!/usr/bin/env python +# -*- coding:utf-8 -*- import unittest import importlib diff --git a/unittests/testMx960.py b/unittests/testMx960.py index 07234c3..8dc3d5c 100644 --- a/unittests/testMx960.py +++ b/unittests/testMx960.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testN5548.py b/unittests/testN5548.py index 8eceb5f..5976bfe 100644 --- a/unittests/testN5548.py +++ b/unittests/testN5548.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testN5596.py b/unittests/testN5596.py index c3bab40..896aa65 100644 --- a/unittests/testN5596.py +++ b/unittests/testN5596.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testN7010.py b/unittests/testN7010.py index c853d33..c1f16f3 100644 --- a/unittests/testN7010.py +++ b/unittests/testN7010.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testN7018.py b/unittests/testN7018.py index 5971d20..025b42e 100644 --- a/unittests/testN7018.py +++ b/unittests/testN7018.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testN7710.py b/unittests/testN7710.py index 6470d3a..7eb23c4 100644 --- a/unittests/testN7710.py +++ b/unittests/testN7710.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testN7718.py b/unittests/testN7718.py index a1f1aa4..2a0d200 100644 --- a/unittests/testN7718.py +++ b/unittests/testN7718.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -62,3 +48,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASECISCO) + diff --git a/unittests/testNe40ex16.py b/unittests/testNe40ex16.py index d93c61a..f7a8d68 100644 --- a/unittests/testNe40ex16.py +++ b/unittests/testNe40ex16.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testNe40ex3.py b/unittests/testNe40ex3.py index 21dc950..3da7141 100644 --- a/unittests/testNe40ex3.py +++ b/unittests/testNe40ex3.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -62,3 +48,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testR3048g.py b/unittests/testR3048g.py index f5c3e8f..6c016e5 100644 --- a/unittests/testR3048g.py +++ b/unittests/testR3048g.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASERAISECOM) + diff --git a/unittests/testRg5510.py b/unittests/testRg5510.py index 2e88477..ca55860 100644 --- a/unittests/testRg5510.py +++ b/unittests/testRg5510.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASERUIJIE) + diff --git a/unittests/testS3300.py b/unittests/testS3300.py index 2a0c1ee..beb0d98 100644 --- a/unittests/testS3300.py +++ b/unittests/testS3300.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testS5328.py b/unittests/testS5328.py index d4fffe6..e463793 100644 --- a/unittests/testS5328.py +++ b/unittests/testS5328.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testS5352.py b/unittests/testS5352.py index bc31d73..2b65423 100644 --- a/unittests/testS5352.py +++ b/unittests/testS5352.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testS5800.py b/unittests/testS5800.py index f9ac729..e9ab355 100644 --- a/unittests/testS5800.py +++ b/unittests/testS5800.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEFENGHUO) + diff --git a/unittests/testS8512.py b/unittests/testS8512.py index 6bf1185..d77d428 100644 --- a/unittests/testS8512.py +++ b/unittests/testS8512.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testS9303.py b/unittests/testS9303.py index 9d2d870..34f9a62 100644 --- a/unittests/testS9303.py +++ b/unittests/testS9303.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testS9306.py b/unittests/testS9306.py index 546ff4a..f65656b 100644 --- a/unittests/testS9306.py +++ b/unittests/testS9306.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testS9312.py b/unittests/testS9312.py index f65ad47..836eaa2 100644 --- a/unittests/testS9312.py +++ b/unittests/testS9312.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -62,3 +48,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEHUAWEI) + diff --git a/unittests/testSr7750.py b/unittests/testSr7750.py index 6aee887..4cb518d 100644 --- a/unittests/testSr7750.py +++ b/unittests/testSr7750.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEBAER) + diff --git a/unittests/testSr7950.py b/unittests/testSr7950.py index b8b01ad..0d38d2f 100644 --- a/unittests/testSr7950.py +++ b/unittests/testSr7950.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testSrx3400.py b/unittests/testSrx3400.py index 95c07fc..ce507f7 100644 --- a/unittests/testSrx3400.py +++ b/unittests/testSrx3400.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testUsg1000.py b/unittests/testUsg1000.py index 9f61919..74fc393 100644 --- a/unittests/testUsg1000.py +++ b/unittests/testUsg1000.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -63,3 +49,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BASEVENUSTECH) + diff --git a/unittests/testVlb.py b/unittests/testVlb.py index 6d67cfd..18ac5b4 100644 --- a/unittests/testVlb.py +++ b/unittests/testVlb.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError diff --git a/unittests/testVyoslinux.py b/unittests/testVyoslinux.py index 3f239e1..a2572a5 100644 --- a/unittests/testVyoslinux.py +++ b/unittests/testVyoslinux.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError @@ -61,3 +47,4 @@ def test_inherit_check(self): cls = getattr(importlib.import_module('forward.devclass.{dev}'.format(dev=self.deviceClassName)), self.deviceClassName.upper()) self.assertEquals(cls.__bases__[0], BCLINUX7) + diff --git a/unittests/testZx5952.py b/unittests/testZx5952.py index 914b08f..ba0d40d 100644 --- a/unittests/testZx5952.py +++ b/unittests/testZx5952.py @@ -1,20 +1,6 @@ -# (c) 2015-2018, Wang Zhe , Zhang Qi Chuan -# -# This file is part of Ansible -# -# Forward is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Forward is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - +#!/usr/bin/env python +# encodint:utf-8 +# Author:Cheung Kei-Chuen import unittest import importlib from forward.utils.forwardError import ForwardError