diff --git a/docs/configuration/optional-settings.md b/docs/configuration/optional-settings.md index aacb50410..83b289b9a 100644 --- a/docs/configuration/optional-settings.md +++ b/docs/configuration/optional-settings.md @@ -139,12 +139,44 @@ An API consumer can request an arbitrary number of objects by appending the "lim ## NAPALM_PASSWORD -NetBox will use these credentials when authenticating to remote devices via the NAPALM library. Both parameters are optional. +NetBox will use these credentials when authenticating to remote devices via the [NAPALM library](https://napalm-automation.net/), if installed. Both parameters are optional. Note: If SSH public key authentication has been set up for the system account under which NetBox runs, these parameters are not needed. --- +## NAPALM_ARGS + +A dictionary of optional arguments to pass to NAPALM when instantiating a network driver. See the NAPALM documentation for a [complete list of optional arguments](http://napalm.readthedocs.io/en/latest/support/#optional-arguments). An example: + +``` +NAPALM_ARGS = { + 'api_key': '472071a93b60a1bd1fafb401d9f8ef41', + 'port': 2222, +} +``` + +Note: Some platforms (e.g. Cisco IOS) require an argument named `secret` to be passed in addition to the normal password. If desired, you can use the configured `NAPALM_PASSWORD` as the value for this argument: + +``` +NAPALM_USERNAME = 'username' +NAPALM_PASSWORD = 'MySecretPassword' +NAPALM_ARGS = { + 'secret': NAPALM_PASSWORD, + # Include any additional args here +} +``` + +--- + +## NAPALM_TIMEOUT + +Default: 30 seconds + +The amount of time (in seconds) to wait for NAPALM to connect to a device. + +--- + ## NETBOX_USERNAME (Deprecated) ## NETBOX_PASSWORD (Deprecated) diff --git a/netbox/dcim/api/views.py b/netbox/dcim/api/views.py index bfbe3c549..116c8db00 100644 --- a/netbox/dcim/api/views.py +++ b/netbox/dcim/api/views.py @@ -273,14 +273,16 @@ class DeviceViewSet(WritableSerializerMixin, CustomFieldModelViewSet): d = driver( hostname=ip_address, username=settings.NAPALM_USERNAME, - password=settings.NAPALM_PASSWORD + password=settings.NAPALM_PASSWORD, + timeout=settings.NAPALM_TIMEOUT, + optional_args=settings.NAPALM_ARGS ) try: d.open() for method in napalm_methods: response[method] = getattr(d, method)() except Exception as e: - raise ServiceUnavailable("Error connecting to the device: {}".format(e)) + raise ServiceUnavailable("Error connecting to the device at {}: {}".format(ip_address, e)) d.close() return Response(response) diff --git a/netbox/netbox/configuration.example.py b/netbox/netbox/configuration.example.py index 834f322bb..78e870072 100644 --- a/netbox/netbox/configuration.example.py +++ b/netbox/netbox/configuration.example.py @@ -97,6 +97,13 @@ MAX_PAGE_SIZE = 1000 NAPALM_USERNAME = '' NAPALM_PASSWORD = '' +# NAPALM timeout (in seconds). (Default: 30) +NAPALM_TIMEOUT = 30 + +# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must +# be provided as a dictionary. +NAPALM_ARGS = {} + # Determine how many objects to display per page within a list. (Default: 50) PAGINATE_COUNT = 50 diff --git a/netbox/netbox/settings.py b/netbox/netbox/settings.py index fe863833f..2cac4ad7d 100644 --- a/netbox/netbox/settings.py +++ b/netbox/netbox/settings.py @@ -48,6 +48,8 @@ PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50) PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False) NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '') NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '') +NAPALM_TIMEOUT = getattr(configuration, 'NAPALM_TIMEOUT', 30) +NAPALM_ARGS = getattr(configuration, 'NAPALM_ARGS', {}) NETBOX_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') # Deprecated NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') # Deprecated SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')