- Replaced the internal `_expand_vlan_range` function in the `Qtech` class with the new `expand_vlan_range` utility from `utils.py` for improved code maintainability. - Added new configuration files `config_1.conf` and `config_2.conf` for Qtech devices to facilitate testing. - Introduced expected output JSON files `config_1.expected.json` and `config_2.expected.json` to validate the parsing of Qtech configurations against expected results.
30 lines
994 B
Python
30 lines
994 B
Python
from oxi.interfaces import register_parser
|
|
from oxi.interfaces.base import BaseDevice
|
|
from oxi.interfaces.utils import expand_vlan_range
|
|
|
|
|
|
@register_parser(["QTECH"])
|
|
class Qtech(BaseDevice):
|
|
template = "qtech.ttp"
|
|
|
|
def vlans(self) -> list[dict]:
|
|
vlans_ttp = self.raw.get("vlans", [])
|
|
vlans: list[dict] = []
|
|
named_vlan: set[str] = set()
|
|
for item in vlans_ttp:
|
|
vlan_id = item.get("vlan_id")
|
|
if vlan_id and "," not in vlan_id and "-" not in vlan_id:
|
|
named_vlan.add(vlan_id)
|
|
vlans.append(item)
|
|
continue
|
|
|
|
ids = item.get("vlan_ids") or vlan_id or ""
|
|
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):
|
|
if vid in named_vlan:
|
|
continue
|
|
vlans.append({"vlan_id": vid})
|
|
return vlans
|