forked from mirrors/thatmattlove-hyperglass
fix empty response handling for structured output
This commit is contained in:
parent
dfe8a2bbec
commit
1a1cad5b40
2 changed files with 22 additions and 20 deletions
|
|
@ -83,23 +83,20 @@ class Connect:
|
|||
log.debug(f"Pre-parsed responses:\n{output}")
|
||||
parsed = ()
|
||||
response = None
|
||||
try:
|
||||
if not self.device.structured_output:
|
||||
for coro in parsers:
|
||||
for response in output:
|
||||
_output = await coro(commands=self.query, output=response)
|
||||
parsed += (_output,)
|
||||
response = "\n\n".join(parsed)
|
||||
elif (
|
||||
self.device.structured_output
|
||||
and self.device.nos in nos_parsers.keys()
|
||||
and self.query_type in nos_parsers[self.device.nos].keys()
|
||||
):
|
||||
func = nos_parsers[self.device.nos][self.query_type]
|
||||
response = func(output)
|
||||
except Exception as err:
|
||||
log.critical(str(err))
|
||||
raise ResponseEmpty(params.messages.parsing_error)
|
||||
|
||||
if not self.device.structured_output:
|
||||
for coro in parsers:
|
||||
for response in output:
|
||||
_output = await coro(commands=self.query, output=response)
|
||||
parsed += (_output,)
|
||||
response = "\n\n".join(parsed)
|
||||
elif (
|
||||
self.device.structured_output
|
||||
and self.device.nos in nos_parsers.keys()
|
||||
and self.query_type in nos_parsers[self.device.nos].keys()
|
||||
):
|
||||
func = nos_parsers[self.device.nos][self.query_type]
|
||||
response = func(output)
|
||||
|
||||
if response is None:
|
||||
response = "\n\n".join(output)
|
||||
|
|
|
|||
|
|
@ -20,13 +20,18 @@ def parse_juniper(output):
|
|||
)
|
||||
|
||||
if "rpc-reply" in parsed.keys():
|
||||
parsed = parsed["rpc-reply"]["route-information"]["route-table"]
|
||||
parsed_base = parsed["rpc-reply"]["route-information"]
|
||||
elif "route-information" in parsed.keys():
|
||||
parsed = parsed["route-information"]["route-table"]
|
||||
parsed_base = parsed["route-information"]
|
||||
|
||||
if "rt" not in parsed:
|
||||
if "route-table" not in parsed_base:
|
||||
raise ResponseEmpty(params.messages.no_output)
|
||||
|
||||
if "rt" not in parsed_base["route-table"]:
|
||||
raise ResponseEmpty(params.messages.no_output)
|
||||
|
||||
parsed = parsed_base["route-table"]
|
||||
|
||||
validated = JuniperRoute(**parsed)
|
||||
serialized = validated.serialize().export_dict()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue