- Added `.idea` to `.gitignore` to exclude IDE configuration files. - Introduced `pydantic` version `2.12.5` as a dependency in `pyproject.toml` and `uv.lock`. - Added `annotated-types` as a new dependency in `uv.lock`. - Refactored `BaseDevice` class to include abstract methods for device properties and loading templates. - Created `Interfaces`, `System`, `Vlans`, and `Device` models in a new `contract.py` file for structured data handling. - Updated `Mikrotik` class to implement the new `BaseDevice` structure and added a template loading method.
38 lines
847 B
Python
38 lines
847 B
Python
from abc import ABC, abstractmethod
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from oxi.interfaces.contract import Interfaces, System, Vlans
|
|
|
|
|
|
class BaseDevice(ABC):
|
|
@property
|
|
@abstractmethod
|
|
def template(self) -> str:
|
|
"""
|
|
:return:
|
|
"""
|
|
|
|
@abstractmethod
|
|
def vlans(self) -> "Vlans": ...
|
|
|
|
@abstractmethod
|
|
def interfaces(self) -> "Interfaces": ...
|
|
|
|
@abstractmethod
|
|
def system(self) -> "System": ...
|
|
|
|
def __load_template(self):
|
|
path = Path(__file__).parent / "template" / self.template
|
|
if not path.exists():
|
|
raise FileNotFoundError(f"Template {self.template} not found")
|
|
return path.read_text(encoding="utf-8")
|
|
|
|
def run(self):
|
|
self.load = self.__load_template()
|
|
return self.load
|
|
|
|
|
|
BaseDevice()
|