mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Closes #1374: Added NAPALM_ARGS and NAPALM_TIMEOUT configiuration parameters
This commit is contained in:
parent
d2c6d79589
commit
65a633f42d
@ -139,12 +139,44 @@ An API consumer can request an arbitrary number of objects by appending the "lim
|
|||||||
|
|
||||||
## NAPALM_PASSWORD
|
## 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.
|
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_USERNAME (Deprecated)
|
||||||
|
|
||||||
## NETBOX_PASSWORD (Deprecated)
|
## NETBOX_PASSWORD (Deprecated)
|
||||||
|
@ -273,14 +273,16 @@ class DeviceViewSet(WritableSerializerMixin, CustomFieldModelViewSet):
|
|||||||
d = driver(
|
d = driver(
|
||||||
hostname=ip_address,
|
hostname=ip_address,
|
||||||
username=settings.NAPALM_USERNAME,
|
username=settings.NAPALM_USERNAME,
|
||||||
password=settings.NAPALM_PASSWORD
|
password=settings.NAPALM_PASSWORD,
|
||||||
|
timeout=settings.NAPALM_TIMEOUT,
|
||||||
|
optional_args=settings.NAPALM_ARGS
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
d.open()
|
d.open()
|
||||||
for method in napalm_methods:
|
for method in napalm_methods:
|
||||||
response[method] = getattr(d, method)()
|
response[method] = getattr(d, method)()
|
||||||
except Exception as e:
|
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()
|
d.close()
|
||||||
return Response(response)
|
return Response(response)
|
||||||
|
@ -97,6 +97,13 @@ MAX_PAGE_SIZE = 1000
|
|||||||
NAPALM_USERNAME = ''
|
NAPALM_USERNAME = ''
|
||||||
NAPALM_PASSWORD = ''
|
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)
|
# Determine how many objects to display per page within a list. (Default: 50)
|
||||||
PAGINATE_COUNT = 50
|
PAGINATE_COUNT = 50
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ PAGINATE_COUNT = getattr(configuration, 'PAGINATE_COUNT', 50)
|
|||||||
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
PREFER_IPV4 = getattr(configuration, 'PREFER_IPV4', False)
|
||||||
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
NAPALM_USERNAME = getattr(configuration, 'NAPALM_USERNAME', '')
|
||||||
NAPALM_PASSWORD = getattr(configuration, 'NAPALM_PASSWORD', '')
|
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_USERNAME = getattr(configuration, 'NETBOX_USERNAME', '') # Deprecated
|
||||||
NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') # Deprecated
|
NETBOX_PASSWORD = getattr(configuration, 'NETBOX_PASSWORD', '') # Deprecated
|
||||||
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
|
SHORT_DATE_FORMAT = getattr(configuration, 'SHORT_DATE_FORMAT', 'Y-m-d')
|
||||||
|
Loading…
Reference in New Issue
Block a user