jeremystretch 4 лет назад
Родитель
Сommit
41ff1d0fc9

+ 8 - 4
netbox/dcim/api/views.py

@@ -21,6 +21,7 @@ from netbox.api.authentication import IsAuthenticatedOrLoginNotRequired
 from netbox.api.exceptions import ServiceUnavailable
 from netbox.api.exceptions import ServiceUnavailable
 from netbox.api.metadata import ContentTypeMetadata
 from netbox.api.metadata import ContentTypeMetadata
 from netbox.api.views import ModelViewSet
 from netbox.api.views import ModelViewSet
+from netbox.config import Config
 from utilities.api import get_serializer_for_model
 from utilities.api import get_serializer_for_model
 from utilities.utils import count_related, decode_dict
 from utilities.utils import count_related, decode_dict
 from virtualization.models import VirtualMachine
 from virtualization.models import VirtualMachine
@@ -457,9 +458,12 @@ class DeviceViewSet(ConfigContextQuerySetMixin, CustomFieldModelViewSet):
 
 
         napalm_methods = request.GET.getlist('method')
         napalm_methods = request.GET.getlist('method')
         response = OrderedDict([(m, None) for m in napalm_methods])
         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:
         if device.platform.napalm_args is not None:
             optional_args.update(device.platform.napalm_args)
             optional_args.update(device.platform.napalm_args)
 
 
@@ -481,7 +485,7 @@ class DeviceViewSet(ConfigContextQuerySetMixin, CustomFieldModelViewSet):
             hostname=host,
             hostname=host,
             username=username,
             username=username,
             password=password,
             password=password,
-            timeout=settings.NAPALM_TIMEOUT,
+            timeout=timeout,
             optional_args=optional_args
             optional_args=optional_args
         )
         )
         try:
         try:

+ 3 - 6
netbox/extras/admin.py

@@ -7,9 +7,6 @@ from .models import ConfigRevision, JobResult
 @admin.register(ConfigRevision)
 @admin.register(ConfigRevision)
 class ConfigRevisionAdmin(admin.ModelAdmin):
 class ConfigRevisionAdmin(admin.ModelAdmin):
     fieldsets = [
     fieldsets = [
-        # ('Authentication', {
-        #     'fields': ('LOGIN_REQUIRED', 'LOGIN_PERSISTENCE', 'LOGIN_TIMEOUT'),
-        # }),
         ('Rack Elevations', {
         ('Rack Elevations', {
             'fields': ('RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', 'RACK_ELEVATION_DEFAULT_UNIT_WIDTH'),
             'fields': ('RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', 'RACK_ELEVATION_DEFAULT_UNIT_WIDTH'),
         }),
         }),
@@ -22,12 +19,12 @@ class ConfigRevisionAdmin(admin.ModelAdmin):
         ('Banners', {
         ('Banners', {
             'fields': ('BANNER_LOGIN', 'BANNER_TOP', 'BANNER_BOTTOM'),
             'fields': ('BANNER_LOGIN', 'BANNER_TOP', 'BANNER_BOTTOM'),
         }),
         }),
-        # ('Logging', {
-        #     'fields': ('CHANGELOG_RETENTION',),
-        # }),
         ('Pagination', {
         ('Pagination', {
             'fields': ('PAGINATE_COUNT', 'MAX_PAGE_SIZE'),
             'fields': ('PAGINATE_COUNT', 'MAX_PAGE_SIZE'),
         }),
         }),
+        ('NAPALM', {
+            'fields': ('NAPALM_USERNAME', 'NAPALM_PASSWORD', 'NAPALM_TIMEOUT', 'NAPALM_ARGS'),
+        }),
         ('Miscellaneous', {
         ('Miscellaneous', {
             'fields': ('MAINTENANCE_MODE', 'MAPS_URL'),
             'fields': ('MAINTENANCE_MODE', 'MAPS_URL'),
         }),
         }),

+ 25 - 0
netbox/netbox/config/parameters.py

@@ -96,6 +96,31 @@ PARAMS = (
         field=forms.IntegerField
         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
     # Miscellaneous
     ConfigParam(
     ConfigParam(
         name='MAINTENANCE_MODE',
         name='MAINTENANCE_MODE',

+ 0 - 11
netbox/netbox/configuration.example.py

@@ -175,17 +175,6 @@ LOGIN_TIMEOUT = None
 # Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
 # Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
 METRICS_ENABLED = False
 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.
 # Enable installed plugins. Add the name of each plugin to the list.
 PLUGINS = []
 PLUGINS = []
 
 

+ 0 - 5
netbox/netbox/settings.py

@@ -130,11 +130,6 @@ for param in PARAMS:
     if hasattr(configuration, param.name):
     if hasattr(configuration, param.name):
         globals()[param.name] = getattr(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
 # Validate update repo URL and timeout
 if RELEASE_CHECK_URL:
 if RELEASE_CHECK_URL:
     validator = URLValidator(
     validator = URLValidator(