Skip to content

Commit d98a7c9

Browse files
authored
release v0.1.1 (#20)
As search for a subnet which doesn't exists leads to exit code 200 and 'No subnet found' message we need to adjust the exception handling. We also add a stupid test for that new exception state.
1 parent 700e161 commit d98a7c9

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

phpypam/core/exceptions.py

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

12-
if self._code == 500:
12+
if self._code == 200:
13+
if self._message == 'No subnets found':
14+
raise PHPyPAMEntityNotFoundException(self._message)
15+
elif self._code == 500:
1316
if self._message == 'Invalid username or password':
1417
raise PHPyPAMInvalidCredentials(self._message)
1518
elif self._code == 400:

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.0",
8+
version="0.1.1",
99
author="Christian Meißner",
1010
author_email="Christian Meißner <[email protected]>",
1111
description="Python API client library for phpIPAM installation",

tests/search_subnet.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+
cidr = '10.0.0.0/24'
23+
24+
try:
25+
entity = pi.get_entity(controller='subnets', controller_path='cidr/' + cidr)
26+
print("""Subnet with cidr '{0}' found:\nResult:\n{1}""".format(cidr, json.dumps(entity, indent=2, sort_keys=True)))
27+
except PHPyPAMEntityNotFoundException:
28+
print("Subnet with cidr '{0}' not found.".format(cidr))

0 commit comments

Comments
 (0)