Skip to content

release v0.1.2 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions phpypam/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ def __init__(self, *args, **kwargs):
self._code = kwargs.pop('code', None)
self._message = kwargs.pop('message', None)

if self._code == 200:
if self._message == 'No subnets found':
raise PHPyPAMEntityNotFoundException(self._message)
_NOT_FOUND_MESSAGES = {
'No subnets found',
'Address not found',
}

if (self._code == 200 and self._message in _NOT_FOUND_MESSAGES) or self.code == 404:
raise PHPyPAMEntityNotFoundException(self._message)
elif self._code == 500:
if self._message == 'Invalid username or password':
raise PHPyPAMInvalidCredentials(self._message)
elif self._code == 400:
raise PHPyPAMInvalidSyntax(message=self._message)
elif self._code == 404:
raise PHPyPAMEntityNotFoundException(self._message)

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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="phpypam",
version="0.1.1",
version="0.1.2",
author="Christian Meißner",
author_email="Christian Meißner <cme+codeaffen@meissner.sh>",
description="Python API client library for phpIPAM installation",
Expand Down
28 changes: 28 additions & 0 deletions tests/search_address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python

import phpypam
import json
import yaml

with open('tests/vars/server.yml') as c:
server = yaml.safe_load(c)

from phpypam import PHPyPAMEntityNotFoundException


if __name__ == '__main__':
pi = phpypam.api(
url=server['url'],
app_id=server['app_id'],
username=server['username'],
password=server['password'],
ssl_verify=True
)

addr = '10.10.0.4'

try:
entity = pi.get_entity(controller='addresses', controller_path='search/' + addr)
print("""Address '{0}' found:\nResult:\n{1}""".format(addr, json.dumps(entity, indent=2, sort_keys=True)))
except PHPyPAMEntityNotFoundException:
print("Address '{0}' not found.".format(addr))