diff --git a/python/nav/portadmin/handlers.py b/python/nav/portadmin/handlers.py index 2f79c3b505..250342272d 100644 --- a/python/nav/portadmin/handlers.py +++ b/python/nav/portadmin/handlers.py @@ -15,8 +15,9 @@ # """Interface definition for PortAdmin management handlers""" import time -from typing import List, Tuple, Dict, Any, Sequence +from typing import List, Tuple, Dict, Any, Sequence, Union, Optional import logging +from dataclasses import dataclass from nav.models import manage from nav.portadmin.vlan import FantasyVlan @@ -25,6 +26,17 @@ _logger = logging.getLogger(__name__) +@dataclass +class PoeState: + """Class for defining PoE states. + `state` is the value used on the device itself. + `name` is a human readable name for the state + """ + + state: Union[str, int] + name: str + + class ManagementHandler: """Defines a common interface for all types of PortAdmin management handlers. @@ -278,6 +290,33 @@ def is_configurable(self) -> bool: return False return True + def get_poe_state_options(self) -> Sequence[PoeState]: + """Returns the available options for enabling/disabling PoE on this netbox""" + raise NotImplementedError + + def set_poe_state(self, interface: manage.Interface, state: PoeState): + """Set state for enabling/disabling PoE on this interface. + Available options should be retrieved using `get_poe_state_options` + """ + raise NotImplementedError + + def get_poe_states( + self, interfaces: Sequence[manage.Interface] = None + ) -> Dict[int, Optional[PoeState]]: + """Retrieves current PoE state for interfaces on this device. + + :param interfaces: Optional sequence of interfaces to filter for, as fetching + data for all interfaces may be a waste of time if only a + single interface is needed. If this parameter is omitted, + the default behavior is to filter on all Interface objects + registered for this device. + :returns: A dict mapping interfaces to their discovered PoE state. + The key matches the `ifindex` attribute for the related + Interface object. + The value will be None if the interface does not support PoE. + """ + raise NotImplementedError + class ManagementError(Exception): """Base exception class for device management errors"""