Skip to content

Commit 92d7620

Browse files
authored
release v0.1.2 (#21)
* detailed exception handling * prepare release
1 parent d98a7c9 commit 92d7620

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

phpypam/core/exceptions.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ def __init__(self, *args, **kwargs):
99
self._code = kwargs.pop('code', None)
1010
self._message = kwargs.pop('message', None)
1111

12-
if self._code == 200:
13-
if self._message == 'No subnets found':
14-
raise PHPyPAMEntityNotFoundException(self._message)
12+
_NOT_FOUND_MESSAGES = {
13+
'No subnets found',
14+
'Address not found',
15+
}
16+
17+
if (self._code == 200 and self._message in _NOT_FOUND_MESSAGES) or self.code == 404:
18+
raise PHPyPAMEntityNotFoundException(self._message)
1519
elif self._code == 500:
1620
if self._message == 'Invalid username or password':
1721
raise PHPyPAMInvalidCredentials(self._message)
1822
elif self._code == 400:
1923
raise PHPyPAMInvalidSyntax(message=self._message)
20-
elif self._code == 404:
21-
raise PHPyPAMEntityNotFoundException(self._message)
2224

2325
# super(PHPyPAMException, self).__init__(*args, **kwargs)
2426

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="phpypam",
8-
version="0.1.1",
8+
version="0.1.2",
99
author="Christian Meißner",
1010
author_email="Christian Meißner <[email protected]>",
1111
description="Python API client library for phpIPAM installation",

tests/search_address.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
import phpypam
4+
import json
5+
import yaml
6+
7+
with open('tests/vars/server.yml') as c:
8+
server = yaml.safe_load(c)
9+
10+
from phpypam import PHPyPAMEntityNotFoundException
11+
12+
13+
if __name__ == '__main__':
14+
pi = phpypam.api(
15+
url=server['url'],
16+
app_id=server['app_id'],
17+
username=server['username'],
18+
password=server['password'],
19+
ssl_verify=True
20+
)
21+
22+
addr = '10.10.0.4'
23+
24+
try:
25+
entity = pi.get_entity(controller='addresses', controller_path='search/' + addr)
26+
print("""Address '{0}' found:\nResult:\n{1}""".format(addr, json.dumps(entity, indent=2, sort_keys=True)))
27+
except PHPyPAMEntityNotFoundException:
28+
print("Address '{0}' not found.".format(addr))

0 commit comments

Comments
 (0)