You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
phpypam is intended to be a complete library for speaking with phpIPAM API.
5
+
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.
6
+
7
+
## installation
8
+
9
+
This library is hosted on [pypi.org](https://pypi.org/project/phpypam/), so you can simply use `pip` to install it.
10
+
11
+
~~~bash
12
+
pip install phpypam
13
+
~~~
8
14
9
-
Using `phpypam` is as easy as using the UI.
15
+
Alternatively you can install it from source. You need to do the following:
To start using `phpypam` you simply have to write some lines of code.
32
+
33
+
~~~python
12
34
import phpypam
13
35
14
36
pi = phpypam.api(
@@ -19,4 +41,138 @@ pi = phpypam.api(
19
41
ssl_verify=True
20
42
)
21
43
pi.get_entity(controller='sections')
22
-
```
44
+
~~~
45
+
46
+
## making api connection
47
+
48
+
To connect to phpIPAM API you need some parameter to authenticate against the phpIPAM instance.
49
+
50
+
Parameter | Description | Default |
51
+
:-------- | :---------- | :------ |
52
+
url | The URL to a phpIPAM instance. It includes the protocol (http or https). | |
53
+
app_id | The app_id which is used for the API operations. |
54
+
username | The `username` which is used to connect to API. | None |
55
+
password | The `password` to authenticate `username` against API. | None |
56
+
ssl_verify | Should certificate of endpoint verified or not. Useful if you use a self signed certificate. | True |
57
+
58
+
*Example* connect to api and request current token:
59
+
60
+
~~~python
61
+
connection_params =dict(
62
+
url='https://ipam.example.com',
63
+
app_id='ansible',
64
+
username='apiuser',
65
+
password='apiP455wd',
66
+
ssl_verify=True
67
+
)
68
+
69
+
pi = phpypam.api(**connection_params)
70
+
71
+
token = pi.get_token()
72
+
~~~
73
+
74
+
First of all you create a dictionary with the connection data. This dictionary will unpacked for creating a `phpypam.api` object.
75
+
76
+
If all went well you can use the `get_token` to get the currently valid token from API.
77
+
78
+
## get available controllers
79
+
80
+
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.
81
+
82
+
~~~python
83
+
controllers = pi.controllers()
84
+
~~~
85
+
86
+
The method returns a set with all supported controllers.
87
+
88
+
## get an entity
89
+
90
+
To get an entity the `get_entity` method has to be used.
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.
149
+
Then you get the entity to obtain its id to work on.
150
+
151
+
**Note:** All modifying operations need the id of an entity not the name.
152
+
153
+
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.
154
+
155
+
## delete an entity
156
+
157
+
To delete an entity you have to use the `delete_entity` method.
0 commit comments