Refactor BaseDevice methods for improved data handling and validation

- Updated the `BaseDevice` class to replace `_raw` with `raw` for consistency in data access.
- Enhanced the `vlans`, `interfaces`, and `system` methods to utilize the new `raw` attribute.
- Introduced a `_validate_contract` method to streamline the validation of parsed data into structured models.
- Adjusted the `Keenetic` and `Mikrotik` models to align with the updated data handling approach, ensuring proper parsing and decoding of interface and VLAN data.
This commit is contained in:
IluaAir
2026-02-22 09:52:17 +03:00
parent 2394296f5b
commit 3635a07b27
4 changed files with 44 additions and 50 deletions

View File

@@ -1,22 +1,21 @@
import os
from oxi.interfaces import register_parser
from oxi.interfaces.base import BaseDevice
from oxi.interfaces.contract import Interfaces, System, Vlans
@register_parser(["routeros", "ros", "mikrotik"])
class Mikrotik(BaseDevice):
template = "mikrotik.ttp"
def system(self) -> "System":
systems = self._raw.get("system")
return System(**systems)
# def system(self) -> "System":
# systems = self._raw.get("system")
# return System(**systems)
def interfaces(self) -> "Interfaces":
return [Interfaces(**item) for item in self._raw.get("interfaces")]
# def interfaces(self) -> "Interfaces":
# return [Interfaces(**item) for item in self._raw.get("interfaces")]
def vlans(self) -> list["Vlans"]:
return [Vlans(**item) for item in self._raw.get("vlans")]
# def vlans(self) -> list["Vlans"]:
# return [Vlans(**item) for item in self._raw.get("vlans")]
if __name__ == "__main__":