From c434712309a19b23afb869c823b41730a6e5525e Mon Sep 17 00:00:00 2001 From: IluaAir Date: Wed, 18 Feb 2026 15:45:17 +0300 Subject: [PATCH] Refactor Mikrotik model and update template structure - Changed the parsing method in `NodeConfig` to use `parse()` instead of `parse_config()`. - Updated the template loading path in `BaseDevice` to reflect the new directory structure. - Enhanced the `Mikrotik` class with new methods for `system`, `interfaces`, and `vlans`, including debug print statements. - Expanded the TTP template for Mikrotik to include structured variable definitions and groups for system, interfaces, and VLANs. --- oxi/conf.py | 2 +- oxi/interfaces/base.py | 4 ++- oxi/interfaces/models/mikrotik.py | 16 ++++++++++ oxi/interfaces/models/templates/mikrotik.ttp | 32 +++++++++++++++++--- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/oxi/conf.py b/oxi/conf.py index e39a6b4..1047b2a 100644 --- a/oxi/conf.py +++ b/oxi/conf.py @@ -16,7 +16,7 @@ class NodeConfig: self._device: type[BaseDevice] = device_registry.get(self._model.lower()) if self._device is None: raise ValueError(f"Device model '{self._model}' not found in registry") - self._parsed_data = self._device(self.text).parse_config() + self._parsed_data = self._device(self.text).parse() @cached_property def _response(self): diff --git a/oxi/interfaces/base.py b/oxi/interfaces/base.py index 05adeeb..a159243 100644 --- a/oxi/interfaces/base.py +++ b/oxi/interfaces/base.py @@ -68,8 +68,10 @@ class BaseDevice(ABC): ... def _load_template(self): - path = Path(__file__).parent / "template" / self.template + path = Path(__file__).parent / "models" / "templates" / self.template if not path.exists(): + print("-" * 12) + print(path) raise FileNotFoundError(f"Template {self.template} not found") return path.read_text(encoding="utf-8") diff --git a/oxi/interfaces/models/mikrotik.py b/oxi/interfaces/models/mikrotik.py index b06f949..c84260d 100644 --- a/oxi/interfaces/models/mikrotik.py +++ b/oxi/interfaces/models/mikrotik.py @@ -1,11 +1,27 @@ +from typing import TYPE_CHECKING from oxi.interfaces import register_parser from oxi.interfaces.base import BaseDevice +if TYPE_CHECKING: + from oxi.interfaces.contract import Interfaces, System, Vlans + @register_parser(["routeros", "ros", "mikrotik"]) class Mikrotik(BaseDevice): template = "mikrotik.ttp" + def system(self) -> "System": + print(self._raw["system"]) + print("-" * 12) + + def interfaces(self) -> "Interfaces": + print(f"{self._raw["interfaces"]=}") + print("-" * 12) + + def vlans(self) -> list["Vlans"]: + print(f"{self._raw["vlans"]=}") + print("-" * 12) + if __name__ == "__main__": mikr = Mikrotik() diff --git a/oxi/interfaces/models/templates/mikrotik.ttp b/oxi/interfaces/models/templates/mikrotik.ttp index 02d8a0c..a535494 100644 --- a/oxi/interfaces/models/templates/mikrotik.ttp +++ b/oxi/interfaces/models/templates/mikrotik.ttp @@ -1,7 +1,31 @@ - - + \ No newline at end of file