CI / test (3.10) (push) Successful in 31s
CI / test (3.11) (push) Successful in 29s
CI / test (3.12) (push) Successful in 31s
CI / test (3.10) (pull_request) Successful in 31s
CI / test (3.11) (pull_request) Successful in 28s
CI / test (3.12) (pull_request) Successful in 30s
netOrk reached these through the private _get/_post (netOrk #1113); they are napalm-device-types 4.17's contracts now: - apply_updates passes the packages it is given (it dropped them) and get_update_progress reports the upgrade's state and log. - get_dns_forwards, set_dns_forward (an existing forward of the domain is changed, not doubled) and remove_dns_forward, each applied with a reconfigure; a refusal is raised. - get_ospf translates FRR's diagnostics into neutral terms. Requires napalm-device-types 4.17.0.
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
"""FRR's OSPF state in neutral terms (napalm-device-types ``OspfMixin``).
|
|
|
|
Reads the os-frr plugin's diagnostics (``/api/quagga/diagnostics/...``); the
|
|
field names are FRR's. Whether an interface without neighbours or without
|
|
authentication is a problem is the caller's to decide.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from napalm_device_types import OspfMixin
|
|
|
|
_DIAG = "/api/quagga/diagnostics"
|
|
|
|
|
|
def _interface(ifc: dict[str, Any]) -> dict[str, Any]:
|
|
return {
|
|
"address": ifc.get("ipAddress") or "",
|
|
"prefix_length": int(ifc.get("ipAddressPrefixlen") or 0),
|
|
"area": ifc.get("area") or "",
|
|
"network_type": ifc.get("networkType") or "",
|
|
"authentication": ifc.get("authentication") or "",
|
|
"neighbors": int(ifc.get("nbrCount") or 0),
|
|
"neighbors_adjacent": int(ifc.get("nbrAdjacentCount") or 0),
|
|
"cost": int(ifc.get("cost") or 0),
|
|
}
|
|
|
|
|
|
class OPNsenseOspfMixin(OspfMixin):
|
|
"""Needs the driver's ``_get``."""
|
|
|
|
def get_ospf(self) -> dict[str, Any]:
|
|
"""Router ID, areas and OSPF per interface; empty when OSPF does not run."""
|
|
overview = self._get(f"{_DIAG}/ospfoverview").get("response") or {} # type: ignore[attr-defined]
|
|
interfaces = (self._get(f"{_DIAG}/ospfinterface").get("response") or {}).get("interfaces") or {} # type: ignore[attr-defined]
|
|
return {
|
|
"router_id": overview.get("routerId") or None,
|
|
"areas": list((overview.get("areas") or {}).keys()),
|
|
"interfaces": {name: _interface(ifc) for name, ifc in interfaces.items()},
|
|
}
|