行业标准CLIs和YANG之间的缺失桥梁
项目描述
ntc_rosetta
ntc_rosetta利用yangify实现一组“驱动程序”,可以将
- 将网络设备的原生配置/状态转换为符合YANG模型的结构化数据
- 将符合YANG模型的数据结构转换为网络设备的原生配置/数据结构
- 合并配置
安装NTC Rosetta
Pip安装
pip install ntc-rosetta
从源安装
- 克隆ntc-rosetta (
git clone https://github.com/networktocode/ntc-rosetta.git
) - 进入项目根目录 (
cd ntc-rosetta
) pip install poetry
poetry install
开始使用NTC Rosetta的方法
- 开始执行Jupyter笔记本
- 阅读文档
开始执行Jupyter笔记本
步骤1
克隆仓库: $ git clone https://github.com/networktocode/ntc-rosetta.git
步骤2
更改目录到 ntc-rosetta
:$ cd ntc-rosetta
步骤3
构建容器:$ make build_test_containers
步骤4
启动一个容器以便运行Jupyter笔记本:$ make jupyter
步骤5
打开浏览器并导航到以下URL:http://127.0.0.1:8888/tree/docs/tutorials
这些笔记本可以在NTC Rosetta Read the Docs中查看,但不具有交互性。
解析
>>> from ntc_rosetta import get_driver
>>>
>>> ios = get_driver("ios", "openconfig")
>>> ios_driver = ios()
>>> with open("data/ios/config.txt", "r") as f:
>>> config = f.read()
>>> print(config)
interface FastEthernet1
description This is Fa1
shutdown
exit
!
vlan 10
name prod
no shutdown
exit
!
vlan 20
name dev
shutdown
exit
!
>>> parsed = ios_driver.parse(native={"dev_conf": config})
>>> import json
>>> print(json.dumps(parsed.raw_value(), indent=4))
{
"openconfig-interfaces:interfaces": {
"interface": [
{
"name": "FastEthernet1",
"config": {
"name": "FastEthernet1",
"type": "iana-if-type:ethernetCsmacd",
"description": "This is Fa1",
"enabled": false
},
"subinterfaces": {
"subinterface": [
{
"index": 1,
"config": {
"index": 1,
"description": "This is Fa1.1"
}
},
{
"index": 2,
"config": {
"index": 2,
"description": "This is Fa1.2"
}
}
]
}
},
]
},
"openconfig-network-instance:network-instances": {
"network-instance": [
{
"name": "default",
"config": {
"name": "default"
},
"vlans": {
"vlan": [
{
"vlan-id": 10,
"config": {
"vlan-id": 10,
"name": "prod",
"status": "ACTIVE"
}
},
{
"vlan-id": 20,
"config": {
"vlan-id": 20,
"name": "dev",
"status": "SUSPENDED"
}
}
]
}
}
]
}
}
翻译
>>> from ntc_rosetta import get_driver
>>>
>>> ios = get_driver("ios", "openconfig")
>>> ios_processor = ios()
>>> data = {
>>> "openconfig-interfaces:interfaces": {
>>> "interface": [
>>> {
>>> "name": "FastEthernet1",
>>> "config": {
>>> "name": "FastEthernet1",
>>> "type": "iana-if-type:ethernetCsmacd",
>>> "description": "This is Fa1",
>>> "enabled": False
>>> },
>>> "subinterfaces": {
>>> "subinterface": [
>>> {
>>> "index": 1,
>>> "config": {
>>> "index": 1,
>>> "description": "This is Fa1.1"
>>> }
>>> },
>>> {
>>> "index": 2,
>>> "config": {
>>> "index": 2,
>>> "description": "This is Fa1.2"
>>> }
>>> }
>>> ]
>>> }
>>> },
>>> ]
>>> },
>>> "openconfig-network-instance:network-instances": {
>>> "network-instance": [
>>> {
>>> "name": "default",
>>> "config": {
>>> "name": "default"
>>> },
>>> "vlans": {
>>> "vlan": [
>>> {
>>> "vlan-id": 10,
>>> "config": {
>>> "vlan-id": 10,
>>> "name": "prod",
>>> "status": "ACTIVE"
>>> }
>>> },
>>> {
>>> "vlan-id": 20,
>>> "config": {
>>> "vlan-id": 20,
>>> "name": "dev",
>>> "status": "SUSPENDED"
>>> }
>>> }
>>> ]
>>> }
>>> }
>>> ]
>>> }
>>> }
>>> native = ios_processor.translate(candidate=data)
>>> print(native)
interface FastEthernet1
description This is Fa1
shutdown
exit
!
interface FastEthernet1.1
description This is Fa1.1
exit
!
interface FastEthernet1.2
description This is Fa1.2
exit
!
interface FastEthernet3
description This is Fa3
no shutdown
switchport mode access
switchport access vlan 10
exit
!
interface FastEthernet4
shutdown
switchport mode trunk
switchport trunk allowed vlan 10,20
exit
!
vlan 10
name prod
no shutdown
exit
!
vlan 20
name dev
shutdown
exit
!
项目详情
下载文件
下载适用于您平台的文件。如果您不确定该选择哪一个,请了解有关 安装包 的更多信息。
源代码分发
ntc_rosetta-0.2.1.tar.gz (453.1 kB 查看哈希值)
构建分发
ntc_rosetta-0.2.1-py3-none-any.whl (615.9 kB 查看哈希值)