mirror of
https://github.com/thatmattlove/hyperglass.git
synced 2026-04-17 21:38:27 +00:00
Enhance MikroTik BGP route handling by adding BGPRoute import and simplifying BGPRouteTable initialization
This commit is contained in:
parent
ae6a1a0bb8
commit
e78685d8c6
1 changed files with 20 additions and 25 deletions
|
|
@ -9,7 +9,7 @@ from pydantic import ConfigDict
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.log import log
|
from hyperglass.log import log
|
||||||
from hyperglass.models.data.bgp_route import BGPRouteTable
|
from hyperglass.models.data.bgp_route import BGPRoute, BGPRouteTable # Add BGPRoute import
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
from ..main import HyperglassModel
|
from ..main import HyperglassModel
|
||||||
|
|
@ -249,13 +249,8 @@ def _parse_route_block(block: t.List[str]) -> t.Optional[MikrotikRouteEntry]:
|
||||||
|
|
||||||
|
|
||||||
class MikrotikBGPRouteTable(BGPRouteTable):
|
class MikrotikBGPRouteTable(BGPRouteTable):
|
||||||
"""Bypass validation to align with Huawei parser."""
|
"""Canonical MikroTik BGP Route Table."""
|
||||||
|
# No custom __init__ needed; inherit from BGPRouteTable (which should be a Pydantic model)
|
||||||
def __init__(self, **kwargs):
|
|
||||||
object.__setattr__(self, "vrf", kwargs.get("vrf", "default"))
|
|
||||||
object.__setattr__(self, "count", kwargs.get("count", 0))
|
|
||||||
object.__setattr__(self, "routes", kwargs.get("routes", []))
|
|
||||||
object.__setattr__(self, "winning_weight", kwargs.get("winning_weight", "low"))
|
|
||||||
|
|
||||||
|
|
||||||
class MikrotikBGPTable(MikrotikBase):
|
class MikrotikBGPTable(MikrotikBase):
|
||||||
|
|
@ -287,23 +282,23 @@ class MikrotikBGPTable(MikrotikBase):
|
||||||
def bgp_table(self) -> BGPRouteTable:
|
def bgp_table(self) -> BGPRouteTable:
|
||||||
out = []
|
out = []
|
||||||
for r in self.routes:
|
for r in self.routes:
|
||||||
out.append(
|
route_dict = {
|
||||||
{
|
"prefix": r.prefix,
|
||||||
"prefix": r.prefix,
|
"active": r.active,
|
||||||
"active": r.active,
|
"age": r.age,
|
||||||
"age": r.age,
|
"weight": r.weight,
|
||||||
"weight": r.weight,
|
"med": r.med,
|
||||||
"med": r.med,
|
"local_preference": r.local_preference,
|
||||||
"local_preference": r.local_preference,
|
"as_path": r.as_path,
|
||||||
"as_path": r.as_path,
|
"communities": r.all_communities,
|
||||||
"communities": r.all_communities,
|
"next_hop": r.next_hop,
|
||||||
"next_hop": r.next_hop,
|
"source_as": r.source_as,
|
||||||
"source_as": r.source_as,
|
"source_rid": r.source_rid,
|
||||||
"source_rid": r.source_rid,
|
"peer_rid": r.peer_rid,
|
||||||
"peer_rid": r.peer_rid,
|
"rpki_state": r.rpki_state,
|
||||||
"rpki_state": r.rpki_state,
|
}
|
||||||
}
|
# Instantiate BGPRoute to trigger validation (including external RPKI)
|
||||||
)
|
out.append(BGPRoute(**route_dict))
|
||||||
return MikrotikBGPRouteTable(
|
return MikrotikBGPRouteTable(
|
||||||
vrf="default",
|
vrf="default",
|
||||||
count=len(out),
|
count=len(out),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue