Skip to content

Commit 0fea51d

Browse files
authored
Merge pull request #33 from jagter/update_delete_by_id
Added update/delete by ID methods
2 parents b893492 + 7e88e1e commit 0fea51d

File tree

7 files changed

+484
-13
lines changed

7 files changed

+484
-13
lines changed

netbox/connection.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ def patch(self, params, key, **kwargs):
105105

106106
body_data = {key: value for (key, value) in kwargs.items()}
107107
resp_ok, resp_status, resp_data = self.__request('PATCH', params=params, key=key, body=body_data)
108+
108109
if resp_ok and resp_status == 200:
109110
return resp_data
110-
else:
111-
raise exceptions.UpdateException(resp_data)
111+
112+
if resp_status == 404:
113+
raise exceptions.NotFoundException("object not found with id {}".format(key), from_con=True)
114+
115+
raise exceptions.UpdateException(resp_data)
112116

113117
def post(self, params, required_fields, **kwargs):
114118

@@ -129,8 +133,11 @@ def delete(self, params, del_id):
129133
resp_ok, resp_status, resp_data = self.__request('DELETE', del_str)
130134
if resp_ok and resp_status == 204:
131135
return True
132-
else:
133-
raise exceptions.DeleteException(resp_data)
136+
137+
if resp_status == 404:
138+
raise exceptions.NotFoundException("Unable to found object with id {}".format(del_id), from_con=True)
139+
140+
raise exceptions.DeleteException(resp_data)
134141

135142
def close(self):
136143

0 commit comments

Comments
 (0)