diff --git a/python/nav/arnold.py b/python/nav/arnold.py index 58eb59bbc5..53f9ab8e6b 100644 --- a/python/nav/arnold.py +++ b/python/nav/arnold.py @@ -31,6 +31,7 @@ from subprocess import Popen, PIPE from collections import namedtuple from smtplib import SMTPException +from typing import Callable from IPy import IP from django.db import connection @@ -40,6 +41,7 @@ from nav.Snmp.errors import AgentError import nav.bitvector import nav.buildconf +from nav.Snmp.profile import get_snmp_session_for_profile from nav.config import find_config_file from nav.errors import GeneralException from nav.models.arnold import Identity, Event @@ -443,7 +445,11 @@ def open_port(identity, username, eventcomment=""): _logger.info("openPort: Port successfully opened") -def change_port_status(action, identity): +def change_port_status( + action, + identity, + agent_getter: Callable = get_snmp_session_for_profile, +): """Use SNMP to change status on an interface. We use ifadminstatus to enable and disable ports @@ -464,11 +470,7 @@ def change_port_status(action, identity): if not profile: raise NoReadWriteManagementProfileError - agent = nav.Snmp.Snmp( - host=netbox.ip, - community=profile.snmp_community, - version=profile.snmp_version, - ) + agent = agent_getter(profile)(host=netbox.ip) # Disable or enable based on input try: