Skip to content

Commit

Permalink
Catch pynetbox.RequestError
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Jan 5, 2020
1 parent f8ee7d3 commit 2725fa1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions salt/modules/netbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

try:
import pynetbox
from pynetbox.core.query import RequestError
HAS_PYNETBOX = True
except ImportError:
HAS_PYNETBOX = False
Expand Down Expand Up @@ -102,7 +101,7 @@ def _add(app, endpoint, payload):
nb = _nb_obj(auth_required=True)
try:
return getattr(getattr(nb, app), endpoint).create(**payload)
except RequestError as e:
except pynetbox.RequestError as e:
log.error("{}, {}, {}".format(e.req.request.headers, e.request_body, e.error))
return False

Expand Down Expand Up @@ -378,7 +377,7 @@ def create_device(name,
return False

status = {'label': "Active", 'value': 1}
except RequestError as e:
except pynetbox.RequestError as e:
log.error("{}, {}, {}".format(e.req.request.headers, e.request_body, e.error))
return False

Expand Down Expand Up @@ -415,7 +414,7 @@ def update_device(name, **kwargs):
try:
nb_device.save()
return {'dcim': {'devices': kwargs}}
except RequestError as e:
except pynetbox.RequestError as e:
log.error("{}, {}, {}".format(e.req.request.headers, e.request_body, e.error))
return False

Expand Down Expand Up @@ -797,7 +796,7 @@ def update_interface(device_name, interface_name, **kwargs):
try:
nb_interface.save()
return {'dcim': {'interfaces': {nb_interface.id: dict(nb_interface)}}}
except RequestError as e:
except pynetbox.RequestError as e:
log.error("{}, {}, {}".format(e.req.request.headers, e.request_body, e.error))
return False

Expand Down

0 comments on commit 2725fa1

Please sign in to comment.