Refactor Eltex model to use centralized VLAN range expansion utility

- Replaced the internal `_expand_vlan_range` function in the `Eltex` class with the new `expand_vlan_range` utility from `utils.py` for improved code maintainability.
- Added a new configuration file `config.conf` for Eltex devices to facilitate testing.
- Introduced an expected output JSON file `config.expected.json` to validate the parsing of Eltex configurations against expected results.
This commit is contained in:
IluaAir
2026-06-07 08:42:41 +03:00
parent 168111e23c
commit 170a2ebf85
4 changed files with 195 additions and 32 deletions

View File

@@ -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())