mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
add support for juniper protocol-nh type, see #83
This commit is contained in:
@@ -22,9 +22,11 @@ def parse_juniper(output: Iterable) -> Dict: # noqa: C901
|
||||
for i, response in enumerate(output):
|
||||
try:
|
||||
parsed = xmltodict.parse(
|
||||
response, force_list=("rt", "rt-entry", "community", "nh")
|
||||
response, force_list=("rt", "rt-entry", "community")
|
||||
)
|
||||
|
||||
log.debug("Initially Parsed Response: \n{}", parsed)
|
||||
|
||||
if "rpc-reply" in parsed.keys():
|
||||
parsed_base = parsed["rpc-reply"]["route-information"]
|
||||
elif "route-information" in parsed.keys():
|
||||
|
@@ -1,7 +1,7 @@
|
||||
"""Data Models for Parsing Juniper XML Response."""
|
||||
|
||||
# Standard Library
|
||||
from typing import List
|
||||
from typing import Dict, List
|
||||
|
||||
# Third Party
|
||||
from pydantic import StrictInt, StrictStr, StrictBool, validator, root_validator
|
||||
@@ -49,10 +49,27 @@ class JuniperRouteTableEntry(_JuniperBase):
|
||||
@root_validator(pre=True)
|
||||
def validate_optional_flags(cls, values):
|
||||
"""Flatten & rename keys prior to validation."""
|
||||
next_hop = values.pop("nh")
|
||||
selected_next_hop = ""
|
||||
next_hops = []
|
||||
nh = None
|
||||
|
||||
for hop in next_hop:
|
||||
# Handle Juniper's 'Router' Next Hop Type
|
||||
if "nh" in values:
|
||||
nh = values.pop("nh")
|
||||
|
||||
# Handle Juniper's 'Indirect' Next Hop Type
|
||||
if "protocol-nh" in values:
|
||||
nh = values.pop("protocol-nh")
|
||||
|
||||
# Force the next hops to be a list
|
||||
if isinstance(nh, Dict):
|
||||
nh = [nh]
|
||||
|
||||
if nh is not None:
|
||||
next_hops.extend(nh)
|
||||
|
||||
# Extract the 'to:' value from the next-hop
|
||||
selected_next_hop = ""
|
||||
for hop in next_hops:
|
||||
if "selected-next-hop" in hop:
|
||||
selected_next_hop = hop.get("to", "")
|
||||
break
|
||||
|
Reference in New Issue
Block a user