forked from mirrors/thatmattlove-hyperglass
Implement plugins during execution workflow
This commit is contained in:
parent
3d97d118fb
commit
1adad7e46d
2 changed files with 7 additions and 5 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Standard Library
|
# Standard Library
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import TYPE_CHECKING, Dict, Union, Sequence
|
from typing import TYPE_CHECKING, Union, Sequence
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.log import log
|
from hyperglass.log import log
|
||||||
|
|
@ -14,6 +14,7 @@ from ._construct import Construct
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.models.api import Query
|
from hyperglass.models.api import Query
|
||||||
|
from hyperglass.models.data import OutputDataModel
|
||||||
from hyperglass.compat._sshtunnel import SSHTunnelForwarder
|
from hyperglass.compat._sshtunnel import SSHTunnelForwarder
|
||||||
from hyperglass.models.config.devices import Device
|
from hyperglass.models.config.devices import Device
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ class Connection(ABC):
|
||||||
"""Return a preconfigured sshtunnel.SSHTunnelForwarder instance."""
|
"""Return a preconfigured sshtunnel.SSHTunnelForwarder instance."""
|
||||||
pass
|
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."""
|
"""Send output through common parsers."""
|
||||||
|
|
||||||
log.debug("Pre-parsed responses:\n{}", output)
|
log.debug("Pre-parsed responses:\n{}", output)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ hyperglass-frr API calls, returns the output back to the front end.
|
||||||
|
|
||||||
# Standard Library
|
# Standard Library
|
||||||
import signal
|
import signal
|
||||||
from typing import TYPE_CHECKING, Any, Dict, Union, Callable, Sequence
|
from typing import TYPE_CHECKING, Any, Dict, Union, Callable
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
from hyperglass.log import log
|
from hyperglass.log import log
|
||||||
|
|
@ -18,6 +18,7 @@ from hyperglass.exceptions.public import DeviceTimeout, ResponseEmpty
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from hyperglass.models.api import Query
|
from hyperglass.models.api import Query
|
||||||
from .drivers import Connection
|
from .drivers import Connection
|
||||||
|
from hyperglass.models.data import OutputDataModel
|
||||||
|
|
||||||
# Local
|
# Local
|
||||||
from .drivers import AgentConnection, NetmikoConnection, ScrapliConnection
|
from .drivers import AgentConnection, NetmikoConnection, ScrapliConnection
|
||||||
|
|
@ -44,7 +45,7 @@ def handle_timeout(**exc_args: Any) -> Callable:
|
||||||
return handler
|
return handler
|
||||||
|
|
||||||
|
|
||||||
async def execute(query: "Query") -> Union[str, Sequence[Dict]]:
|
async def execute(query: "Query") -> Union[OutputDataModel, str]:
|
||||||
"""Initiate query validation and execution."""
|
"""Initiate query validation and execution."""
|
||||||
|
|
||||||
output = params.messages.general
|
output = params.messages.general
|
||||||
|
|
@ -68,7 +69,7 @@ async def execute(query: "Query") -> Union[str, Sequence[Dict]]:
|
||||||
else:
|
else:
|
||||||
response = await driver.collect()
|
response = await driver.collect()
|
||||||
|
|
||||||
output = await driver.parsed_response(response)
|
output = await driver.response(response)
|
||||||
|
|
||||||
if isinstance(output, str):
|
if isinstance(output, str):
|
||||||
# If the output is a string (not structured) and is empty,
|
# If the output is a string (not structured) and is empty,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue