- 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.
27 lines
742 B
Python
27 lines
742 B
Python
import os
|
|
from oxi.interfaces import register_parser
|
|
from oxi.interfaces.base import BaseDevice
|
|
|
|
|
|
@register_parser(["routeros", "ros", "mikrotik"])
|
|
class Mikrotik(BaseDevice):
|
|
template = "mikrotik.ttp"
|
|
|
|
# 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 vlans(self) -> list["Vlans"]:
|
|
# return [Vlans(**item) for item in self._raw.get("vlans")]
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print(os.path.abspath(os.curdir))
|
|
with open("./test.txt") as file:
|
|
data = file.read()
|
|
mikr = Mikrotik(data)
|
|
print(mikr.parse().json())
|