Skip to content

Commit f9c7399

Browse files
committed
Add delete method
Add method to delete existing entities. In this case we changed also the `PyHPIPAMEntityNotFound` exception to handle errors if the entity whihch should be delete does not exists.
1 parent 27aecd8 commit f9c7399

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

pyhpipam/core/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
GET = requests.get
1111
POST = requests.post
1212
PATCH = requests.patch
13+
DELETE = requests.delete
1314
OPTIONS = requests.options
1415

1516

@@ -114,3 +115,8 @@ def create_entity(self, controller, data, **kwargs):
114115
_path = '{}/{}'.format(_path, _controller_path)
115116

116117
return self._query(token=self._api_token, method=POST, path=_path, data=data)
118+
119+
def delete_entity(self, controller, controller_path, **kwargs):
120+
_path = '{}/{}'.format(controller, controller_path)
121+
122+
return self._query(token=self._api_token, method=DELETE, path=_path)

pyhpipam/core/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ def __init__(self, *args, **kwargs):
1515
elif self._code == 400:
1616
raise PyHPIPAMInvalidSyntax(message=self._message)
1717
elif self._code == 404:
18-
if self._message == 'Not Found':
19-
raise PyHPIPAMEntityNotFoundException(self._message)
18+
raise PyHPIPAMEntityNotFoundException(self._message)
2019

2120
# super(PyHPIPAMException, self).__init__(*args, **kwargs)
2221

0 commit comments

Comments
 (0)