Skip to main content

Python Scripts to get schema YANG files from network device

Project description

NETCONF scripts for LNU Campus Network

BRAS 设备 IPoE 认证用户 IPv6 地址溯源程序

一、工作原理

本程序通过 NETCONF 协议获得 BRAS 设备 IPoE 认证用户 MAC、IPv4、IPv6 地址信息,并发送到 syslog 进行记录。可以通过 cron 每二十分钟定时执行本程序,记录用户地址信息,以供事后溯源。

本程序在 H3C SR8808-X 以及华为 ME60 上进行了测试。H3C SR8808-X IPoE 认证功能存在问题,需要关闭 IPv6 认证,目前本程序是按照关闭 IPv6 认证的情况编写的。华为 ME60 的 V800R013C00SPC100 版本软件 NETCONF 接口存在问题,无法正常获得 IPv6 地址。

二、开发环境

本项目使用了 PDM 设置开发环境,src/netconf_lnu/mytest.py 中的函数可以作为测试使用,具体命令类似如下:

pdm run netconf-lnu -c config/config.ini -t dispatch_test

其中 config/config.ini 是配置文件,可以参考 config/config.ini.example 来编写。

src/netconf_lnu/mytest.py 程序中的 download_schema 函数,能够下载网络设备的 YANG 文件,用户可以参考该测试函数编写自己的下载程序。

对于下载后的 YANG 文件,可以利用已经安装的 pyang 程序来浏览,命令如下:

pdm run pyang -f tree schema/huawei-bras-user-manage.yang

虽然可以从设备上获得 YANG 文件,但还是建议在 Netconf Central 查找并浏览。

对于程序基本功能可以通过下面命令进行测试:

pdm run netconf-lnu -c config/config.ini

三、打包部署

本项目可以通过 pdm build 命令可以打包,方便修改后部署。

项目已经在 PyPI 上发布,可以直接通过 pip 安装,以 Debian 类系统为例,可以通过如下命令安装:

apt install pipx
pipx ensurepath
pipx install netconf-lnu

安装后可以直接运行 netconf-lnu 命令进行测试,测试无误后可以建立 cron 配置文件 /etc/cron.d/netconf-lnu,每20分钟运行程序一次,其内容如下:

*/20 * * * * root /root/.local/bin/netconf-lnu -c /etc/netconf-lnu/config.ini

其中 /etc/netconf-lnu/config.ini 为配置文件位置。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

netconf_lnu-2023.12.1.17.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

netconf_lnu-2023.12.1.17-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file netconf_lnu-2023.12.1.17.tar.gz.

File metadata

  • Download URL: netconf_lnu-2023.12.1.17.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.10.4 CPython/3.12.0

File hashes

Hashes for netconf_lnu-2023.12.1.17.tar.gz
Algorithm Hash digest
SHA256 f89e8b6d69b4a120a433b204d60d98b4ebfb1561d7e66864b4f9800d6fd7bb33
MD5 b1616e4ef80666f5d45c2687d8b26204
BLAKE2b-256 43a4cfaa0de0cd88bc9d37df42dd438e9b12b35e74de87396d0d24e48e441cd4

See more details on using hashes here.

File details

Details for the file netconf_lnu-2023.12.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for netconf_lnu-2023.12.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 aed2fdd9a1fb8b2ed7ea7e5f6423db0682945d129d2f85ce92ab51c64881c6cf
MD5 51e935bbd5d185edf6cd07554dd50645
BLAKE2b-256 8f7e2a6b141ed9ed47d0d41c274ee58d2be7d09dc88deed707fab4f8f6fba2e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page