Skip to content

Commit

Permalink
Merge pull request #2731 from lunkwill42/feature/snmpv3-portadmin
Browse files Browse the repository at this point in the history
Add SNMPv3 support to Portadmin
  • Loading branch information
lunkwill42 authored Nov 16, 2023
2 parents cf0c417 + 493e595 commit 854efb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
15 changes: 3 additions & 12 deletions python/nav/portadmin/snmp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
# details. You should have received a copy of the GNU General Public License
# along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
import time
from functools import wraps
from operator import attrgetter
import logging
from typing import Dict, Sequence, List, Any

from nav import Snmp
from nav.Snmp.profile import get_snmp_session_for_profile
from nav.Snmp import safestring, OID
from nav.Snmp.errors import (
UnsupportedSnmpVersionError,
Expand Down Expand Up @@ -174,15 +173,9 @@ def _get_read_only_handle(self):

if not profile:
raise NoReadOnlyManagementProfileError
if not hasattr(profile, "snmp_community") or not hasattr(
profile, "snmp_version"
):
raise InvalidManagementProfileError

self.read_only_handle = Snmp.Snmp(
self.read_only_handle = get_snmp_session_for_profile(profile)(
host=self.netbox.ip,
community=profile.snmp_community,
version=profile.snmp_version,
retries=self.retries,
timeout=self.timeout,
)
Expand All @@ -209,10 +202,8 @@ def _get_read_write_handle(self):
"""
if self.read_write_handle is None:
profile = self.netbox.get_preferred_snmp_management_profile(writeable=True)
self.read_write_handle = Snmp.Snmp(
self.read_write_handle = get_snmp_session_for_profile(profile)(
host=self.netbox.ip,
community=profile.snmp_community,
version=profile.snmp_version,
retries=self.retries,
timeout=self.timeout,
)
Expand Down
8 changes: 5 additions & 3 deletions tests/unittests/portadmin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import pytest

from nav.enterprise.ids import VENDOR_ID_HEWLETT_PACKARD, VENDOR_ID_CISCOSYSTEMS
from nav.models.manage import ManagementProfile
from nav.portadmin.management import ManagementFactory


@pytest.fixture
def profile():
profile = Mock()
profile.snmp_version = 2
profile.snmp_community = "public"
profile = ManagementProfile(
protocol=ManagementProfile.PROTOCOL_SNMP,
configuration={"version": 2, "community": "public"},
)
return profile


Expand Down

0 comments on commit 854efb7

Please sign in to comment.