- Implemented the `interfaces` and `vlans` methods in the `Keenetic` model to process and decode interface and VLAN data. - Added a `_decode_utf` method to handle UTF-8 encoded descriptions. - Updated the Keenetic TTP template to define structured groups for system, interfaces, and VLANs. - Refactored file paths in the `Mikrotik` model for consistency and clarity.
28 lines
790 B
Python
28 lines
790 B
Python
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 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())
|