1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00

Refactor and restructure directive model

This commit is contained in:
thatmattlove
2021-09-16 17:12:30 -07:00
parent 446534d839
commit dda73cb370
6 changed files with 12 additions and 12 deletions

View File

@@ -16,10 +16,10 @@ from hyperglass.settings import Settings
from hyperglass.constants import PARSED_RESPONSE_FIELDS, __version__ from hyperglass.constants import PARSED_RESPONSE_FIELDS, __version__
from hyperglass.models.ui import UIParameters from hyperglass.models.ui import UIParameters
from hyperglass.util.files import check_path from hyperglass.util.files import check_path
from hyperglass.models.directive import Directive
from hyperglass.exceptions.private import ConfigError, ConfigMissing from hyperglass.exceptions.private import ConfigError, ConfigMissing
from hyperglass.models.config.params import Params from hyperglass.models.config.params import Params
from hyperglass.models.config.devices import Devices from hyperglass.models.config.devices import Devices
from hyperglass.models.commands.generic import Directive
# Local # Local
from .markdown import get_markdown from .markdown import get_markdown

View File

@@ -20,8 +20,8 @@ from hyperglass.exceptions.private import ConfigError
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
# Project # Project
from hyperglass.models.api.query import Query from hyperglass.models.api.query import Query
from hyperglass.models.directive import Directive
from hyperglass.models.config.devices import Device from hyperglass.models.config.devices import Device
from hyperglass.models.commands.generic import Directive
class Construct: class Construct:

View File

@@ -29,8 +29,8 @@ from .proxy import Proxy
from .params import Params from .params import Params
from ..fields import SupportedDriver from ..fields import SupportedDriver
from .network import Network from .network import Network
from ..directive import Directive
from .credential import Credential from .credential import Credential
from ..commands.generic import Directive
class Device(HyperglassModelWithId, extra="allow"): class Device(HyperglassModelWithId, extra="allow"):

View File

@@ -22,12 +22,12 @@ from hyperglass.settings import Settings
from hyperglass.exceptions.private import InputValidationError from hyperglass.exceptions.private import InputValidationError
# Local # Local
from ..main import HyperglassModel, HyperglassModelWithId from .main import HyperglassModel, HyperglassModelWithId
from ..fields import Action from .fields import Action
if t.TYPE_CHECKING: if t.TYPE_CHECKING:
# Local # Local
from ..config.params import Params from .config.params import Params
IPv4PrefixLength = conint(ge=0, le=32) IPv4PrefixLength = conint(ge=0, le=32)
IPv6PrefixLength = conint(ge=0, le=128) IPv6PrefixLength = conint(ge=0, le=128)

View File

@@ -18,8 +18,8 @@ if t.TYPE_CHECKING:
# Project # Project
from hyperglass.state import HyperglassState from hyperglass.state import HyperglassState
from hyperglass.models.api.query import Query from hyperglass.models.api.query import Query
from hyperglass.models.directive import Directive
from hyperglass.models.config.devices import Device from hyperglass.models.config.devices import Device
from hyperglass.models.commands.generic import Directive
PluginT = t.TypeVar("PluginT", bound=HyperglassPlugin) PluginT = t.TypeVar("PluginT", bound=HyperglassPlugin)

View File

@@ -2,7 +2,7 @@
# Standard Library # Standard Library
import sys import sys
from typing import Any, Tuple import typing as t
from inspect import isclass, getmembers from inspect import isclass, getmembers
from pathlib import Path from pathlib import Path
from importlib.util import module_from_spec, spec_from_file_location from importlib.util import module_from_spec, spec_from_file_location
@@ -19,7 +19,7 @@ from ._manager import InputPluginManager, OutputPluginManager
_PLUGIN_GLOBALS = {"InputPlugin": InputPlugin, "OutputPlugin": OutputPlugin, "log": log} _PLUGIN_GLOBALS = {"InputPlugin": InputPlugin, "OutputPlugin": OutputPlugin, "log": log}
def _is_class(module: Any, obj: object) -> bool: def _is_class(module: t.Any, obj: object) -> bool:
if isclass(obj): if isclass(obj):
# Get the object's containing module name. # Get the object's containing module name.
obj_module_name: str = getattr(obj, "__module__", "") obj_module_name: str = getattr(obj, "__module__", "")
@@ -30,7 +30,7 @@ def _is_class(module: Any, obj: object) -> bool:
return False return False
def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]: def _register_from_module(module: t.Any, **kwargs: t.Any) -> t.Tuple[str, ...]:
"""Register defined classes from the module.""" """Register defined classes from the module."""
failures = () failures = ()
defs = getmembers(module, lambda o: _is_class(module, o)) defs = getmembers(module, lambda o: _is_class(module, o))
@@ -48,7 +48,7 @@ def _register_from_module(module: Any, **kwargs: Any) -> Tuple[str, ...]:
return failures return failures
def _module_from_file(file: Path) -> Any: def _module_from_file(file: Path) -> t.Any:
"""Import a plugin module from its file Path object.""" """Import a plugin module from its file Path object."""
name = file.name.split(".")[0] name = file.name.split(".")[0]
spec = spec_from_file_location(f"hyperglass.plugins.external.{name}", file) spec = spec_from_file_location(f"hyperglass.plugins.external.{name}", file)
@@ -64,7 +64,7 @@ def init_builtin_plugins() -> None:
_register_from_module(_builtin) _register_from_module(_builtin)
def register_plugin(plugin_file: Path, **kwargs) -> Tuple[str, ...]: def register_plugin(plugin_file: Path, **kwargs) -> t.Tuple[str, ...]:
"""Register an external plugin by file path.""" """Register an external plugin by file path."""
if plugin_file.exists(): if plugin_file.exists():
module = _module_from_file(plugin_file) module = _module_from_file(plugin_file)