pyixapi 0.2.2__tar.gz → 0.2.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.
- {pyixapi-0.2.2 → pyixapi-0.2.3}/PKG-INFO +1 -1
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/api.py +13 -15
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/endpoint.py +7 -12
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/query.py +14 -21
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/response.py +6 -6
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/util.py +1 -1
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyproject.toml +1 -1
- pyixapi-0.2.2/pyixapi/__main__.py +0 -69
- {pyixapi-0.2.2 → pyixapi-0.2.3}/LICENSE +0 -0
- {pyixapi-0.2.2 → pyixapi-0.2.3}/README.md +0 -0
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/__init__.py +0 -0
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/__init__.py +0 -0
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/core/token.py +0 -0
- {pyixapi-0.2.2 → pyixapi-0.2.3}/pyixapi/models.py +0 -0
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
1
|
import requests
|
|
4
2
|
|
|
5
3
|
from pyixapi.core.endpoint import Endpoint
|
|
@@ -44,13 +42,13 @@ class API(object):
|
|
|
44
42
|
|
|
45
43
|
def __init__(
|
|
46
44
|
self,
|
|
47
|
-
url
|
|
48
|
-
key
|
|
49
|
-
secret
|
|
50
|
-
access_token
|
|
51
|
-
refresh_token
|
|
52
|
-
user_agent
|
|
53
|
-
)
|
|
45
|
+
url,
|
|
46
|
+
key,
|
|
47
|
+
secret,
|
|
48
|
+
access_token="",
|
|
49
|
+
refresh_token="",
|
|
50
|
+
user_agent=f"pyixapi/{__version__}",
|
|
51
|
+
):
|
|
54
52
|
self.url = url.rstrip("/")
|
|
55
53
|
self.key = key
|
|
56
54
|
self.secret = secret
|
|
@@ -92,7 +90,7 @@ class API(object):
|
|
|
92
90
|
self.role_assignments = Endpoint(self, "role-assignments", model=RoleAssignment)
|
|
93
91
|
|
|
94
92
|
@property
|
|
95
|
-
def version(self)
|
|
93
|
+
def version(self):
|
|
96
94
|
"""
|
|
97
95
|
Get the API version of IX-API.
|
|
98
96
|
"""
|
|
@@ -101,20 +99,20 @@ class API(object):
|
|
|
101
99
|
).get_version()
|
|
102
100
|
|
|
103
101
|
@property
|
|
104
|
-
def accounts(self)
|
|
102
|
+
def accounts(self):
|
|
105
103
|
return Endpoint(
|
|
106
104
|
self, "customers" if self.version == 1 else "accounts", model=Account
|
|
107
105
|
)
|
|
108
106
|
|
|
109
107
|
@property
|
|
110
|
-
def product_offerings(self)
|
|
108
|
+
def product_offerings(self):
|
|
111
109
|
return Endpoint(
|
|
112
110
|
self,
|
|
113
111
|
"products" if self.version == 1 else "product-offerings",
|
|
114
112
|
model=ProductOffering,
|
|
115
113
|
)
|
|
116
114
|
|
|
117
|
-
def authenticate(self)
|
|
115
|
+
def authenticate(self):
|
|
118
116
|
"""
|
|
119
117
|
Authenticate and generate a pair of tokens.
|
|
120
118
|
|
|
@@ -141,7 +139,7 @@ class API(object):
|
|
|
141
139
|
|
|
142
140
|
return Record(r, self, self.auth)
|
|
143
141
|
|
|
144
|
-
def refresh_authentication(self)
|
|
142
|
+
def refresh_authentication(self):
|
|
145
143
|
"""
|
|
146
144
|
Prolong authentication by refreshing the tokens pair.
|
|
147
145
|
"""
|
|
@@ -156,7 +154,7 @@ class API(object):
|
|
|
156
154
|
|
|
157
155
|
return Record(r, self, self.auth)
|
|
158
156
|
|
|
159
|
-
def health(self)
|
|
157
|
+
def health(self):
|
|
160
158
|
"""
|
|
161
159
|
Get the health information from IX-API.
|
|
162
160
|
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
from typing import TYPE_CHECKING, Optional
|
|
2
|
-
|
|
3
1
|
from pyixapi.core.query import Request, RequestError
|
|
4
2
|
from pyixapi.core.response import Record, RecordSet
|
|
5
3
|
from pyixapi.core.util import cat
|
|
6
4
|
|
|
7
|
-
if TYPE_CHECKING:
|
|
8
|
-
from .api import API
|
|
9
|
-
|
|
10
5
|
|
|
11
|
-
class Endpoint:
|
|
6
|
+
class Endpoint(object):
|
|
12
7
|
"""
|
|
13
8
|
Represent actions available on endpoints in the IX-API.
|
|
14
9
|
|
|
@@ -16,16 +11,16 @@ class Endpoint:
|
|
|
16
11
|
object.
|
|
17
12
|
"""
|
|
18
13
|
|
|
19
|
-
def __init__(self, api
|
|
14
|
+
def __init__(self, api, name, model=None):
|
|
20
15
|
self.return_obj = model if model else Record
|
|
21
16
|
self.api = api
|
|
22
17
|
self.url = cat(api.url, name)
|
|
23
18
|
self.name = name
|
|
24
19
|
|
|
25
|
-
def __str__(self)
|
|
20
|
+
def __str__(self):
|
|
26
21
|
return self.url
|
|
27
22
|
|
|
28
|
-
def all(self)
|
|
23
|
+
def all(self):
|
|
29
24
|
"""
|
|
30
25
|
Return all objects from an endpoint.
|
|
31
26
|
"""
|
|
@@ -36,7 +31,7 @@ class Endpoint:
|
|
|
36
31
|
)
|
|
37
32
|
return RecordSet(self, r)
|
|
38
33
|
|
|
39
|
-
def filter(self, *args, **kwargs)
|
|
34
|
+
def filter(self, *args, **kwargs):
|
|
40
35
|
"""
|
|
41
36
|
Query the list of a given endpoint. Also take named arguments that match the
|
|
42
37
|
usable filters on a given endpoint.
|
|
@@ -49,7 +44,7 @@ class Endpoint:
|
|
|
49
44
|
)
|
|
50
45
|
return RecordSet(self, r)
|
|
51
46
|
|
|
52
|
-
def get(self, *args, **kwargs)
|
|
47
|
+
def get(self, *args, **kwargs):
|
|
53
48
|
"""
|
|
54
49
|
Return a single object from an endpoint.
|
|
55
50
|
"""
|
|
@@ -88,7 +83,7 @@ class Endpoint:
|
|
|
88
83
|
else:
|
|
89
84
|
raise e
|
|
90
85
|
|
|
91
|
-
def create(self, *args, **kwargs)
|
|
86
|
+
def create(self, *args, **kwargs):
|
|
92
87
|
"""
|
|
93
88
|
Creates an object on an endpoint.
|
|
94
89
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from typing import Any, Optional
|
|
3
2
|
|
|
4
3
|
from pyixapi.core.util import cat
|
|
5
4
|
|
|
@@ -34,7 +33,7 @@ class RequestError(Exception):
|
|
|
34
33
|
self.req = r
|
|
35
34
|
self.error = r.text
|
|
36
35
|
|
|
37
|
-
def __str__(self)
|
|
36
|
+
def __str__(self):
|
|
38
37
|
return self.message
|
|
39
38
|
|
|
40
39
|
|
|
@@ -45,7 +44,7 @@ class ContentError(Exception):
|
|
|
45
44
|
those cases.
|
|
46
45
|
"""
|
|
47
46
|
|
|
48
|
-
def __init__(self, req)
|
|
47
|
+
def __init__(self, req):
|
|
49
48
|
super(ContentError, self).__init__(req)
|
|
50
49
|
|
|
51
50
|
self.req = req
|
|
@@ -53,11 +52,11 @@ class ContentError(Exception):
|
|
|
53
52
|
"The server returned invalid (non-JSON) data. Maybe not an IX-API server?"
|
|
54
53
|
)
|
|
55
54
|
|
|
56
|
-
def __str__(self)
|
|
55
|
+
def __str__(self):
|
|
57
56
|
return self.error
|
|
58
57
|
|
|
59
58
|
|
|
60
|
-
class Request:
|
|
59
|
+
class Request(object):
|
|
61
60
|
"""
|
|
62
61
|
Create requests to the IX-API.
|
|
63
62
|
|
|
@@ -81,7 +80,7 @@ class Request:
|
|
|
81
80
|
self.url = self.base if not key else cat(self.base, key)
|
|
82
81
|
self.user_agent = user_agent
|
|
83
82
|
|
|
84
|
-
def get_openapi(self)
|
|
83
|
+
def get_openapi(self):
|
|
85
84
|
"""
|
|
86
85
|
Get the OpenAPI Spec.
|
|
87
86
|
"""
|
|
@@ -94,7 +93,7 @@ class Request:
|
|
|
94
93
|
else:
|
|
95
94
|
raise RequestError(req)
|
|
96
95
|
|
|
97
|
-
def get_version(self)
|
|
96
|
+
def get_version(self):
|
|
98
97
|
"""
|
|
99
98
|
Get the API version of IX-API.
|
|
100
99
|
|
|
@@ -108,7 +107,7 @@ class Request:
|
|
|
108
107
|
except RequestError:
|
|
109
108
|
return 1
|
|
110
109
|
|
|
111
|
-
def get_health(self)
|
|
110
|
+
def get_health(self):
|
|
112
111
|
"""
|
|
113
112
|
Get the health from /api/health endpoint in IX-API.
|
|
114
113
|
"""
|
|
@@ -121,13 +120,7 @@ class Request:
|
|
|
121
120
|
else:
|
|
122
121
|
raise RequestError(r)
|
|
123
122
|
|
|
124
|
-
def _make_call(
|
|
125
|
-
self,
|
|
126
|
-
verb: str = "get",
|
|
127
|
-
url_override: Optional[str] = None,
|
|
128
|
-
add_params: Optional[dict[str, Any]] = None,
|
|
129
|
-
data: Optional[Any] = None,
|
|
130
|
-
) -> Any:
|
|
123
|
+
def _make_call(self, verb="get", url_override=None, add_params=None, data=None):
|
|
131
124
|
if verb in ("post", "put") or verb == "delete" and data:
|
|
132
125
|
headers = {"Content-Type": "application/json;"}
|
|
133
126
|
else:
|
|
@@ -160,7 +153,7 @@ class Request:
|
|
|
160
153
|
else:
|
|
161
154
|
raise RequestError(r)
|
|
162
155
|
|
|
163
|
-
def get(self, add_params
|
|
156
|
+
def get(self, add_params=None):
|
|
164
157
|
"""
|
|
165
158
|
Make a GET request to IX-API.
|
|
166
159
|
|
|
@@ -179,7 +172,7 @@ class Request:
|
|
|
179
172
|
self.count = len(req)
|
|
180
173
|
yield req
|
|
181
174
|
|
|
182
|
-
def put(self, data
|
|
175
|
+
def put(self, data):
|
|
183
176
|
"""
|
|
184
177
|
Make a PUT request to IX-API.
|
|
185
178
|
|
|
@@ -191,7 +184,7 @@ class Request:
|
|
|
191
184
|
"""
|
|
192
185
|
return self._make_call(verb="put", data=data)
|
|
193
186
|
|
|
194
|
-
def post(self, data
|
|
187
|
+
def post(self, data):
|
|
195
188
|
"""
|
|
196
189
|
Make a POST request to IX-API.
|
|
197
190
|
|
|
@@ -203,7 +196,7 @@ class Request:
|
|
|
203
196
|
"""
|
|
204
197
|
return self._make_call(verb="post", data=data)
|
|
205
198
|
|
|
206
|
-
def delete(self, data
|
|
199
|
+
def delete(self, data=None):
|
|
207
200
|
"""
|
|
208
201
|
Make a DELETE request to IX-API.
|
|
209
202
|
|
|
@@ -217,7 +210,7 @@ class Request:
|
|
|
217
210
|
"""
|
|
218
211
|
return self._make_call(verb="delete", data=data)
|
|
219
212
|
|
|
220
|
-
def patch(self, data
|
|
213
|
+
def patch(self, data):
|
|
221
214
|
"""
|
|
222
215
|
Make a PATCH request to IX-API.
|
|
223
216
|
|
|
@@ -229,7 +222,7 @@ class Request:
|
|
|
229
222
|
"""
|
|
230
223
|
return self._make_call(verb="patch", data=data)
|
|
231
224
|
|
|
232
|
-
def options(self)
|
|
225
|
+
def options(self):
|
|
233
226
|
"""
|
|
234
227
|
Make an OPTIONS request to IX-API.
|
|
235
228
|
|
|
@@ -2,7 +2,7 @@ from pyixapi.core.query import Request
|
|
|
2
2
|
from pyixapi.core.util import Hashabledict
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
def get_return(lookup)
|
|
5
|
+
def get_return(lookup):
|
|
6
6
|
"""
|
|
7
7
|
Return simple representations for items passed to lookup.
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ def get_return(lookup) -> int:
|
|
|
15
15
|
return lookup
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class RecordSet:
|
|
18
|
+
class RecordSet(object):
|
|
19
19
|
"""
|
|
20
20
|
Iterator containing :py:class:`.Record` objects.
|
|
21
21
|
|
|
@@ -52,13 +52,13 @@ class RecordSet:
|
|
|
52
52
|
>>>
|
|
53
53
|
"""
|
|
54
54
|
|
|
55
|
-
def __init__(self, endpoint, request, **kwargs)
|
|
55
|
+
def __init__(self, endpoint, request, **kwargs):
|
|
56
56
|
self.endpoint = endpoint
|
|
57
57
|
self.request = request
|
|
58
58
|
self.response = self.request.get()
|
|
59
59
|
self._response_cache = []
|
|
60
60
|
|
|
61
|
-
def __iter__(self)
|
|
61
|
+
def __iter__(self):
|
|
62
62
|
return self
|
|
63
63
|
|
|
64
64
|
def __next__(self):
|
|
@@ -81,7 +81,7 @@ class RecordSet:
|
|
|
81
81
|
return self.request.count
|
|
82
82
|
|
|
83
83
|
|
|
84
|
-
class Record:
|
|
84
|
+
class Record(object):
|
|
85
85
|
"""
|
|
86
86
|
Create Python objects from IX-API responses.
|
|
87
87
|
|
|
@@ -144,7 +144,7 @@ class Record:
|
|
|
144
144
|
|
|
145
145
|
url = None
|
|
146
146
|
|
|
147
|
-
def __init__(self, values, api, endpoint)
|
|
147
|
+
def __init__(self, values, api, endpoint):
|
|
148
148
|
self._full_cache = []
|
|
149
149
|
self._init_cache = []
|
|
150
150
|
self.api = api
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
from pyixapi import api
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def create_mac_address(ixapi, mac_address):
|
|
5
|
-
"""
|
|
6
|
-
Create a new MAC address in IX-API. If the MAC already exists, return it
|
|
7
|
-
without creation.
|
|
8
|
-
"""
|
|
9
|
-
# Make sure to have a consistent case
|
|
10
|
-
mac_address = str(mac_address).lower()
|
|
11
|
-
|
|
12
|
-
# Return existing object if MAC already exists
|
|
13
|
-
for mac in ixapi.macs.all():
|
|
14
|
-
if mac["address"] == mac_address:
|
|
15
|
-
return mac
|
|
16
|
-
|
|
17
|
-
return ixapi.macs.create(
|
|
18
|
-
address=mac_address, consuming_customer="2", managing_customer="2"
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# ixapi = api(
|
|
23
|
-
# "https://api.de-cix.net/api/v1/",
|
|
24
|
-
# "-GnNlMD8hBuxSSUJmpbfUkss9dyOKfTV1SnZibNyyr4",
|
|
25
|
-
# "XKq8M6NVh5lCbPJ2Ml1h7V93QNIMsGVBfM6g2nRZF-E",
|
|
26
|
-
# )
|
|
27
|
-
|
|
28
|
-
ixapi = api(
|
|
29
|
-
"https://api.de-cix.net/api/v2/",
|
|
30
|
-
"lZJ_sV59gydj12RFATG4NaQFRI15iKRi9RC0oDqn2_A",
|
|
31
|
-
"Yt_RImR_ymuhx2r9YQXerh5q9EyE6TxaREjzmEQNr1o",
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
# ixapi = api(
|
|
35
|
-
# "http://localhost:8000/api/v1/",
|
|
36
|
-
# "c25f077c899694fc",
|
|
37
|
-
# "zZm-hzDIR5BZUhn5ULo4-_BQyx39ayRRn_0HFaSNDShqunrTiNY4a6n0Bnjqg62F-NsywRLvn3Dt3pRXWRgS1A",
|
|
38
|
-
# )
|
|
39
|
-
|
|
40
|
-
authentication = ixapi.authenticate()
|
|
41
|
-
print(authentication)
|
|
42
|
-
|
|
43
|
-
print(f"IX-API is at version {ixapi.version}")
|
|
44
|
-
|
|
45
|
-
authentication = ixapi.authenticate()
|
|
46
|
-
print(authentication)
|
|
47
|
-
|
|
48
|
-
print([i for i in ixapi.accounts.all()])
|
|
49
|
-
|
|
50
|
-
# for i in ixapi.ips.all():
|
|
51
|
-
# print(f"{i.ip} - {i.network}")
|
|
52
|
-
# print(ixapi.network_service_configs.get("DXDB:PAS:509177"))
|
|
53
|
-
|
|
54
|
-
# for i in ixapi.ports.all():
|
|
55
|
-
# print(i)
|
|
56
|
-
|
|
57
|
-
# print(len(ixapi.network_services.filter(consuming_customer="DXDB:CUST:1348")))
|
|
58
|
-
# print(len(ixapi.network_services.all()))
|
|
59
|
-
|
|
60
|
-
# mac = create_mac_address(ixapi, "e4:f7:ad:58:87:ff")
|
|
61
|
-
|
|
62
|
-
# for i in ixapi.macs.all():
|
|
63
|
-
# print(dict(i))
|
|
64
|
-
|
|
65
|
-
# for i in ixapi.network_service_configs.all():
|
|
66
|
-
# # i.macs = [mac]
|
|
67
|
-
# # print(i.save())
|
|
68
|
-
# i.update({"macs": [mac]})
|
|
69
|
-
# print(dict(i))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|