dev #3
@@ -1,29 +1,6 @@
|
||||
from oxi.interfaces import register_parser
|
||||
from oxi.interfaces.base import BaseDevice
|
||||
|
||||
|
||||
def _expand_vlan_range(value: str | list[str]) -> list[str]:
|
||||
if isinstance(value, list):
|
||||
value = ",".join(str(item) for item in value)
|
||||
|
||||
result: list[str] = []
|
||||
for part in value.split(","):
|
||||
part = part.strip()
|
||||
if not part:
|
||||
continue
|
||||
if "-" not in part:
|
||||
result.append(part)
|
||||
continue
|
||||
start_s, end_s = part.split("-", 1)
|
||||
try:
|
||||
start, end = int(start_s), int(end_s)
|
||||
except ValueError:
|
||||
result.append(part)
|
||||
continue
|
||||
if start > end:
|
||||
start, end = end, start
|
||||
result.extend(str(vlan_id) for vlan_id in range(start, end + 1))
|
||||
return result
|
||||
from oxi.interfaces.utils import expand_vlan_range
|
||||
|
||||
|
||||
@register_parser("eltex")
|
||||
@@ -54,15 +31,8 @@ class Eltex(BaseDevice):
|
||||
tail = item.get("vlan_tail")
|
||||
if tail:
|
||||
ids = [*ids, tail] if isinstance(ids, list) else f"{ids},{tail}"
|
||||
for vid in _expand_vlan_range(ids):
|
||||
for vid in expand_vlan_range(ids):
|
||||
if vid in named_vlan:
|
||||
continue
|
||||
vlans.append({"vlan_id": vid})
|
||||
return vlans
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("./test_not_found.txt") as file:
|
||||
data = file.read()
|
||||
eltex = Eltex(data)
|
||||
print(eltex.parse())
|
||||
|
||||
55
tests/fixtures/eltex/config.conf
vendored
Normal file
55
tests/fixtures/eltex/config.conf
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
!
|
||||
Active-image: flash://system/images/mes3300-669-3R3.ros
|
||||
! Version: 6.6.9.3
|
||||
! Commit: 3a5c2e39
|
||||
! Build: 3 (master)
|
||||
! MD5 Digest: 7bc289cc18be560954bd5cb0afd9b2d5
|
||||
! Date: 22-Sep-2025
|
||||
! Time: 12:38:20
|
||||
! Inactive-image: flash://system/images/_image1.bin
|
||||
! Version: 6.6.2
|
||||
! Commit: 3ebc7503
|
||||
! Build: 5 (master)
|
||||
! MD5 Digest: a3f15a788c97c71e07e90d84c0ff3b12
|
||||
! Date: 20-Nov-2023
|
||||
! Time: 16:39:20
|
||||
!
|
||||
! Unit MAC address Hardware version Serial number
|
||||
! ---- ----------------- ---------------- -------------
|
||||
! 1 90:54:b7:6b:9d:40 01.01.01 ESG7007778
|
||||
! 2 90:54:b7:6b:bb:80 01.01.01 ESG7007777
|
||||
!
|
||||
!
|
||||
!
|
||||
interface TenGigabitEthernet1/0/2
|
||||
shutdown
|
||||
description FREE
|
||||
storm-control broadcast pps 3000
|
||||
storm-control multicast pps 3000
|
||||
exit
|
||||
!
|
||||
interface TenGigabitEthernet1/0/11
|
||||
shutdown
|
||||
description FREE
|
||||
storm-control broadcast pps 3000
|
||||
storm-control multicast pps 3000
|
||||
exit
|
||||
!
|
||||
interface vlan 1700
|
||||
name sw-test_HW
|
||||
ip address 13.36.8.1 255.255.255.0
|
||||
exit
|
||||
!
|
||||
vlan database
|
||||
vlan 114-115,120,130,414,610,999-1000,1701-1703,1705,1801,2001,2011
|
||||
vlan 2021-2022,3157-3158,3333-3334
|
||||
exit
|
||||
!
|
||||
interface vlan 666
|
||||
name test
|
||||
exit
|
||||
!
|
||||
interface vlan 777
|
||||
name test2
|
||||
exit
|
||||
!
|
||||
137
tests/fixtures/eltex/config.expected.json
vendored
Normal file
137
tests/fixtures/eltex/config.expected.json
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
{
|
||||
"system": {
|
||||
"model": "",
|
||||
"serial_number": "ESG7007778",
|
||||
"version": "6.6.9.3"
|
||||
},
|
||||
"interfaces": [
|
||||
{
|
||||
"interface": "TenGigabitEthernet1/0/2",
|
||||
"ip_address": null,
|
||||
"mask": null,
|
||||
"description": "FREE"
|
||||
},
|
||||
{
|
||||
"interface": "TenGigabitEthernet1/0/11",
|
||||
"ip_address": null,
|
||||
"mask": null,
|
||||
"description": "FREE"
|
||||
},
|
||||
{
|
||||
"interface": "vlan 1700",
|
||||
"ip_address": "13.36.8.1",
|
||||
"mask": 24,
|
||||
"description": "sw-test_HW"
|
||||
},
|
||||
{
|
||||
"interface": "vlan 666",
|
||||
"ip_address": null,
|
||||
"mask": null,
|
||||
"description": "test"
|
||||
},
|
||||
{
|
||||
"interface": "vlan 777",
|
||||
"ip_address": null,
|
||||
"mask": null,
|
||||
"description": "test2"
|
||||
}
|
||||
],
|
||||
"vlans": [
|
||||
{
|
||||
"vlan_id": 1700,
|
||||
"description": "sw-test_HW"
|
||||
},
|
||||
{
|
||||
"vlan_id": 114,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 115,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 120,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 130,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 414,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 610,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 999,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1000,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1701,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1702,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1703,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1705,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 1801,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 2001,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 2011,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 2021,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 2022,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 3157,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 3158,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 3333,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 3334,
|
||||
"description": null
|
||||
},
|
||||
{
|
||||
"vlan_id": 666,
|
||||
"description": "test"
|
||||
},
|
||||
{
|
||||
"vlan_id": 777,
|
||||
"description": "test2"
|
||||
}
|
||||
]
|
||||
}
|
||||
1
tests/fixtures/eltex/not_found.conf
vendored
Normal file
1
tests/fixtures/eltex/not_found.conf
vendored
Normal file
@@ -0,0 +1 @@
|
||||
node not found
|
||||
Reference in New Issue
Block a user