phpypam 1.0.2__tar.gz → 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
phpypam-1.0.3/PKG-INFO ADDED
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: phpypam
3
+ Version: 1.0.3
4
+ Summary: Python API client library for phpIPAM installation
5
+ Home-page: https://codeaffen.org/projects/phpypam/
6
+ Author: Christian Meißner
7
+ Author-email: Christian Meißner <cme+codeaffen@meissner.sh>
8
+ License: GPLv3
9
+ Keywords: api phpipam
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Intended Audience :: Developers
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: requests<3.0,>=2.31
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: keywords
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # phpypam: Python API client library for phpIPAM installation
31
+
32
+ [![PyPI version](https://badge.fury.io/py/phpypam.svg)](https://badge.fury.io/py/phpypam)
33
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/ed3511c33a254bfe942777c9ef3251e3)](https://www.codacy.com/gh/codeaffen/phpypam/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=codeaffen/phpypam&amp;utm_campaign=Badge_Grade)
34
+ [![Documentation Status](https://readthedocs.org/projects/phpypam/badge/?version=latest)](https://phpypam.readthedocs.io/en/latest/?badge=latest)
35
+
36
+ As we started to develop phpipam-ansible-modules we used an existing python library for phpIPAM API. As we needed a good error handling and we don't expect a quick fix of existing project we started to develop our own library.
37
+
38
+ ## installation
39
+
40
+ This library is hosted on [pypi.org](https://pypi.org/project/phpypam/), so you can simply use `pip` to install it.
41
+
42
+ ~~~bash
43
+ pip install phpypam
44
+ ~~~
45
+
46
+ Alternatively you can install it from source. You need to do the following:
47
+
48
+ ~~~bash
49
+ $ git clone https://github.com/codeaffen/phpypam.git
50
+ Cloning into 'phpypam'...
51
+ remote: Enumerating objects: 1, done.
52
+ remote: Counting objects: 100% (1/1), done.
53
+ remote: Total 366 (delta 0), reused 0 (delta 0), pack-reused 365
54
+ Receiving objects: 100% (366/366), 88.57 KiB | 521.00 KiB/s, done.
55
+ Resolving deltas: 100% (187/187), done.
56
+ $ cd phpypam/
57
+ $ python setup.py install
58
+ ~~~
59
+
60
+ ## quick start
61
+
62
+ To start using `phpypam` you simply have to write some lines of code.
63
+
64
+ ~~~python
65
+ import phpypam
66
+
67
+ pi = phpypam.api(
68
+ url='https://ipam.example.com',
69
+ app_id='ansible',
70
+ username='apiuser',
71
+ password='apiP455wd',
72
+ ssl_verify=True
73
+ )
74
+ pi.get_entity(controller='sections')
75
+ ~~~
76
+
77
+ ## making api connection
78
+
79
+ To connect to phpIPAM API you need some parameters to authenticate against the phpIPAM instance.
80
+
81
+ Parameter | Description | Default |
82
+ :-------- | :---------- | :------ |
83
+ url | The URL to a phpIPAM instance. It includes the protocol (http or https). | |
84
+ app_id | The app_id which is used for the API operations. |
85
+ username | The `username` which is used to connect to API. | None |
86
+ password | The `password` to authenticate `username` against API. | None |
87
+ ssl_verify | Should certificate of endpoint verified or not. Useful if you use a self signed certificate. | True |
88
+
89
+ *Example* connect to api and request current token:
90
+
91
+ ~~~python
92
+ connection_params = dict(
93
+ url='https://ipam.example.com',
94
+ app_id='ansible',
95
+ username='apiuser',
96
+ password='apiP455wd',
97
+ ssl_verify=True
98
+ )
99
+
100
+ pi = phpypam.api(**connection_params)
101
+
102
+ token = pi.get_token()
103
+ ~~~
104
+
105
+ First of all you create a dictionary with the connection data. This dictionary will unpacked for creating a `phpypam.api` object.
106
+
107
+ If all went well you can use the `get_token` to get the currently valid token from API.
108
+
109
+ ## get available controllers
110
+
111
+ To work with the phpIPAM api it is useful if you know all available controllers. To achieve this you can either read the api documentation or you can use the `controllers` method.
112
+
113
+ ~~~python
114
+ controllers = pi.controllers()
115
+ ~~~
116
+
117
+ The method returns a set with all supported controllers.
118
+
119
+ ## get an entity
120
+
121
+ To get an entity the `get_entity` method has to be used.
122
+
123
+ ~~~python
124
+ get_entity(controller, controller_path=None, params=None)
125
+ ~~~
126
+
127
+ *Example* get a `section` by name:
128
+
129
+ ~~~python
130
+ entity = pi.get_entity(controller='sections', controller_path='foobar')
131
+ ~~~
132
+
133
+ This call returns a dictionary for the entity with the name `foobar`.
134
+
135
+ ## create an entity
136
+
137
+ To create an entity the `create_entity` method has to be used.
138
+
139
+ ~~~python
140
+ create_entity(controller, controller_path=None, data=None, params=None)
141
+ ~~~
142
+
143
+ *Example* create a `section` if it does not exists:
144
+
145
+ ~~~python
146
+ my_section = dict(
147
+ name='foobar',
148
+ description='new section',
149
+ permissions='{"3":"1","2":"2"}'
150
+ )
151
+
152
+ try:
153
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
154
+ except PHPyPAMEntityNotFoundException:
155
+ print('create entity')
156
+ entity = pi.create_entity(controller='sections', data=my_section)
157
+
158
+ ~~~
159
+
160
+ In this example first we check if the section we work on already exists. If the PHPyPAMEntityNotFoundException is raised we create the entity.
161
+
162
+ ## update an entity
163
+
164
+ To update an entity you have to use the `update_entity` method.
165
+
166
+ ~~~python
167
+ update_entity(controller, controller_path=None, data=None, params=None)
168
+ ~~~
169
+
170
+ *Example* update a `section` if it exists:
171
+
172
+ ~~~python
173
+ my_section['description'] = 'new description'
174
+
175
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
176
+ pi.update_entity(controller='sections', controller_path=entity['id'], data=my_section)
177
+ ~~~
178
+
179
+ To change data you have to modify the value of the desired key to the value you want. You can see the data is changed in the dict from the former example.
180
+ Then you get the entity to obtain its id to work on.
181
+
182
+ **Note:** All modifying operations need the id of an entity not the name.
183
+
184
+ In the last step you call `update_entity` and put the entity id in parameter `controller_path` with the `data` parameter you provide the fully entity description dictionary.
185
+
186
+ ## delete an entity
187
+
188
+ To delete an entity you have to use the `delete_entity` method.
189
+
190
+ ~~~python
191
+ delete_entity(controller, controller_path, params=None)
192
+ ~~~
193
+
194
+ *Example* delete a existing section:
195
+
196
+ ~~~python
197
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
198
+ pi.delete_entity(controller='sections', controller_path=entity['id'])
199
+ ~~~
200
+
201
+ In this example you request the entity you had created/updated in the above examples.
202
+ After that you call `delete_entity` with the entity id from the request before.
203
+
204
+ ## possible exceptions
205
+
206
+ * ***PHPyPAMInvalidCredentials*** - will be raised if something goes wrong with the authentication
207
+ * ***PHPyPAMEntityNotFoundException*** - will be raised if an entity does not exists
208
+ * ***PHPyPAMInvalidSyntax*** - will be raised for requests which will be answered with status code 400 from API
209
+ * ***PHPyPAMException*** - for any errors which we catch but no specific exception exists this exception wil be raised
@@ -1,10 +1,11 @@
1
1
  """Package that provides phpIPAM API interface."""
2
- from pkg_resources import get_distribution, DistributionNotFound
2
+ import importlib.metadata
3
3
 
4
4
  from phpypam.core.api import Api as api
5
5
  from phpypam.core.exceptions import PHPyPAMEntityNotFoundException
6
6
 
7
7
  try:
8
- __version__ = get_distribution(__name__).version
9
- except DistributionNotFound:
8
+ __version__ = importlib.metadata.version(__name__)
9
+ except importlib.metadata.PackageNotFoundError:
10
+
10
11
  pass
@@ -15,7 +15,8 @@ class PHPyPAMException(Exception):
15
15
  'No devices configured',
16
16
  'No results (filter applied)',
17
17
  'No objects found',
18
- 'Hostname not found'
18
+ 'Hostname not found',
19
+ 'No addresses found'
19
20
  }
20
21
 
21
22
  def __init__(self, *args, code=None, message=None):
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: phpypam
3
+ Version: 1.0.3
4
+ Summary: Python API client library for phpIPAM installation
5
+ Home-page: https://codeaffen.org/projects/phpypam/
6
+ Author: Christian Meißner
7
+ Author-email: Christian Meißner <cme+codeaffen@meissner.sh>
8
+ License: GPLv3
9
+ Keywords: api phpipam
10
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Intended Audience :: Developers
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: requests<3.0,>=2.31
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: keywords
24
+ Dynamic: license
25
+ Dynamic: license-file
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # phpypam: Python API client library for phpIPAM installation
31
+
32
+ [![PyPI version](https://badge.fury.io/py/phpypam.svg)](https://badge.fury.io/py/phpypam)
33
+ [![Codacy Badge](https://app.codacy.com/project/badge/Grade/ed3511c33a254bfe942777c9ef3251e3)](https://www.codacy.com/gh/codeaffen/phpypam/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=codeaffen/phpypam&amp;utm_campaign=Badge_Grade)
34
+ [![Documentation Status](https://readthedocs.org/projects/phpypam/badge/?version=latest)](https://phpypam.readthedocs.io/en/latest/?badge=latest)
35
+
36
+ As we started to develop phpipam-ansible-modules we used an existing python library for phpIPAM API. As we needed a good error handling and we don't expect a quick fix of existing project we started to develop our own library.
37
+
38
+ ## installation
39
+
40
+ This library is hosted on [pypi.org](https://pypi.org/project/phpypam/), so you can simply use `pip` to install it.
41
+
42
+ ~~~bash
43
+ pip install phpypam
44
+ ~~~
45
+
46
+ Alternatively you can install it from source. You need to do the following:
47
+
48
+ ~~~bash
49
+ $ git clone https://github.com/codeaffen/phpypam.git
50
+ Cloning into 'phpypam'...
51
+ remote: Enumerating objects: 1, done.
52
+ remote: Counting objects: 100% (1/1), done.
53
+ remote: Total 366 (delta 0), reused 0 (delta 0), pack-reused 365
54
+ Receiving objects: 100% (366/366), 88.57 KiB | 521.00 KiB/s, done.
55
+ Resolving deltas: 100% (187/187), done.
56
+ $ cd phpypam/
57
+ $ python setup.py install
58
+ ~~~
59
+
60
+ ## quick start
61
+
62
+ To start using `phpypam` you simply have to write some lines of code.
63
+
64
+ ~~~python
65
+ import phpypam
66
+
67
+ pi = phpypam.api(
68
+ url='https://ipam.example.com',
69
+ app_id='ansible',
70
+ username='apiuser',
71
+ password='apiP455wd',
72
+ ssl_verify=True
73
+ )
74
+ pi.get_entity(controller='sections')
75
+ ~~~
76
+
77
+ ## making api connection
78
+
79
+ To connect to phpIPAM API you need some parameters to authenticate against the phpIPAM instance.
80
+
81
+ Parameter | Description | Default |
82
+ :-------- | :---------- | :------ |
83
+ url | The URL to a phpIPAM instance. It includes the protocol (http or https). | |
84
+ app_id | The app_id which is used for the API operations. |
85
+ username | The `username` which is used to connect to API. | None |
86
+ password | The `password` to authenticate `username` against API. | None |
87
+ ssl_verify | Should certificate of endpoint verified or not. Useful if you use a self signed certificate. | True |
88
+
89
+ *Example* connect to api and request current token:
90
+
91
+ ~~~python
92
+ connection_params = dict(
93
+ url='https://ipam.example.com',
94
+ app_id='ansible',
95
+ username='apiuser',
96
+ password='apiP455wd',
97
+ ssl_verify=True
98
+ )
99
+
100
+ pi = phpypam.api(**connection_params)
101
+
102
+ token = pi.get_token()
103
+ ~~~
104
+
105
+ First of all you create a dictionary with the connection data. This dictionary will unpacked for creating a `phpypam.api` object.
106
+
107
+ If all went well you can use the `get_token` to get the currently valid token from API.
108
+
109
+ ## get available controllers
110
+
111
+ To work with the phpIPAM api it is useful if you know all available controllers. To achieve this you can either read the api documentation or you can use the `controllers` method.
112
+
113
+ ~~~python
114
+ controllers = pi.controllers()
115
+ ~~~
116
+
117
+ The method returns a set with all supported controllers.
118
+
119
+ ## get an entity
120
+
121
+ To get an entity the `get_entity` method has to be used.
122
+
123
+ ~~~python
124
+ get_entity(controller, controller_path=None, params=None)
125
+ ~~~
126
+
127
+ *Example* get a `section` by name:
128
+
129
+ ~~~python
130
+ entity = pi.get_entity(controller='sections', controller_path='foobar')
131
+ ~~~
132
+
133
+ This call returns a dictionary for the entity with the name `foobar`.
134
+
135
+ ## create an entity
136
+
137
+ To create an entity the `create_entity` method has to be used.
138
+
139
+ ~~~python
140
+ create_entity(controller, controller_path=None, data=None, params=None)
141
+ ~~~
142
+
143
+ *Example* create a `section` if it does not exists:
144
+
145
+ ~~~python
146
+ my_section = dict(
147
+ name='foobar',
148
+ description='new section',
149
+ permissions='{"3":"1","2":"2"}'
150
+ )
151
+
152
+ try:
153
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
154
+ except PHPyPAMEntityNotFoundException:
155
+ print('create entity')
156
+ entity = pi.create_entity(controller='sections', data=my_section)
157
+
158
+ ~~~
159
+
160
+ In this example first we check if the section we work on already exists. If the PHPyPAMEntityNotFoundException is raised we create the entity.
161
+
162
+ ## update an entity
163
+
164
+ To update an entity you have to use the `update_entity` method.
165
+
166
+ ~~~python
167
+ update_entity(controller, controller_path=None, data=None, params=None)
168
+ ~~~
169
+
170
+ *Example* update a `section` if it exists:
171
+
172
+ ~~~python
173
+ my_section['description'] = 'new description'
174
+
175
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
176
+ pi.update_entity(controller='sections', controller_path=entity['id'], data=my_section)
177
+ ~~~
178
+
179
+ To change data you have to modify the value of the desired key to the value you want. You can see the data is changed in the dict from the former example.
180
+ Then you get the entity to obtain its id to work on.
181
+
182
+ **Note:** All modifying operations need the id of an entity not the name.
183
+
184
+ In the last step you call `update_entity` and put the entity id in parameter `controller_path` with the `data` parameter you provide the fully entity description dictionary.
185
+
186
+ ## delete an entity
187
+
188
+ To delete an entity you have to use the `delete_entity` method.
189
+
190
+ ~~~python
191
+ delete_entity(controller, controller_path, params=None)
192
+ ~~~
193
+
194
+ *Example* delete a existing section:
195
+
196
+ ~~~python
197
+ entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
198
+ pi.delete_entity(controller='sections', controller_path=entity['id'])
199
+ ~~~
200
+
201
+ In this example you request the entity you had created/updated in the above examples.
202
+ After that you call `delete_entity` with the entity id from the request before.
203
+
204
+ ## possible exceptions
205
+
206
+ * ***PHPyPAMInvalidCredentials*** - will be raised if something goes wrong with the authentication
207
+ * ***PHPyPAMEntityNotFoundException*** - will be raised if an entity does not exists
208
+ * ***PHPyPAMInvalidSyntax*** - will be raised for requests which will be answered with status code 400 from API
209
+ * ***PHPyPAMException*** - for any errors which we catch but no specific exception exists this exception wil be raised
@@ -0,0 +1 @@
1
+ requests<3.0,>=2.31
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setuptools.setup(
7
7
  name="phpypam",
8
- version="1.0.2",
8
+ version="1.0.3",
9
9
  author="Christian Meißner",
10
10
  author_email="Christian Meißner <cme+codeaffen@meissner.sh>",
11
11
  description="Python API client library for phpIPAM installation",
@@ -23,6 +23,6 @@ setuptools.setup(
23
23
  keywords='api phpipam',
24
24
  python_requires='>=3.6',
25
25
  install_requires=[
26
- 'requests (>=2.21,<3.0)',
26
+ 'requests (>=2.31,<3.0)',
27
27
  ],
28
28
  )
@@ -0,0 +1,50 @@
1
+ """Provide some base configurations for tests."""
2
+ import phpypam
3
+ import pytest
4
+ import py.path # pyright: ignore reportMissingImports=false
5
+ import yaml
6
+
7
+ from urllib.parse import urlparse, urlunparse
8
+
9
+ TEST_CASES_PATH = py.path.local(__file__).realpath() / '..' / 'test_cases'
10
+
11
+ with open('tests/vars/server.yml') as c:
12
+ server = yaml.safe_load(c)
13
+
14
+
15
+ @pytest.fixture(scope='module')
16
+ def pi(*arg, **kwargs):
17
+ """Create a phpypam.api object and return it.
18
+
19
+ :return: object phpypam
20
+ :rtype: phpypam.api
21
+ """
22
+ url = kwargs.pop('url', server['url'])
23
+ app_id = kwargs.pop('app_id', server['app_id'])
24
+ username = kwargs.pop('username', server['username'])
25
+ password = kwargs.pop('password', server['password'])
26
+ ssl_verify = kwargs.pop('ssl_verify', server['ssl_verify'])
27
+
28
+ return phpypam.api(
29
+ url=url,
30
+ app_id=app_id,
31
+ username=username,
32
+ password=password,
33
+ ssl_verify=ssl_verify,
34
+ **kwargs
35
+ )
36
+
37
+
38
+ def find_all_test_cases():
39
+ """Generate list of test cases.
40
+
41
+ :yield: generates each test case as list item
42
+ :rtype: str
43
+ """
44
+ for c in TEST_CASES_PATH.listdir(sort=True):
45
+ c = c.basename
46
+ if c.endswith('.py'):
47
+ yield c.replace('.py', '')
48
+
49
+
50
+ TEST_CASES = list(find_all_test_cases())
phpypam-1.0.2/PKG-INFO DELETED
@@ -1,196 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: phpypam
3
- Version: 1.0.2
4
- Summary: Python API client library for phpIPAM installation
5
- Home-page: https://codeaffen.org/projects/phpypam/
6
- Author: Christian Meißner
7
- Author-email: Christian Meißner <cme+codeaffen@meissner.sh>
8
- License: GPLv3
9
- Description: # phpypam: Python API client library for phpIPAM installation
10
-
11
- [![PyPI version](https://badge.fury.io/py/phpypam.svg)](https://badge.fury.io/py/phpypam)
12
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/ed3511c33a254bfe942777c9ef3251e3)](https://www.codacy.com/gh/codeaffen/phpypam/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=codeaffen/phpypam&amp;utm_campaign=Badge_Grade)
13
- [![Documentation Status](https://readthedocs.org/projects/phpypam/badge/?version=latest)](https://phpypam.readthedocs.io/en/latest/?badge=latest)
14
-
15
- As we started to develop phpipam-ansible-modules we used an existing python library for phpIPAM API. As we needed a good error handling and we don't expect a quick fix of existing project we started to develop our own library.
16
-
17
- ## installation
18
-
19
- This library is hosted on [pypi.org](https://pypi.org/project/phpypam/), so you can simply use `pip` to install it.
20
-
21
- ~~~bash
22
- pip install phpypam
23
- ~~~
24
-
25
- Alternatively you can install it from source. You need to do the following:
26
-
27
- ~~~bash
28
- $ git clone https://github.com/codeaffen/phpypam.git
29
- Cloning into 'phpypam'...
30
- remote: Enumerating objects: 1, done.
31
- remote: Counting objects: 100% (1/1), done.
32
- remote: Total 366 (delta 0), reused 0 (delta 0), pack-reused 365
33
- Receiving objects: 100% (366/366), 88.57 KiB | 521.00 KiB/s, done.
34
- Resolving deltas: 100% (187/187), done.
35
- $ cd phpypam/
36
- $ python setup.py install
37
- ~~~
38
-
39
- ## quick start
40
-
41
- To start using `phpypam` you simply have to write some lines of code.
42
-
43
- ~~~python
44
- import phpypam
45
-
46
- pi = phpypam.api(
47
- url='https://ipam.example.com',
48
- app_id='ansible',
49
- username='apiuser',
50
- password='apiP455wd',
51
- ssl_verify=True
52
- )
53
- pi.get_entity(controller='sections')
54
- ~~~
55
-
56
- ## making api connection
57
-
58
- To connect to phpIPAM API you need some parameters to authenticate against the phpIPAM instance.
59
-
60
- Parameter | Description | Default |
61
- :-------- | :---------- | :------ |
62
- url | The URL to a phpIPAM instance. It includes the protocol (http or https). | |
63
- app_id | The app_id which is used for the API operations. |
64
- username | The `username` which is used to connect to API. | None |
65
- password | The `password` to authenticate `username` against API. | None |
66
- ssl_verify | Should certificate of endpoint verified or not. Useful if you use a self signed certificate. | True |
67
-
68
- *Example* connect to api and request current token:
69
-
70
- ~~~python
71
- connection_params = dict(
72
- url='https://ipam.example.com',
73
- app_id='ansible',
74
- username='apiuser',
75
- password='apiP455wd',
76
- ssl_verify=True
77
- )
78
-
79
- pi = phpypam.api(**connection_params)
80
-
81
- token = pi.get_token()
82
- ~~~
83
-
84
- First of all you create a dictionary with the connection data. This dictionary will unpacked for creating a `phpypam.api` object.
85
-
86
- If all went well you can use the `get_token` to get the currently valid token from API.
87
-
88
- ## get available controllers
89
-
90
- To work with the phpIPAM api it is useful if you know all available controllers. To achieve this you can either read the api documentation or you can use the `controllers` method.
91
-
92
- ~~~python
93
- controllers = pi.controllers()
94
- ~~~
95
-
96
- The method returns a set with all supported controllers.
97
-
98
- ## get an entity
99
-
100
- To get an entity the `get_entity` method has to be used.
101
-
102
- ~~~python
103
- get_entity(controller, controller_path=None, params=None)
104
- ~~~
105
-
106
- *Example* get a `section` by name:
107
-
108
- ~~~python
109
- entity = pi.get_entity(controller='sections', controller_path='foobar')
110
- ~~~
111
-
112
- This call returns a dictionary for the entity with the name `foobar`.
113
-
114
- ## create an entity
115
-
116
- To create an entity the `create_entity` method has to be used.
117
-
118
- ~~~python
119
- create_entity(controller, controller_path=None, data=None, params=None)
120
- ~~~
121
-
122
- *Example* create a `section` if it does not exists:
123
-
124
- ~~~python
125
- my_section = dict(
126
- name='foobar',
127
- description='new section',
128
- permissions='{"3":"1","2":"2"}'
129
- )
130
-
131
- try:
132
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
133
- except PHPyPAMEntityNotFoundException:
134
- print('create entity')
135
- entity = pi.create_entity(controller='sections', data=my_section)
136
-
137
- ~~~
138
-
139
- In this example first we check if the section we work on already exists. If the PHPyPAMEntityNotFoundException is raised we create the entity.
140
-
141
- ## update an entity
142
-
143
- To update an entity you have to use the `update_entity` method.
144
-
145
- ~~~python
146
- update_entity(controller, controller_path=None, data=None, params=None)
147
- ~~~
148
-
149
- *Example* update a `section` if it exists:
150
-
151
- ~~~python
152
- my_section['description'] = 'new description'
153
-
154
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
155
- pi.update_entity(controller='sections', controller_path=entity['id'], data=my_section)
156
- ~~~
157
-
158
- To change data you have to modify the value of the desired key to the value you want. You can see the data is changed in the dict from the former example.
159
- Then you get the entity to obtain its id to work on.
160
-
161
- **Note:** All modifying operations need the id of an entity not the name.
162
-
163
- In the last step you call `update_entity` and put the entity id in parameter `controller_path` with the `data` parameter you provide the fully entity description dictionary.
164
-
165
- ## delete an entity
166
-
167
- To delete an entity you have to use the `delete_entity` method.
168
-
169
- ~~~python
170
- delete_entity(controller, controller_path, params=None)
171
- ~~~
172
-
173
- *Example* delete a existing section:
174
-
175
- ~~~python
176
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
177
- pi.delete_entity(controller='sections', controller_path=entity['id'])
178
- ~~~
179
-
180
- In this example you request the entity you had created/updated in the above examples.
181
- After that you call `delete_entity` with the entity id from the request before.
182
-
183
- ## possible exceptions
184
-
185
- * ***PHPyPAMInvalidCredentials*** - will be raised if something goes wrong with the authentication
186
- * ***PHPyPAMEntityNotFoundException*** - will be raised if an entity does not exists
187
- * ***PHPyPAMInvalidSyntax*** - will be raised for requests which will be answered with status code 400 from API
188
- * ***PHPyPAMException*** - for any errors which we catch but no specific exception exists this exception wil be raised
189
-
190
- Keywords: api phpipam
191
- Platform: UNKNOWN
192
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
193
- Classifier: Programming Language :: Python :: 3
194
- Classifier: Intended Audience :: Developers
195
- Requires-Python: >=3.6
196
- Description-Content-Type: text/markdown
@@ -1,196 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: phpypam
3
- Version: 1.0.2
4
- Summary: Python API client library for phpIPAM installation
5
- Home-page: https://codeaffen.org/projects/phpypam/
6
- Author: Christian Meißner
7
- Author-email: Christian Meißner <cme+codeaffen@meissner.sh>
8
- License: GPLv3
9
- Description: # phpypam: Python API client library for phpIPAM installation
10
-
11
- [![PyPI version](https://badge.fury.io/py/phpypam.svg)](https://badge.fury.io/py/phpypam)
12
- [![Codacy Badge](https://app.codacy.com/project/badge/Grade/ed3511c33a254bfe942777c9ef3251e3)](https://www.codacy.com/gh/codeaffen/phpypam/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=codeaffen/phpypam&amp;utm_campaign=Badge_Grade)
13
- [![Documentation Status](https://readthedocs.org/projects/phpypam/badge/?version=latest)](https://phpypam.readthedocs.io/en/latest/?badge=latest)
14
-
15
- As we started to develop phpipam-ansible-modules we used an existing python library for phpIPAM API. As we needed a good error handling and we don't expect a quick fix of existing project we started to develop our own library.
16
-
17
- ## installation
18
-
19
- This library is hosted on [pypi.org](https://pypi.org/project/phpypam/), so you can simply use `pip` to install it.
20
-
21
- ~~~bash
22
- pip install phpypam
23
- ~~~
24
-
25
- Alternatively you can install it from source. You need to do the following:
26
-
27
- ~~~bash
28
- $ git clone https://github.com/codeaffen/phpypam.git
29
- Cloning into 'phpypam'...
30
- remote: Enumerating objects: 1, done.
31
- remote: Counting objects: 100% (1/1), done.
32
- remote: Total 366 (delta 0), reused 0 (delta 0), pack-reused 365
33
- Receiving objects: 100% (366/366), 88.57 KiB | 521.00 KiB/s, done.
34
- Resolving deltas: 100% (187/187), done.
35
- $ cd phpypam/
36
- $ python setup.py install
37
- ~~~
38
-
39
- ## quick start
40
-
41
- To start using `phpypam` you simply have to write some lines of code.
42
-
43
- ~~~python
44
- import phpypam
45
-
46
- pi = phpypam.api(
47
- url='https://ipam.example.com',
48
- app_id='ansible',
49
- username='apiuser',
50
- password='apiP455wd',
51
- ssl_verify=True
52
- )
53
- pi.get_entity(controller='sections')
54
- ~~~
55
-
56
- ## making api connection
57
-
58
- To connect to phpIPAM API you need some parameters to authenticate against the phpIPAM instance.
59
-
60
- Parameter | Description | Default |
61
- :-------- | :---------- | :------ |
62
- url | The URL to a phpIPAM instance. It includes the protocol (http or https). | |
63
- app_id | The app_id which is used for the API operations. |
64
- username | The `username` which is used to connect to API. | None |
65
- password | The `password` to authenticate `username` against API. | None |
66
- ssl_verify | Should certificate of endpoint verified or not. Useful if you use a self signed certificate. | True |
67
-
68
- *Example* connect to api and request current token:
69
-
70
- ~~~python
71
- connection_params = dict(
72
- url='https://ipam.example.com',
73
- app_id='ansible',
74
- username='apiuser',
75
- password='apiP455wd',
76
- ssl_verify=True
77
- )
78
-
79
- pi = phpypam.api(**connection_params)
80
-
81
- token = pi.get_token()
82
- ~~~
83
-
84
- First of all you create a dictionary with the connection data. This dictionary will unpacked for creating a `phpypam.api` object.
85
-
86
- If all went well you can use the `get_token` to get the currently valid token from API.
87
-
88
- ## get available controllers
89
-
90
- To work with the phpIPAM api it is useful if you know all available controllers. To achieve this you can either read the api documentation or you can use the `controllers` method.
91
-
92
- ~~~python
93
- controllers = pi.controllers()
94
- ~~~
95
-
96
- The method returns a set with all supported controllers.
97
-
98
- ## get an entity
99
-
100
- To get an entity the `get_entity` method has to be used.
101
-
102
- ~~~python
103
- get_entity(controller, controller_path=None, params=None)
104
- ~~~
105
-
106
- *Example* get a `section` by name:
107
-
108
- ~~~python
109
- entity = pi.get_entity(controller='sections', controller_path='foobar')
110
- ~~~
111
-
112
- This call returns a dictionary for the entity with the name `foobar`.
113
-
114
- ## create an entity
115
-
116
- To create an entity the `create_entity` method has to be used.
117
-
118
- ~~~python
119
- create_entity(controller, controller_path=None, data=None, params=None)
120
- ~~~
121
-
122
- *Example* create a `section` if it does not exists:
123
-
124
- ~~~python
125
- my_section = dict(
126
- name='foobar',
127
- description='new section',
128
- permissions='{"3":"1","2":"2"}'
129
- )
130
-
131
- try:
132
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
133
- except PHPyPAMEntityNotFoundException:
134
- print('create entity')
135
- entity = pi.create_entity(controller='sections', data=my_section)
136
-
137
- ~~~
138
-
139
- In this example first we check if the section we work on already exists. If the PHPyPAMEntityNotFoundException is raised we create the entity.
140
-
141
- ## update an entity
142
-
143
- To update an entity you have to use the `update_entity` method.
144
-
145
- ~~~python
146
- update_entity(controller, controller_path=None, data=None, params=None)
147
- ~~~
148
-
149
- *Example* update a `section` if it exists:
150
-
151
- ~~~python
152
- my_section['description'] = 'new description'
153
-
154
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
155
- pi.update_entity(controller='sections', controller_path=entity['id'], data=my_section)
156
- ~~~
157
-
158
- To change data you have to modify the value of the desired key to the value you want. You can see the data is changed in the dict from the former example.
159
- Then you get the entity to obtain its id to work on.
160
-
161
- **Note:** All modifying operations need the id of an entity not the name.
162
-
163
- In the last step you call `update_entity` and put the entity id in parameter `controller_path` with the `data` parameter you provide the fully entity description dictionary.
164
-
165
- ## delete an entity
166
-
167
- To delete an entity you have to use the `delete_entity` method.
168
-
169
- ~~~python
170
- delete_entity(controller, controller_path, params=None)
171
- ~~~
172
-
173
- *Example* delete a existing section:
174
-
175
- ~~~python
176
- entity = pi.get_entity(controller='sections', controller_path=my_section['name'])
177
- pi.delete_entity(controller='sections', controller_path=entity['id'])
178
- ~~~
179
-
180
- In this example you request the entity you had created/updated in the above examples.
181
- After that you call `delete_entity` with the entity id from the request before.
182
-
183
- ## possible exceptions
184
-
185
- * ***PHPyPAMInvalidCredentials*** - will be raised if something goes wrong with the authentication
186
- * ***PHPyPAMEntityNotFoundException*** - will be raised if an entity does not exists
187
- * ***PHPyPAMInvalidSyntax*** - will be raised for requests which will be answered with status code 400 from API
188
- * ***PHPyPAMException*** - for any errors which we catch but no specific exception exists this exception wil be raised
189
-
190
- Keywords: api phpipam
191
- Platform: UNKNOWN
192
- Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
193
- Classifier: Programming Language :: Python :: 3
194
- Classifier: Intended Audience :: Developers
195
- Requires-Python: >=3.6
196
- Description-Content-Type: text/markdown
@@ -1 +0,0 @@
1
- requests<3.0,>=2.21
@@ -1,119 +0,0 @@
1
- """Provide some base configurations for tests."""
2
- import phpypam
3
- import pytest
4
- import py.path
5
- import yaml
6
-
7
- from urllib.parse import urlparse, urlunparse
8
-
9
- TEST_CASES_PATH = py.path.local(__file__).realpath() / '..' / 'test_cases'
10
-
11
- with open('tests/vars/server.yml') as c:
12
- server = yaml.safe_load(c)
13
-
14
-
15
- @pytest.fixture(scope='module')
16
- def pi(*arg, **kwargs):
17
- """Create a phpypam.api object and return it.
18
-
19
- :return: object phpypam
20
- :rtype: phpypam.api
21
- """
22
- url = kwargs.pop('url', server['url'])
23
- app_id = kwargs.pop('app_id', server['app_id'])
24
- username = kwargs.pop('username', server['username'])
25
- password = kwargs.pop('password', server['password'])
26
- ssl_verify = kwargs.pop('ssl_verify', True)
27
-
28
- return phpypam.api(
29
- url=url,
30
- app_id=app_id,
31
- username=username,
32
- password=password,
33
- ssl_verify=ssl_verify,
34
- **kwargs
35
- )
36
-
37
-
38
- def find_all_test_cases():
39
- """Generate list of test cases.
40
-
41
- :yield: generates each test case as list item
42
- :rtype: str
43
- """
44
- for c in TEST_CASES_PATH.listdir(sort=True):
45
- c = c.basename
46
- if c.endswith('.py'):
47
- yield c.replace('.py', '')
48
-
49
-
50
- TEST_CASES = list(find_all_test_cases())
51
-
52
-
53
- def pytest_addoption(parser):
54
- """Change command line options defaults.
55
-
56
- We want run our tests only in three modes
57
- `live` - interact with an existing API
58
- `record` - interact with an existing API and record the interactions
59
- `replay` - replay previouly recorded interactions with API
60
-
61
- :param parser: A parser object
62
- :type parser: object parser
63
- """
64
- parser.addoption(
65
- "--vcrmode",
66
- action="store",
67
- default="replay",
68
- choices=["replay", "record", "live"],
69
- help="mode for vcr recording; one of ['replay', 'record', 'live']",
70
- )
71
-
72
-
73
- @pytest.fixture
74
- def vcrmode(request):
75
- """Return vcrmode of a request.
76
-
77
- :param request: A request object
78
- :type request: object request
79
- :return: vcrmode
80
- :rtype: str
81
- """
82
- return request.config.getoption("vcrmode")
83
-
84
-
85
- def cassette_name(test_name=None):
86
- """Generate cassette_name."""
87
- return 'tests/fixtures/{0}.yml'.format(test_name)
88
-
89
-
90
- FILTER_REQUEST_HEADERS = ['Authorization', 'Cookie', 'Token']
91
- FILTER_RESPONSE_HEADERS = ['Apipie-Checksum', 'Date', 'ETag', 'Server', 'Set-Cookie', 'Via', 'X-Powered-By', 'X-Request-Id', 'X-Runtime']
92
-
93
-
94
- def filter_response(response):
95
- """Filter headers before recording.
96
-
97
- :param response: A response object where we want to filter the headers from.
98
- :type response: object response
99
- :return: response
100
- :rtype: object response
101
- """
102
- for header in FILTER_RESPONSE_HEADERS:
103
- # headers should be case insensitive, but for some reason they weren't for me
104
- response['headers'].pop(header.lower(), None)
105
- response['headers'].pop(header, None)
106
-
107
- return response
108
-
109
-
110
- def filter_request_uri(request):
111
- """Filter uri before recording.
112
-
113
- :param request: A request object where we want to filter the uri from.
114
- :type request: object request
115
- :return: request
116
- :rtype: object request
117
- """
118
- request.uri = urlunparse(urlparse(request.uri)._replace(netloc="ipam.example.org"))
119
- return request
File without changes
File without changes
File without changes
File without changes
File without changes