Implement Keenetic model and enhance BaseDevice documentation - Added a new `Keenetic` model that registers a parser for KeeneticOS, extending the `BaseDevice` class. - Updated docstrings in the `BaseDevice` class methods to provide clearer descriptions of their functionality and expected data structures. - Introduced `model_config` in the `Vlans` model to enable name-based population. - Removed unnecessary print statements from the `Mikrotik` model methods to streamline output. """
26 lines
746 B
Python
26 lines
746 B
Python
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__":
|
|
with open("../../test.txt") as file:
|
|
data = file.read()
|
|
mikr = Mikrotik(data)
|
|
print(mikr.parse().json())
|