mirror of
https://github.com/checktheroads/hyperglass
synced 2024-05-11 05:55:08 +00:00
fix plain text output on Junos
This commit is contained in:
@@ -89,6 +89,15 @@ async def query(query_data: Query, request: Request, background_tasks: Backgroun
|
|||||||
|
|
||||||
cache_response = await cache.get_dict(cache_key, "output")
|
cache_response = await cache.get_dict(cache_key, "output")
|
||||||
|
|
||||||
|
json_output = False
|
||||||
|
|
||||||
|
if query_data.device.structured_output and query_data.query_type in (
|
||||||
|
"bgp_route",
|
||||||
|
"bgp_community",
|
||||||
|
"bgp_aspath",
|
||||||
|
):
|
||||||
|
json_output = True
|
||||||
|
|
||||||
cached = False
|
cached = False
|
||||||
if cache_response:
|
if cache_response:
|
||||||
log.debug("Query {q} exists in cache", q=cache_key)
|
log.debug("Query {q} exists in cache", q=cache_key)
|
||||||
@@ -118,7 +127,7 @@ async def query(query_data: Query, request: Request, background_tasks: Backgroun
|
|||||||
raise HyperglassError(message=params.messages.general, alert="danger")
|
raise HyperglassError(message=params.messages.general, alert="danger")
|
||||||
|
|
||||||
# Create a cache entry
|
# Create a cache entry
|
||||||
if query_data.device.structured_output:
|
if json_output:
|
||||||
raw_output = json.dumps(cache_output)
|
raw_output = json.dumps(cache_output)
|
||||||
else:
|
else:
|
||||||
raw_output = str(cache_output)
|
raw_output = str(cache_output)
|
||||||
@@ -134,7 +143,7 @@ async def query(query_data: Query, request: Request, background_tasks: Backgroun
|
|||||||
cache_response = await cache.get_dict(cache_key, "output")
|
cache_response = await cache.get_dict(cache_key, "output")
|
||||||
response_format = "text/plain"
|
response_format = "text/plain"
|
||||||
|
|
||||||
if query_data.device.structured_output:
|
if json_output:
|
||||||
response_format = "application/json"
|
response_format = "application/json"
|
||||||
|
|
||||||
log.debug(f"Cache match for {cache_key}:\n {cache_response}")
|
log.debug(f"Cache match for {cache_key}:\n {cache_response}")
|
||||||
|
@@ -84,6 +84,9 @@ class Connect:
|
|||||||
parsed = ()
|
parsed = ()
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
|
nos_to_parse = nos_parsers.keys()
|
||||||
|
query_type_to_parse = nos_parsers[self.device.nos].keys()
|
||||||
|
|
||||||
if not self.device.structured_output:
|
if not self.device.structured_output:
|
||||||
for coro in parsers:
|
for coro in parsers:
|
||||||
for response in output:
|
for response in output:
|
||||||
@@ -92,8 +95,18 @@ class Connect:
|
|||||||
response = "\n\n".join(parsed)
|
response = "\n\n".join(parsed)
|
||||||
elif (
|
elif (
|
||||||
self.device.structured_output
|
self.device.structured_output
|
||||||
and self.device.nos in nos_parsers.keys()
|
and self.device.nos in nos_to_parse
|
||||||
and self.query_type in nos_parsers[self.device.nos].keys()
|
and self.query_type not in query_type_to_parse
|
||||||
|
):
|
||||||
|
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_to_parse
|
||||||
|
and self.query_type in query_type_to_parse
|
||||||
):
|
):
|
||||||
func = nos_parsers[self.device.nos][self.query_type]
|
func = nos_parsers[self.device.nos][self.query_type]
|
||||||
response = func(output)
|
response = func(output)
|
||||||
|
Reference in New Issue
Block a user