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

Select generic SNMPHandler for Cisco Small Business switches in PortAdmin #3250

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions python/nav/portadmin/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ class ManagementHandler:
a class.
"""

VENDOR = None

def __init__(self, netbox: manage.Netbox, **kwargs):
self.netbox = netbox

@classmethod
def can_handle(cls, netbox: manage.Netbox) -> bool:
"""Returns True if this handler can handle the given netbox"""
return netbox.type and netbox.type.get_enterprise_id() == cls.VENDOR

def set_interface_description(self, interface: manage.Interface, description: str):
"""Configures a single interface's description, AKA the ifalias value"""
raise NotImplementedError
Expand Down
17 changes: 6 additions & 11 deletions python/nav/portadmin/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""This is a utility library made especially for PortAdmin."""
from nav.enterprise.ids import VENDOR_ID_CISCOSYSTEMS
from nav.errors import NoNetboxTypeError
from nav.models import manage
from nav.portadmin.handlers import ManagementHandler
Expand All @@ -25,7 +24,7 @@
from nav.portadmin.snmp.hp import HP
from nav.portadmin.napalm.juniper import Juniper

VENDOR_MAP = {cls.VENDOR: cls for cls in (Cisco, Dell, H3C, HP, Juniper)}
SUPPORTED_HANDLERS = (Cisco, Dell, H3C, HP, Juniper, SNMPHandler)


class ManagementFactory(object):
Expand All @@ -38,15 +37,11 @@ def get_instance(cls, netbox: manage.Netbox, **kwargs) -> ManagementHandler:
if not netbox.type:
raise NoNetboxTypeError()

vendor_id = netbox.type.get_enterprise_id()
if (
vendor_id == VENDOR_ID_CISCOSYSTEMS
and Cisco.OTHER_ENTERPRISES.is_a_prefix_of(netbox.type.sysobjectid)
):
# Cisco SM and SMB products are not supported by the Cisco handler:
vendor_id = None
handler = VENDOR_MAP.get(vendor_id, SNMPHandler)
return handler(netbox, **kwargs)
for handler_class in SUPPORTED_HANDLERS:
if handler_class.can_handle(netbox):
break

return handler_class(netbox, **kwargs)
lunkwill42 marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self):
pass
2 changes: 0 additions & 2 deletions python/nav/portadmin/snmp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class InvalidManagementProfileError(ManagementError):
class SNMPHandler(ManagementHandler):
"""Implements PortAdmin management functions for SNMP-enabled switches"""

VENDOR = None

QBRIDGENODES = get_mib('Q-BRIDGE-MIB')['nodes']

SYSOBJECTID = '.1.3.6.1.2.1.1.2.0'
Expand Down
9 changes: 9 additions & 0 deletions python/nav/portadmin/snmp/cisco.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def __init__(self, netbox, **kwargs):
self.voice_vlan_oid = '1.3.6.1.4.1.9.9.68.1.5.1.1.1'
self.cdp_oid = '1.3.6.1.4.1.9.9.23.1.1.1.1.2'

@classmethod
def can_handle(cls, netbox: manage.Netbox) -> bool:
"""Returns True if this handler can handle this netbox"""
if netbox.type and cls.OTHER_ENTERPRISES.is_a_prefix_of(
netbox.type.sysobjectid
):
return False
return super().can_handle(netbox)

@translate_protocol_errors
def get_interface_native_vlan(self, interface):
return self._query_netbox(self.vlan_oid, interface.ifindex)
Expand Down
Loading