Merge pull request 'dev' (#5) from dev into main
All checks were successful
CI / lint (push) Successful in 25s
CI / test (3.10) (push) Successful in 27s
CI / test (3.11) (push) Successful in 40s
CI / test (3.12) (push) Successful in 37s
CI / test (3.13) (push) Successful in 37s
CI / ci-success (push) Successful in 2s

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2026-07-23 13:11:50 +03:00
3 changed files with 42 additions and 5 deletions

View File

@@ -10,6 +10,9 @@ from .interfaces import BaseDevice, device_registry
if TYPE_CHECKING: if TYPE_CHECKING:
from requests import Session from requests import Session
from oxi.interfaces.contract import Interfaces, System, Vlans
TModel = TypeVar("TModel", bound=BaseModel) TModel = TypeVar("TModel", bound=BaseModel)
@@ -20,7 +23,7 @@ class ModelView(Generic[TModel]):
def dump_json(self) -> str: def dump_json(self) -> str:
if isinstance(self._model, list): if isinstance(self._model, list):
return json.dumps( return json.dumps(
[item.model_dump(by_alias=True) for item in self._model], [item.model_dump_json(by_alias=True) for item in self._model],
ensure_ascii=False, ensure_ascii=False,
) )
return self._model.model_dump_json(by_alias=True) return self._model.model_dump_json(by_alias=True)
@@ -83,13 +86,42 @@ class NodeConfig:
return self.text return self.text
@property @property
def vlans(self): def vlans(self) -> list["Vlans"]:
"""
Returns the list of VLAN configurations for the node.
:return: List of Vlans associated with the device.
vlan_id: int
name: str | None = Field(default=None, alias="description")
:rtype: list[oxi.interfaces.contract.Vlans]
"""
return ModelView(self._parsed_data.vlans)
return ModelView(self._parsed_data.vlans) return ModelView(self._parsed_data.vlans)
@property @property
def interfaces(self): def interfaces(self) -> list["Interfaces"]:
"""
Returns the list of Interfaces configurations for the node.
:return: List of Interfaces associated with the device.
name: str = Field(alias="interface")
ip_address: IPv4Address | None = None
mask: int | None = None
description: str | None = None
shutdown: bool = False
:rtype: list[oxi.interfaces.contract.Interfaces]
"""
return ModelView(self._parsed_data.interfaces) return ModelView(self._parsed_data.interfaces)
@property @property
def system(self): def system(self) -> "System":
"""
Returns the Systems configurations for the node.
:return: System associated with the device.
model: str
serial_number: str
version: str
:rtype: oxi.interfaces.contract.System
"""
return ModelView(self._parsed_data.system) return ModelView(self._parsed_data.system)

View File

@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project] [project]
name = "oxipy" name = "oxipy"
version = "0.1.3" version = "0.1.4"
description = "Python client for Oxidized API with TTP-based config parsing" description = "Python client for Oxidized API with TTP-based config parsing"
readme = "README.md" readme = "README.md"
license = "Apache-2.0" license = "Apache-2.0"

View File

@@ -1,4 +1,5 @@
import json import json
from ipaddress import IPv4Address
import pytest import pytest
@@ -66,6 +67,10 @@ class TestListModelView:
def test_dump_uses_aliases(self, interfaces_view): def test_dump_uses_aliases(self, interfaces_view):
dumped = interfaces_view.dump() dumped = interfaces_view.dump()
assert dumped[0]["interface"] == "eth0" assert dumped[0]["interface"] == "eth0"
assert dumped[0]["ip_address"] == IPv4Address("192.168.1.1")
def test_dump_json(self, interfaces_view):
assert interfaces_view.dump_json()
def test_dump_json_keeps_unicode(self): def test_dump_json_keeps_unicode(self):
view = ModelView([Interfaces(interface="eth0", description="Дом")]) view = ModelView([Interfaces(interface="eth0", description="Дом")])