45
45
sync_detailed as _get_session_sync ,
46
46
)
47
47
from scaleway_qaas_client .quantum_as_a_service_api_client .api .sessions .list_sessions import (
48
- sync_detailed as _list_session_sync ,
48
+ sync_detailed as _list_sessions_sync ,
49
49
)
50
50
from scaleway_qaas_client .quantum_as_a_service_api_client .api .sessions .terminate_session import (
51
51
sync_detailed as _terminate_session_sync ,
@@ -81,10 +81,15 @@ def _raise_on_error(response: Response):
81
81
82
82
class QaaSClient :
83
83
def __init__ (self , project_id : str , secret_key : str , url : str = _DEFAULT_URL ):
84
+ if not project_id :
85
+ raise Exception ("QaasClient: project_id cannot be None" )
86
+
87
+ if not secret_key :
88
+ raise Exception ("QaasClient: secret_key cannot be None" )
89
+
84
90
self .__project_id = project_id
85
91
86
92
self .__client = AuthenticatedClient (
87
- # headers={"X-Auth-Token": secret_key},
88
93
base_url = url ,
89
94
timeout = 10.0 ,
90
95
verify_ssl = "https" in url ,
@@ -113,6 +118,9 @@ def __repr__(self) -> str:
113
118
"""
114
119
115
120
def get_platform (self , platform_id : str ) -> ScalewayQaasV1Alpha1Platform :
121
+ if not platform_id :
122
+ raise Exception ("get_platform: platform_id cannot be None" )
123
+
116
124
response = _get_platform_sync (client = self .__client , platform_id = platform_id )
117
125
118
126
_raise_on_error (response )
@@ -166,6 +174,9 @@ def create_session(
166
174
deduplication_id : Optional [str ] = None ,
167
175
name : Optional [str ] = None ,
168
176
) -> ScalewayQaasV1Alpha1Session :
177
+ if not platform_id :
178
+ raise Exception ("create_session: platform_id cannot be None" )
179
+
169
180
name = name if name else f"qs-{ randomname .get_name ()} "
170
181
171
182
if isinstance (max_duration , str ):
@@ -207,16 +218,44 @@ def create_session(
207
218
"""
208
219
209
220
def get_session (self , session_id : str ) -> ScalewayQaasV1Alpha1Session :
221
+ if not session_id :
222
+ raise Exception ("get_session: session_id cannot be None" )
223
+
210
224
response = _get_session_sync (client = self .__client , session_id = session_id )
211
225
212
226
_raise_on_error (response )
213
227
214
228
return response .parsed
215
229
216
- def list_session (
230
+ """List all sessions
231
+
232
+ Retrieve information about all sessions.
233
+
234
+ Args:
235
+ platform_id (Union[Unset, str]): List sessions that have been created for this platform.
236
+ tags (Union[Unset, list[str]]): List sessions with these tags.
237
+ page (Union[Unset, int]): Page number.
238
+ page_size (Union[Unset, int]): Maximum number of sessions to return per page.
239
+ order_by (Union[Unset, ListSessionsOrderBy]): Sort order of the returned sessions.
240
+ Default: ListSessionsOrderBy.NAME_ASC.
241
+ project_id (str): List sessions belonging to this project ID. (UUID format) Example:
242
+ 6170692e-7363-616c-6577-61792e636f6d.
243
+
244
+ Raises:
245
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
246
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
247
+
248
+ Returns:
249
+ List[ScalewayQaasV1Alpha1ListSessionsResponse]
250
+ """
251
+
252
+ def list_sessions (
217
253
self , platform_id : Optional [str ] = None
218
254
) -> List [ScalewayQaasV1Alpha1Session ]:
219
- response = _list_session_sync (
255
+ if not platform_id :
256
+ raise Exception ("list_session: platform_id cannot be None" )
257
+
258
+ response = _list_sessions_sync (
220
259
client = self .__client , project_id = self .__project_id , platform_id = platform_id
221
260
)
222
261
@@ -241,6 +280,9 @@ def list_session(
241
280
"""
242
281
243
282
def terminate_session (self , session_id : str ) -> ScalewayQaasV1Alpha1Session :
283
+ if not session_id :
284
+ raise Exception ("terminate_session: session_id cannot be None" )
285
+
244
286
response = _terminate_session_sync (
245
287
client = self .__client ,
246
288
session_id = session_id ,
@@ -264,6 +306,9 @@ def terminate_session(self, session_id: str) -> ScalewayQaasV1Alpha1Session:
264
306
"""
265
307
266
308
def delete_session (self , session_id : str ):
309
+ if not session_id :
310
+ raise Exception ("delete_session: session_id cannot be None" )
311
+
267
312
_delete_session_sync (client = self .__client , session_id = session_id )
268
313
269
314
"""Create a job
@@ -287,6 +332,12 @@ def create_job(
287
332
payload : Union [Dict , List , str ],
288
333
name : Optional [str ] = None ,
289
334
) -> ScalewayQaasV1Alpha1Job :
335
+ if not session_id :
336
+ raise Exception ("create_job: session_id cannot be None" )
337
+
338
+ if not payload :
339
+ raise Exception ("create_job: payload cannot be None" )
340
+
290
341
payload = payload if isinstance (payload , str ) else json .dumps (payload )
291
342
name = name if name else f"qj-{ randomname .get_name ()} "
292
343
@@ -319,6 +370,9 @@ def create_job(
319
370
"""
320
371
321
372
def get_job (self , job_id : str ) -> ScalewayQaasV1Alpha1Job :
373
+ if not job_id :
374
+ raise Exception ("get_job: job_id cannot be None" )
375
+
322
376
response = _get_job_sync (client = self .__client , job_id = job_id )
323
377
324
378
_raise_on_error (response )
@@ -341,6 +395,9 @@ def get_job(self, job_id: str) -> ScalewayQaasV1Alpha1Job:
341
395
"""
342
396
343
397
def list_job_results (self , job_id : str ) -> List [ScalewayQaasV1Alpha1JobResult ]:
398
+ if not job_id :
399
+ raise Exception ("list_job_results: job_id cannot be None" )
400
+
344
401
response = _list_job_result_sync (client = self .__client , job_id = job_id )
345
402
346
403
_raise_on_error (response )
@@ -364,6 +421,9 @@ def list_job_results(self, job_id: str) -> List[ScalewayQaasV1Alpha1JobResult]:
364
421
"""
365
422
366
423
def cancel_job (self , job_id : str ) -> ScalewayQaasV1Alpha1Job :
424
+ if not job_id :
425
+ raise Exception ("cancel_job: job_id cannot be None" )
426
+
367
427
response = _cancel_job_sync (
368
428
client = self .__client ,
369
429
job_id = job_id ,
0 commit comments