From 1adad7e46d7accfb0a1afa24c7435acad71ed75e Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Mon, 13 Sep 2021 02:37:32 -0700 Subject: [PATCH] Implement plugins during execution workflow --- hyperglass/execution/drivers/_common.py | 5 +++-- hyperglass/execution/main.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hyperglass/execution/drivers/_common.py b/hyperglass/execution/drivers/_common.py index e37aa1d..bc4c4ae 100644 --- a/hyperglass/execution/drivers/_common.py +++ b/hyperglass/execution/drivers/_common.py @@ -2,7 +2,7 @@ # Standard Library from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Dict, Union, Sequence +from typing import TYPE_CHECKING, Union, Sequence # Project from hyperglass.log import log @@ -14,6 +14,7 @@ from ._construct import Construct if TYPE_CHECKING: # Project from hyperglass.models.api import Query + from hyperglass.models.data import OutputDataModel from hyperglass.compat._sshtunnel import SSHTunnelForwarder from hyperglass.models.config.devices import Device @@ -36,7 +37,7 @@ class Connection(ABC): """Return a preconfigured sshtunnel.SSHTunnelForwarder instance.""" pass - async def parsed_response(self, output: Sequence[str]) -> Union[str, Sequence[Dict]]: + async def response(self, output: Sequence[str]) -> Union[OutputDataModel, str]: """Send output through common parsers.""" log.debug("Pre-parsed responses:\n{}", output) diff --git a/hyperglass/execution/main.py b/hyperglass/execution/main.py index b8aa93d..91a2bbf 100644 --- a/hyperglass/execution/main.py +++ b/hyperglass/execution/main.py @@ -8,7 +8,7 @@ hyperglass-frr API calls, returns the output back to the front end. # Standard Library import signal -from typing import TYPE_CHECKING, Any, Dict, Union, Callable, Sequence +from typing import TYPE_CHECKING, Any, Dict, Union, Callable # Project from hyperglass.log import log @@ -18,6 +18,7 @@ from hyperglass.exceptions.public import DeviceTimeout, ResponseEmpty if TYPE_CHECKING: from hyperglass.models.api import Query from .drivers import Connection + from hyperglass.models.data import OutputDataModel # Local from .drivers import AgentConnection, NetmikoConnection, ScrapliConnection @@ -44,7 +45,7 @@ def handle_timeout(**exc_args: Any) -> Callable: return handler -async def execute(query: "Query") -> Union[str, Sequence[Dict]]: +async def execute(query: "Query") -> Union[OutputDataModel, str]: """Initiate query validation and execution.""" output = params.messages.general @@ -68,7 +69,7 @@ async def execute(query: "Query") -> Union[str, Sequence[Dict]]: else: response = await driver.collect() - output = await driver.parsed_response(response) + output = await driver.response(response) if isinstance(output, str): # If the output is a string (not structured) and is empty,