1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #2588: Catch all exceptions from failed NAPALM API Calls

This commit is contained in:
Jeremy Stretch
2018-11-14 10:12:35 -05:00
parent 83be0b5db4
commit 408f632636
2 changed files with 5 additions and 2 deletions

View File

@ -263,9 +263,9 @@ class DeviceViewSet(CustomFieldModelViewSet):
# Check that NAPALM is installed
try:
import napalm
from napalm.base.exceptions import ModuleImportError
except ImportError:
raise ServiceUnavailable("NAPALM is not installed. Please see the documentation for instructions.")
from napalm.base.exceptions import ModuleImportError
# Validate the configured driver
try:
@ -309,7 +309,9 @@ class DeviceViewSet(CustomFieldModelViewSet):
try:
response[method] = getattr(d, method)()
except NotImplementedError:
response[method] = {'error': 'Method not implemented for NAPALM driver {}'.format(driver)}
response[method] = {'error': 'Method {} not implemented for NAPALM driver {}'.format(method, driver)}
except Exception as e:
response[method] = {'error': 'Method {} failed: {}'.format(method, e)}
d.close()
return Response(response)