Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add abstract functions for PoE enabling #2636

Merged
merged 14 commits into from
Sep 5, 2023
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


stveit marked this conversation as resolved.
Show resolved Hide resolved
class ManagementHandler:
"""Defines a common interface for all types of PortAdmin management handlers.

Expand Down Expand Up @@ -278,6 +290,33 @@
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

Check warning on line 295 in python/nav/portadmin/handlers.py

View check run for this annotation

Codecov / codecov/patch

python/nav/portadmin/handlers.py#L295

Added line #L295 was not covered by tests

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

Check warning on line 301 in python/nav/portadmin/handlers.py

View check run for this annotation

Codecov / codecov/patch

python/nav/portadmin/handlers.py#L301

Added line #L301 was not covered by tests

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

Check warning on line 318 in python/nav/portadmin/handlers.py

View check run for this annotation

Codecov / codecov/patch

python/nav/portadmin/handlers.py#L318

Added line #L318 was not covered by tests


class ManagementError(Exception):
"""Base exception class for device management errors"""
Expand Down
Loading