Skip to content

Commit

Permalink
Merge pull request #2636 from stveit/portadmin-poe-abstract-funcs
Browse files Browse the repository at this point in the history
Add abstract functions for PoE enabling
  • Loading branch information
stveit authored Sep 5, 2023
2 parents fb4ea26 + b9ace82 commit f0fe990
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion python/nav/portadmin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit f0fe990

Please sign in to comment.