- Introduced a new method `_validate_template_groups` in `BaseDevice` to ensure TTP templates declare all required and optional sections. - Updated `_REQUIRED_SECTIONS` and added `_OPTIONAL_SECTIONS` to improve template validation. - Modified the `vlans` method in `Mikrotik` to streamline raw data handling and added debug print statements for clarity. - Revised the Mikrotik TTP template to include structured variable definitions and improved group handling for interfaces and VLANs.
33 lines
790 B
Python
33 lines
790 B
Python
import re
|
|
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"]:
|
|
raw = self._raw.get("vlans", [])
|
|
print(raw)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
with open("../../test.txt") as file:
|
|
data = file.read()
|
|
mikr = Mikrotik(data)
|
|
mikr.parse()
|
|
print(mikr.load)
|