syneto_api 0.2.32__tar.gz → 0.2.34__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.
- {syneto_api-0.2.32 → syneto_api-0.2.34}/PKG-INFO +1 -1
- {syneto_api-0.2.32 → syneto_api-0.2.34}/pyproject.toml +1 -1
- {syneto_api-0.2.32 → syneto_api-0.2.34}/setup.py +1 -1
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/api_client.py +23 -10
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/auth_api.py +5 -3
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/central_api.py +7 -1
- {syneto_api-0.2.32 → syneto_api-0.2.34}/README.md +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/__init__.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/jobs_api.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/keyring.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/protection_api.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/settings.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/storage_api.py +0 -0
- {syneto_api-0.2.32 → syneto_api-0.2.34}/src/syneto_api/virt_api.py +0 -0
|
@@ -20,7 +20,7 @@ install_requires = \
|
|
|
20
20
|
|
|
21
21
|
setup_kwargs = {
|
|
22
22
|
'name': 'syneto-api',
|
|
23
|
-
'version': '0.2.
|
|
23
|
+
'version': '0.2.34',
|
|
24
24
|
'description': 'Syneto Client API library',
|
|
25
25
|
'long_description': '# Syneto API\n\nSyneto Client API library: authentication, storage, virtualization and protection\n\n# Installation\n\n```\n$ pip install syneto-api\n```\n\n# Basic Usage\n\n```\nfrom syneto_api import Authentication, Virtualization, Storage, Protection\n\nauth_api = Authentication(url_base="https://syneto-instance-ip-address/api/auth", insecure_ssl=True)\nresponse = auth_api.login(username="admin", password="admin")\njwt = response[\'jwt\']\n\nvirt_api = Virtualization(url_base="https://syneto-instance-ip-address/api/virtualization", insecure_ssl=True)\nvirt_api.set_auth_jwt(jwt)\nprint(virt_api.get_vms())\n\nstorage_api = Storage(url_base="https://syneto-instance-ip-address/api/storage", insecure_ssl=True)\nstorage_api.set_auth_jwt(jwt)\nprint(storage_api.get_pools())\n```\n\n# Environment Variables\n\nFor conveninence, the base urls for the api endpoints are also accepted as environment variables, please see below.\n\n```\nAUTH_SERVICE=https://syneto-instance-ip-address/api/auth\nVIRTUALIZATION_SERVICE=https://syneto-instance-ip-address/api/virtualization\nSTORAGE_SERVICE=https://syneto-instance-ip-address/api/storage\nPROTECTION_SERVICE=https://syneto-instance-ip-address/api/protection\n```\n\nIf you are using self-signed SSL certificates, set the following env. so that the http request library does not perform ssl verification. \n\n```\nALLOW_INSECURE_SSL=True\n```\n',
|
|
26
26
|
'author': 'Your Name',
|
|
@@ -84,6 +84,7 @@ class APIClientBase:
|
|
|
84
84
|
query_args: dict = None,
|
|
85
85
|
body: dict = None,
|
|
86
86
|
success_codes: list = None,
|
|
87
|
+
on_response_callback=None,
|
|
87
88
|
**kwargs,
|
|
88
89
|
):
|
|
89
90
|
url = self._make_url(relative_url, *args, query_args=query_args, **kwargs)
|
|
@@ -93,16 +94,20 @@ class APIClientBase:
|
|
|
93
94
|
success_codes = APIClientBase.SUCCESS_CODES[method]
|
|
94
95
|
|
|
95
96
|
if self._use_asyncio and is_event_loop_available():
|
|
96
|
-
return self._async_request(method, url, body, success_codes, error_subject)
|
|
97
|
+
return self._async_request(method, url, body, success_codes, error_subject, on_response_callback)
|
|
97
98
|
else:
|
|
98
|
-
return self._sync_request(method, url, body, success_codes, error_subject)
|
|
99
|
+
return self._sync_request(method, url, body, success_codes, error_subject, on_response_callback)
|
|
99
100
|
|
|
100
|
-
async def _async_request(
|
|
101
|
+
async def _async_request(
|
|
102
|
+
self, method: str, url: str, body: dict, success_codes: list, error_subject: str, on_response_callback
|
|
103
|
+
):
|
|
101
104
|
try:
|
|
102
105
|
logger.debug(f"Calling {method} {url} with aiohttp lib")
|
|
103
106
|
# loop = asyncio.get_event_loop()
|
|
104
107
|
# return loop.run_until_complete(self._async_request(method, url, body, success_codes, error_subject))
|
|
105
|
-
return await self._unsafe_async_request(
|
|
108
|
+
return await self._unsafe_async_request(
|
|
109
|
+
method, url, body, success_codes, error_subject, on_response_callback
|
|
110
|
+
)
|
|
106
111
|
|
|
107
112
|
except APIException as e:
|
|
108
113
|
raise
|
|
@@ -132,7 +137,9 @@ class APIClientBase:
|
|
|
132
137
|
error = self._append_url_if_not_local_service(str(e) or type(e).__name__)
|
|
133
138
|
raise APIException(url=url, message=f"{error_subject} has failed ({error})", request_body=body,) from e
|
|
134
139
|
|
|
135
|
-
async def _unsafe_async_request(
|
|
140
|
+
async def _unsafe_async_request(
|
|
141
|
+
self, method: str, url: str, body: dict, success_codes: list, error_subject: str, on_response_callback
|
|
142
|
+
):
|
|
136
143
|
headers = None
|
|
137
144
|
if self.headers is not None and len(self.headers) > 0:
|
|
138
145
|
headers = self.headers
|
|
@@ -158,7 +165,8 @@ class APIClientBase:
|
|
|
158
165
|
if response.status in success_codes:
|
|
159
166
|
logger.debug(f"Received {response.status} from {method} {url}")
|
|
160
167
|
if is_json or self._force_json:
|
|
161
|
-
|
|
168
|
+
json_response = await response.json()
|
|
169
|
+
return on_response_callback(json_response) if on_response_callback else json_response
|
|
162
170
|
else:
|
|
163
171
|
return await response.read()
|
|
164
172
|
|
|
@@ -172,10 +180,12 @@ class APIClientBase:
|
|
|
172
180
|
response=response,
|
|
173
181
|
)
|
|
174
182
|
|
|
175
|
-
def _sync_request(
|
|
183
|
+
def _sync_request(
|
|
184
|
+
self, method: str, url: str, body: dict, success_codes: list, error_subject: str, on_response_callback
|
|
185
|
+
):
|
|
176
186
|
try:
|
|
177
187
|
logger.debug(f"Calling {method} {url} with requests lib")
|
|
178
|
-
return self._unsafe_sync_request(method, url, body, success_codes, error_subject)
|
|
188
|
+
return self._unsafe_sync_request(method, url, body, success_codes, error_subject, on_response_callback)
|
|
179
189
|
|
|
180
190
|
except APIException as e:
|
|
181
191
|
raise
|
|
@@ -205,7 +215,9 @@ class APIClientBase:
|
|
|
205
215
|
error = self._append_url_if_not_local_service(str(e) or type(e).__name__)
|
|
206
216
|
raise APIException(url=url, message=f"{error_subject} has failed ({error})", request_body=body) from e
|
|
207
217
|
|
|
208
|
-
def _unsafe_sync_request(
|
|
218
|
+
def _unsafe_sync_request(
|
|
219
|
+
self, method: str, url: str, body: dict, success_codes: list, error_subject: str, on_response_callback
|
|
220
|
+
):
|
|
209
221
|
method_func = self._get_method_func(method)
|
|
210
222
|
method_args = {"verify": self._verify_ssl_cert}
|
|
211
223
|
if self.headers is not None and len(self.headers) > 0:
|
|
@@ -219,7 +231,8 @@ class APIClientBase:
|
|
|
219
231
|
if response.status_code in success_codes:
|
|
220
232
|
logger.debug(f"Received {response.status_code} from {method} {url}")
|
|
221
233
|
if is_json or self._force_json:
|
|
222
|
-
|
|
234
|
+
json_response = response.json()
|
|
235
|
+
return on_response_callback(json_response) if on_response_callback else json_response
|
|
223
236
|
else:
|
|
224
237
|
return response.content
|
|
225
238
|
|
|
@@ -8,9 +8,7 @@ class Authentication(APIClientBase):
|
|
|
8
8
|
def __init__(self, url_base=None, **kwargs):
|
|
9
9
|
super().__init__(url_base or os.environ.get("AUTHORIZATION_SERVICE", ""), **kwargs)
|
|
10
10
|
|
|
11
|
-
def
|
|
12
|
-
body = {"username": username, "password": password}
|
|
13
|
-
response = self.post_request("/login", body=body)
|
|
11
|
+
def on_login_response(self, response):
|
|
14
12
|
if "jwt" in response:
|
|
15
13
|
token = response["jwt"]
|
|
16
14
|
parsed_base_url = urllib.parse.urlparse(self.url_base)
|
|
@@ -18,6 +16,10 @@ class Authentication(APIClientBase):
|
|
|
18
16
|
keyring.set_token(token)
|
|
19
17
|
return response
|
|
20
18
|
|
|
19
|
+
def login(self, username: str, password: str):
|
|
20
|
+
body = {"username": username, "password": password}
|
|
21
|
+
return self.post_request("/login", body=body, on_response_callback=self.on_login_response)
|
|
22
|
+
|
|
21
23
|
def get_public_key(self, username: str):
|
|
22
24
|
return self.get_request("/public-key", query_args={"username": username})
|
|
23
25
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
-
from typing import Any, Optional
|
|
2
|
+
from typing import Any, Optional, List, Dict
|
|
3
3
|
from .api_client import APIClientBase
|
|
4
4
|
|
|
5
5
|
|
|
@@ -34,3 +34,9 @@ class Central(APIClientBase):
|
|
|
34
34
|
|
|
35
35
|
def disable_monitoring(self) -> Any:
|
|
36
36
|
return self.post_request("/monitoring/disable")
|
|
37
|
+
|
|
38
|
+
def configure_monitoring(self, exporters: List[Any]) -> Any:
|
|
39
|
+
body: Dict = {
|
|
40
|
+
"exporters": exporters,
|
|
41
|
+
}
|
|
42
|
+
return self.post_request("/monitoring/configure", body=body)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|