Translating (IOS)¶
As explained in the previous tutorial, a ntc_rosetta driver can both parse and translate between native and yang-based models. In this tutorial we are going to translate data that complies to the openconfig model into native IOS configuration.
Let’s start by loading the needed driver:
[1]:
from ntc_rosetta import get_driver
ios = get_driver("ios", "openconfig")
ios_processor = ios()
Now we need some data:
[2]:
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"
}
}
]
}
},
{
"name": "FastEthernet3",
"config": {
"name": "FastEthernet3",
"type": "iana-if-type:ethernetCsmacd",
"description": "This is Fa3",
"enabled": True
},
"openconfig-if-ethernet:ethernet": {
"openconfig-vlan:switched-vlan": {
"config": {
"interface-mode": "ACCESS",
"access-vlan": 10
}
}
}
},
{
"name": "FastEthernet4",
"config": {
"name": "FastEthernet4",
"type": "iana-if-type:ethernetCsmacd",
"enabled": False
},
"openconfig-if-ethernet:ethernet": {
"openconfig-vlan:switched-vlan": {
"config": {
"interface-mode": "TRUNK",
"trunk-vlans": [
10,
20
]
}
}
}
}
]
},
"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"
}
}
]
}
}
]
}
}
Once we have the data, translating it to native is very simple:
[3]:
native = ios_processor.translate(candidate=data)
We can verify the result by just printing it:
[4]:
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
!