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
43 changes: 42 additions & 1 deletion python/nav/portadmin/handlers.py
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
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,35 @@ 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, 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
"""
raise NotImplementedError

def interface_supports_poe(self, interface: manage.Interface) -> bool:
"""Returns True if this interface supports PoE"""
raise NotImplementedError

Copy link
Contributor Author

@stveit stveit Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I question the need for this function. When ive tried to implement this for cisco and juniper, it boils down to trying to get the state from the device and returning true/false based on if it found anything. It doesnt actually save any time over just calling get_poe_states for the interface youre interested in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. You could simply change the definition of get_poe_state to return something like Dict[int, Optional[PoeState]], where the value for a non-supported interface would just be None.


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