Files
oxipy/oxi/conf.py
IluaAir 16e97692fc Refactor NodeConfig methods for consistency in data access
- Renamed `l3interfaces` to `interfaces` and `vlaninterfaces` to `system` in the `NodeConfig` class to align with updated data structure.
- This change enhances clarity and consistency in method naming, reflecting the underlying data model more accurately.
2026-02-24 22:31:18 +03:00

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._parsed_data.json()
def __str__(self):
return self.text
def vlans(self):
return self._parsed_data.vlans
def interfaces(self):
return self._parsed_data.interfaces
def system(self):
return self._parsed_data.system