- Changed the parsing method in `NodeConfig` to use `parse()` instead of `parse_config()`. - Updated the template loading path in `BaseDevice` to reflect the new directory structure. - Enhanced the `Mikrotik` class with new methods for `system`, `interfaces`, and `vlans`, including debug print statements. - Expanded the TTP template for Mikrotik to include structured variable definitions and groups for system, interfaces, and VLANs.
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from functools import cached_property
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .interfaces import BaseDevice, device_registry
|
|
|
|
if TYPE_CHECKING:
|
|
from requests import Session
|
|
|
|
|
|
class NodeConfig:
|
|
def __init__(self, session: "Session", full_name: str, model: str, base_url: str):
|
|
self._session = session
|
|
self._full_name = full_name
|
|
self._model = model.lower()
|
|
self._url = f"{base_url}/node/fetch/{full_name}"
|
|
self._device: type[BaseDevice] = device_registry.get(self._model.lower())
|
|
if self._device is None:
|
|
raise ValueError(f"Device model '{self._model}' not found in registry")
|
|
self._parsed_data = self._device(self.text).parse()
|
|
|
|
@cached_property
|
|
def _response(self):
|
|
response = self._session.get(self._url)
|
|
response.raise_for_status()
|
|
return response
|
|
|
|
@property
|
|
def text(self):
|
|
return self._response.text
|
|
|
|
@property
|
|
def json(self):
|
|
return self._response.json()
|
|
|
|
def __str__(self):
|
|
return self.text
|
|
|
|
def vlans(self):
|
|
return self._parsed_data.vlans
|
|
|
|
def l3interfaces(self):
|
|
return self._parsed_data.l3interfaces
|
|
|
|
def vlaninterfaces(self):
|
|
return self._parsed_data.vlaninterfaces
|