diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index 921ee3a99..54712a9b3 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -21,6 +21,7 @@ from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired from netbox.api.exceptions import ServiceUnavailable from netbox.api.metadata import ContentTypeMetadata from netbox.api.views import ModelViewSet +from netbox.config import Config from utilities.api import get_serializer_for_model from utilities.utils import count_related, decode_dict from virtualization.models import VirtualMachine @@ -457,9 +458,12 @@ class DeviceViewSet(ConfigContextQuerySetMixin, CustomFieldModelViewSet): napalm_methods = request.GET.getlist('method') response = OrderedDict([(m, None) for m in napalm_methods]) - username = settings.NAPALM_USERNAME - password = settings.NAPALM_PASSWORD - optional_args = settings.NAPALM_ARGS.copy() + + config = Config() + username = config.NAPALM_USERNAME + password = config.NAPALM_PASSWORD + timeout = config.NAPALM_TIMEOUT + optional_args = config.NAPALM_ARGS.copy() if device.platform.napalm_args is not None: optional_args.update(device.platform.napalm_args) @@ -481,7 +485,7 @@ class DeviceViewSet(ConfigContextQuerySetMixin, CustomFieldModelViewSet): hostname=host, username=username, password=password, - timeout=settings.NAPALM_TIMEOUT, + timeout=timeout, optional_args=optional_args ) try: diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index aaacbb0af..85bcd351d 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -7,9 +7,6 @@ from .models import ConfigRevision, JobResult @admin.register(ConfigRevision) class ConfigRevisionAdmin(admin.ModelAdmin): fieldsets = [ - # ('Authentication', { - # 'fields': ('LOGIN_REQUIRED', 'LOGIN_PERSISTENCE', 'LOGIN_TIMEOUT'), - # }), ('Rack Elevations', { 'fields': ('RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', 'RACK_ELEVATION_DEFAULT_UNIT_WIDTH'), }), @@ -22,12 +19,12 @@ class ConfigRevisionAdmin(admin.ModelAdmin): ('Banners', { 'fields': ('BANNER_LOGIN', 'BANNER_TOP', 'BANNER_BOTTOM'), }), - # ('Logging', { - # 'fields': ('CHANGELOG_RETENTION',), - # }), ('Pagination', { 'fields': ('PAGINATE_COUNT', 'MAX_PAGE_SIZE'), }), + ('NAPALM', { + 'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'), + }), ('Miscellaneous', { 'fields': ('MAINTENANCE_MODE', 'MAPS_URL'), }), diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py index be981e3ea..e09466839 100644 --- a/netbox/netbox/config/parameters.py +++ b/netbox/netbox/config/parameters.py @@ -96,6 +96,31 @@ PARAMS = ( field=forms.IntegerField ), + # NAPALM + ConfigParam( + name='NAPALM_USERNAME', + label='NAPALM username', + default='' + ), + ConfigParam( + name='NAPALM_PASSWORD', + label='NAPALM password', + default='' + ), + ConfigParam( + name='NAPALM_TIMEOUT', + label='NAPALM timeout', + default=30, + field=forms.IntegerField + ), + ConfigParam( + name='NAPALM_ARGS', + label='NAPALM arguments', + default={}, + description="Additional arguments to pass when invoking NAPALM", + field=forms.JSONField + ), + # Miscellaneous ConfigParam( name='MAINTENANCE_MODE', diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index ffcac8fba..189e98d11 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -175,17 +175,6 @@ LOGIN_TIMEOUT = None # Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics' METRICS_ENABLED = False -# Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM. -NAPALM_USERNAME = '' -NAPALM_PASSWORD = '' - -# NAPALM timeout (in seconds). (Default: 30) -NAPALM_TIMEOUT = 30 - -# NAPALM optional arguments (see https://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must -# be provided as a dictionary. -NAPALM_ARGS = {} - # Enable installed plugins. Add the name of each plugin to the list. PLUGINS = [] diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index f3526a70b..1ff000ff8 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -130,11 +130,6 @@ for param in PARAMS: if hasattr(configuration, param.name): globals()[param.name] = getattr(configuration, param.name) -NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) -NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '') -NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30) -NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '') - # Validate update repo URL and timeout if RELEASE_CHECK_URL: validator = URLValidator(