Update plugin typings

This commit is contained in:
thatmattlove 2021-09-13 02:37:05 -07:00
parent 98201c1752
commit 3d97d118fb
4 changed files with 20 additions and 12 deletions

View file

@ -2,15 +2,17 @@
# Local
from .main import init_plugins, register_plugin
from ._input import InputPlugin
from ._output import OutputPlugin
from ._input import InputPlugin, InputPluginReturn
from ._output import OutputType, OutputPlugin
from ._manager import InputPluginManager, OutputPluginManager
__all__ = (
"init_plugins",
"InputPlugin",
"InputPluginManager",
"InputPluginReturn",
"OutputPlugin",
"OutputPluginManager",
"OutputType",
"register_plugin",
)

View file

@ -2,5 +2,9 @@
# Local
from .remove_command import RemoveCommand
from .bgp_route_juniper import BGPRoutePluginJuniper
__all__ = ("RemoveCommand",)
__all__ = (
"RemoveCommand",
"BGPRoutePluginJuniper",
)

View file

@ -16,7 +16,7 @@ from hyperglass.exceptions.private import PluginError
# Local
from ._base import PluginType, HyperglassPlugin
from ._input import InputPlugin, InputPluginReturn
from ._output import OutputPlugin, OutputPluginReturn
from ._output import OutputType, OutputPlugin
if TYPE_CHECKING:
# Project
@ -168,8 +168,8 @@ class OutputPluginManager(PluginManager[OutputPlugin], type="output"):
"""Manage Output Processing Plugins."""
def execute(
self: "OutputPluginManager", *, directive: "Directive", output: str, device: "Device"
) -> OutputPluginReturn:
self: "OutputPluginManager", *, directive: "Directive", output: OutputType, device: "Device"
) -> OutputType:
"""Execute all output parsing plugins.
The result of each plugin is passed to the next plugin.

View file

@ -3,22 +3,24 @@
# Standard Library
from typing import TYPE_CHECKING, Union, Sequence
# Project
from hyperglass.log import log
# Local
from ._base import DirectivePlugin
if TYPE_CHECKING:
# Project
from hyperglass.models.data import OutputDataModel
from hyperglass.models.config.devices import Device
from hyperglass.models.parsing.serialized import ParsedRoutes
OutputPluginReturn = Union[None, "ParsedRoutes", str]
OutputType = Union["OutputDataModel", Sequence[str]]
class OutputPlugin(DirectivePlugin):
"""Plugin to interact with device command output."""
directive_ids: Sequence[str] = ()
def process(self, output: Union["ParsedRoutes", str], device: "Device") -> OutputPluginReturn:
def process(self, output: OutputType, device: "Device") -> OutputType:
"""Process or manipulate output from a device."""
return None
log.warning("Output plugin '{}' has not implemented a 'process()' method", self.name)
return output