Commit e952c066 authored by Morten Brekkevold's avatar Morten Brekkevold

add API functionality for object patching

parent 57da2efd
......@@ -33,6 +33,16 @@ class NAVAPI(object):
response.raise_for_status()
return response.json()
def _simple_patch(self, endpoint, data, **kwargs):
response = requests.patch(
self._endpoint(endpoint),
headers=self._base_headers(),
data=data,
**kwargs
)
response.raise_for_status()
return response.json()
def _simple_delete(self, endpoint, **kwargs):
response = requests.delete(
self._endpoint(endpoint),
......@@ -60,6 +70,17 @@ class NAVAPI(object):
response = self._simple_post('/netbox/', data=netbox)
return response
def patch_netbox(self, netbox_id, patch):
try:
response = self._simple_patch('/netbox/{}/'.format(netbox_id),
data=patch)
except HTTPError as error:
if error.response.status_code == 404:
raise ObjectNotFound(error.response.content.decode())
else:
raise
return response
def delete_netbox(self, netbox_id):
response = self._simple_delete("/netbox/{}".format(netbox_id))
return response
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment