From 386fe3f66a4f4e273ae17defbc9e34b888855699 Mon Sep 17 00:00:00 2001 From: checktheroads Date: Sat, 16 Nov 2019 23:09:43 -0700 Subject: [PATCH] fix frr/bird support --- hyperglass/command/construct.py | 22 ++++++++++++++-------- hyperglass/command/execute.py | 17 +++++++++++------ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/hyperglass/command/construct.py b/hyperglass/command/construct.py index f8f7e56..f2bf115 100644 --- a/hyperglass/command/construct.py +++ b/hyperglass/command/construct.py @@ -52,8 +52,9 @@ class Construct: _target = re.sub(r"\/", r" ", target) else: _target = target - log.debug(f"Formatted target: {_target}") - return _target + target_string = str(_target) + log.debug(f"Formatted target: {target_string}") + return target_string @staticmethod def device_commands(nos, afi, query_type): @@ -95,7 +96,8 @@ class Construct: { "query_type": "ping", "vrf": afi.vrf_name, - "source": afi.source_address, + "afi": query_protocol, + "source": afi.source_address.compressed, "target": self.query_target, } ) @@ -135,7 +137,8 @@ class Construct: { "query_type": "traceroute", "vrf": afi.vrf_name, - "source": afi.source_address, + "afi": query_protocol, + "source": afi.source_address.compressed, "target": self.query_target, } ) @@ -172,8 +175,9 @@ class Construct: { "query_type": "bgp_route", "vrf": afi.vrf_name, - "source": afi.source_address, - "target": self.query_target, + "afi": query_protocol, + "source": afi.source_address.compressed, + "target": self.format_target(self.query_target), } ) ) @@ -220,7 +224,8 @@ class Construct: { "query_type": "bgp_community", "vrf": afi_attr.vrf_name, - "source": afi_attr.source_address, + "afi": query_protocol, + "source": afi_attr.source_address.compressed, "target": self.query_target, } ) @@ -269,7 +274,8 @@ class Construct: { "query_type": "bgp_aspath", "vrf": afi_attr.vrf_name, - "source": afi_attr.source_address, + "afi": query_protocol, + "source": afi_attr.source_address.compressed, "target": self.query_target, } ) diff --git a/hyperglass/command/execute.py b/hyperglass/command/execute.py index a2088aa..6175137 100644 --- a/hyperglass/command/execute.py +++ b/hyperglass/command/execute.py @@ -226,7 +226,7 @@ class Connect: http_protocol = protocol_map.get(self.device.port, "http") endpoint = "{protocol}://{addr}:{port}/{uri}".format( protocol=http_protocol, - addr=self.device.address.exploded, + addr=self.device.address, port=self.device.port, uri=uri, ) @@ -236,12 +236,17 @@ class Connect: try: http_client = httpx.AsyncClient() - raw_response = await http_client.post( - endpoint, headers=headers, json=self.query, timeout=7 - ) - response = raw_response.text + responses = [] + for query in self.query: + raw_response = await http_client.post( + endpoint, headers=headers, json=query, timeout=7 + ) + log.debug(f"HTTP status code: {raw_response.status_code}") - log.debug(f"HTTP status code: {raw_response.status_code}") + raw = raw_response.text + responses.append(raw) + + response = "\n\n".join(responses) log.debug(f"Output for query {self.query}:\n{response}") except ( httpx.exceptions.ConnectTimeout,