2021-09-11 00:47:01 -07:00
|
|
|
"""Remove anything before the command if found in output."""
|
|
|
|
|
2021-09-11 17:55:27 -07:00
|
|
|
# Standard Library
|
|
|
|
from typing import TYPE_CHECKING
|
2021-09-11 00:47:01 -07:00
|
|
|
|
2021-09-12 15:06:34 -07:00
|
|
|
# Third Party
|
|
|
|
from pydantic import PrivateAttr
|
|
|
|
|
2021-09-11 00:47:01 -07:00
|
|
|
# Local
|
|
|
|
from .._output import OutputPlugin
|
|
|
|
|
2021-09-11 17:55:27 -07:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
# Project
|
|
|
|
from hyperglass.models.config.devices import Device
|
|
|
|
|
2021-09-11 00:47:01 -07:00
|
|
|
|
|
|
|
class RemoveCommand(OutputPlugin):
|
|
|
|
"""Remove anything before the command if found in output."""
|
|
|
|
|
2021-09-12 15:06:34 -07:00
|
|
|
__hyperglass_builtin__: bool = PrivateAttr(True)
|
|
|
|
|
2021-09-11 17:55:27 -07:00
|
|
|
def process(self, device_output: str, device: "Device") -> str:
|
2021-09-11 00:47:01 -07:00
|
|
|
"""Remove anything before the command if found in output."""
|
|
|
|
output = device_output.strip().split("\n")
|
|
|
|
|
|
|
|
for command in device.directive_commands:
|
|
|
|
for line in output:
|
|
|
|
if command in line:
|
|
|
|
idx = output.index(line) + 1
|
|
|
|
output = output[idx:]
|
|
|
|
|
|
|
|
return "\n".join(output)
|