-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathapideployer.py
778 lines (602 loc) · 28.6 KB
/
apideployer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
import json
from .future import DSSFuture
from ..utils import CallableStr
class DSSAPIDeployer(object):
"""
Handle to interact with the API Deployer.
Do not create this directly, use :meth:`dataikuapi.dss.DSSClient.get_apideployer`
"""
def __init__(self, client):
self.client = client
def list_deployments(self, as_objects=True):
"""
Lists deployments on the API Deployer
:param boolean as_objects: if True, returns a list of :class:`DSSAPIDeployerDeployment`, else returns a list of dict.
Each dict contains at least a field "id" indicating the identifier of this deployment
:returns: a list - see as_objects for more information
:rtype: list
"""
l = self.client._perform_json("GET", "/api-deployer/deployments")
if as_objects:
return [DSSAPIDeployerDeployment(self.client, x["deploymentBasicInfo"]["id"]) for x in l]
else:
return l
def get_deployment(self, deployment_id):
"""
Returns a handle to interact with a single deployment, as a :class:`DSSAPIDeployerDeployment`
:param str deployment_id: Identifier of the deployment to get
:rtype: :class:`DSSAPIDeployerDeployment`
"""
return DSSAPIDeployerDeployment(self.client, deployment_id)
def create_deployment(self, deployment_id, service_id, infra_id, version, endpoint_id=None, ignore_warnings=False):
"""
Creates a deployment and returns the handle to interact with it. The returned deployment
is not yet started and you need to call :meth:`~DSSAPIDeployerDeployment.start_update`
:param str deployment_id: Identifier of the deployment to create
:param str service_id: Identifier of the API Service to target
:param str infra_id: Identifier of the deployment infrastructure to use
:param str version: Identifier of the API Service version to deploy
:param str endpoint_id: Identifier of the endpoint to deploy if you use a Deploy Anywhere infra. Ignored otherwise
:param boolean ignore_warnings: ignore warnings concerning the governance status of the model version(s) to deploy
:rtype: :class:`DSSAPIDeployerDeployment`
"""
settings = {
"deploymentId": deployment_id,
"publishedServiceId": service_id,
"infraId": infra_id,
"version": version,
"endpointId": endpoint_id
}
self.client._perform_json("POST", "/api-deployer/deployments", params={"ignoreWarnings": ignore_warnings}, body=settings)
return self.get_deployment(deployment_id)
def list_stages(self):
"""
Lists infrastructure stages of the API Deployer
:rtype: list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description.
:rtype: list
"""
return self.client._perform_json("GET", "/api-deployer/stages")
def list_infras(self, as_objects=True):
"""
Lists deployment infrastructures on the API Deployer
:param boolean as_objects: if True, returns a list of :class:`DSSAPIDeployerInfra`, else returns a list of dict.
Each dict contains at least a field "id" indicating the identifier of this infra
:returns: a list - see as_objects for more information
:rtype: list
"""
l = self.client._perform_json("GET", "/api-deployer/infras")
if as_objects:
return [DSSAPIDeployerInfra(self.client, x["infraBasicInfo"]["id"]) for x in l]
else:
return l
def create_infra(self, infra_id, stage, type, govern_check_policy="NO_CHECK"):
"""
Creates a new infrastructure on the API Deployer and returns the handle to interact with it.
:param str infra_id: Unique Identifier of the infra to create
:param str stage: Infrastructure stage. Stages are configurable on each API Deployer
:param str type: STATIC, K8S, AZURE_ML, SAGEMAKER, SNOWPARK or VERTEX_AI
:param str govern_check_policy: PREVENT, WARN, or NO_CHECK depending if the deployer will check whether the saved model versions deployed on this infrastructure has to be managed and approved in Dataiku Govern
:rtype: :class:`DSSAPIDeployerInfra`
"""
settings = {
"id": infra_id,
"stage": stage,
"type": type,
"governCheckPolicy": govern_check_policy,
}
self.client._perform_json("POST", "/api-deployer/infras", body=settings)
return self.get_infra(infra_id)
def get_infra(self, infra_id):
"""
Returns a handle to interact with a single deployment infra, as a :class:`DSSAPIDeployerInfra`
:param str infra_id: Identifier of the infra to get
:rtype: :class:`DSSAPIDeployerInfra`
"""
return DSSAPIDeployerInfra(self.client, infra_id)
def list_services(self, as_objects=True):
"""
Lists API services on the API Deployer
:param boolean as_objects: if True, returns a list of :class:`DSSAPIDeployerService`, else returns a list of dict.
Each dict contains at least a field "id" indicating the identifier of this Service
:returns: a list - see as_objects for more information
:rtype: list
"""
l = self.client._perform_json("GET", "/api-deployer/services")
if as_objects:
return [DSSAPIDeployerService(self.client, x["serviceBasicInfo"]["id"]) for x in l]
else:
return l
def create_service(self, service_id):
"""
Creates a new API Service on the API Deployer and returns the handle to interact with it.
:param str service_id: Identifier of the API Service to create
:rtype: :class:`DSSAPIDeployerService`
"""
settings = {
"publishedServiceId" : service_id
}
self.client._perform_json("POST", "/api-deployer/services", body=settings)
return self.get_service(service_id)
def get_service(self, service_id):
"""
Returns a handle to interact with a single service, as a :class:`DSSAPIDeployerService`
:param str service_id: Identifier of the API service to get
:rtype: :class:`DSSAPIDeployerService`
"""
return DSSAPIDeployerService(self.client, service_id)
###############################################
# Infrastructures
###############################################
class DSSAPIDeployerInfra(object):
"""
An API Deployer infrastructure.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_infra`
"""
def __init__(self, client, infra_id):
self.client = client
self.infra_id = infra_id
@property
def id(self):
return CallableStr(self.infra_id)
def get_status(self):
"""
Returns status information about this infrastructure
:rtype: :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus`
"""
light = self.client._perform_json("GET", "/api-deployer/infras/%s" % (self.infra_id))
return DSSAPIDeployerInfraStatus(self.client, self.infra_id, light)
def get_settings(self):
"""
Gets the settings of this infra. If you want to modify the settings, you need to
call :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfraSettings.save` on the returned
object
:returns: a :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraSettings`
"""
settings = self.client._perform_json(
"GET", "/api-deployer/infras/%s/settings" % (self.infra_id))
return DSSAPIDeployerInfraSettings(self.client, self.infra_id, settings)
def delete(self):
"""
Deletes this infra
You may only delete an infra if it has no deployments on it anymore.
"""
self.client._perform_empty(
"DELETE", "/api-deployer/infras/%s" % (self.infra_id))
class DSSAPIDeployerInfraSettings(object):
"""
The settings of an API Deployer infrastructure
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_settings`
"""
def __init__(self, client, infra_id, settings):
self.client = client
self.infra_id = infra_id
self.settings = settings
def get_type(self):
"""
Gets the type of this infra
:returns: the type of this infra
:rtype: string
"""
return self.settings["type"]
def add_apinode(self, url, api_key, graphite_prefix=None):
"""
Adds an API node to the list of nodes of this infra.
Only applicable to STATIC infrastructures
:param str url: url of the API node that will be added to this infra
:param str api_key: api key secret to connect to the API node
:param str graphite_prefix: graphite prefix for metric reports if graphite is configured
"""
new_node = {
"url": url,
"adminAPIKey" : api_key,
"graphitePrefix" : graphite_prefix
}
self.settings["apiNodes"].append(new_node)
def remove_apinode(self, node_url):
"""
Removes a node from the list of nodes of this infra.
Only applicable to STATIC infrastructures
:param str node_url: URL of the node to remove
"""
api_nodes = list(self.settings["apiNodes"])
for node in api_nodes:
if node.get("url") == node_url:
self.settings["apiNodes"].remove(node)
def get_raw(self):
"""
Gets the raw settings of this infra. This returns a reference to the raw settings, not a copy,
so changes made to the returned object will be reflected when saving.
:rtype: dict
"""
return self.settings
def save(self):
"""Saves back these settings to the infra"""
self.client._perform_empty(
"PUT", "/api-deployer/infras/%s/settings" % (self.infra_id),
body = self.settings)
class DSSAPIDeployerInfraStatus(object):
"""
The status of an API Deployer infrastructure.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_status`
"""
def __init__(self, client, infra_id, light_status):
self.client = client
self.infra_id = infra_id
self.light_status = light_status
def get_deployments(self):
"""
Returns the deployments that are deployed on this infrastructure
:returns: a list of deployments
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
"""
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]
def get_raw(self):
"""
Gets the raw status information. This returns a dictionary with various information about the infrastructure
:rtype: dict
"""
return self.light_status
###############################################
# Deployments
###############################################
class DSSAPIDeployerDeployment(object):
"""
A Deployment on the API Deployer
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_deployment`
"""
def __init__(self, client, deployment_id):
self.client = client
self.deployment_id = deployment_id
@property
def id(self):
return CallableStr(self.deployment_id)
def get_status(self):
"""
Returns status information about this deployment
:rtype: dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus
"""
light = self.client._perform_json("GET", "/api-deployer/deployments/%s" % (self.deployment_id))
heavy = self.client._perform_json("GET", "/api-deployer/deployments/%s/status" % (self.deployment_id))
return DSSAPIDeployerDeploymentStatus(self.client, self.deployment_id, light, heavy)
def get_governance_status(self, version=""):
"""
Returns the governance status about this deployment if applicable
It covers all the embedded model versions
:param str version: (Optional) The specific package version of the published service to get status from. If empty, consider all the versions used in the deployment generation mapping.
:rtype: dict InforMessages containing the governance status
"""
return self.client._perform_json("GET", "/api-deployer/deployments/%s/governance-status" % (self.deployment_id), params={ "version": version })
def get_settings(self):
"""
Gets the settings of this deployment. If you want to modify the settings, you need to
call :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentSettings.save` on the returned
object
:returns: a :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentSettings`
"""
settings = self.client._perform_json(
"GET", "/api-deployer/deployments/%s/settings" % (self.deployment_id))
return DSSAPIDeployerDeploymentSettings(self.client, self.deployment_id, settings)
def start_update(self):
"""
Starts an asynchronous update of this deployment to try to match the actual state to the current settings
:returns: a :class:`dataikuapi.dss.future.DSSFuture` tracking the progress of the update. Call
:meth:`~dataikuapi.dss.future.DSSFuture.wait_for_result` on the returned object
to wait for completion (or failure)
"""
future_response = self.client._perform_json(
"POST", "/api-deployer/deployments/%s/actions/update" % (self.deployment_id))
return DSSFuture(self.client, future_response.get('jobId', None), future_response)
def delete(self, disable_first=False, ignore_pre_delete_errors=False):
"""
Deletes this deployment. The disable_first flag automatically disables the deployment
before its deletion.
:param boolean disable_first: If True, automatically disables this deployment before deleting it.
If False, will raise an Exception if this deployment is enabled.
:param boolean ignore_pre_delete_errors: If True, any error occurred during the actions performed previously to
delete the deployment will be ignored and the delete action will be performed anyway.
"""
# Check if the deployment is disabled
is_enabled = self.get_status().light_status["deploymentBasicInfo"].get("enabled")
if is_enabled and not disable_first:
raise Exception("Deployment {} deletion failed: deployment must be disabled first.".format(self.deployment_id))
if is_enabled:
settings = self.get_settings()
settings.set_enabled(enabled=False)
settings.save()
self.client._perform_empty(
"DELETE", "/api-deployer/deployments/%s" % (self.deployment_id),
params = { "ignorePreDeleteErrors" : ignore_pre_delete_errors }
)
def get_open_api(self):
"""
Gets the OpenAPI document of this deployment if it's available or raise a 404 error.
:returns: a :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentOpenApi`
"""
open_api = self.client._perform_text("GET", "/api-deployer/deployments/%s/get-open-api" % (self.deployment_id))
return DSSAPIDeployerDeploymentOpenApi(open_api)
def run_test_queries(self, endpoint_id=None, test_queries=None):
"""
Runs test queries on a deployment and returns results as a dict
:param str endpoint_id: Mandatory if the deployment has multiple endpoints
:param list test_queries: Queries as str, formatted as [{"q": {"features": {"feat_1": "value", ...}}, {...}, ... ].
If left to None, the test queries of the current version of the service will be used.
:rtype: dict
Usage example
.. code-block:: python
import dataiku
client = dataiku.api_client()
deployer = client.get_apideployer()
deployment = deployer.get_deployment('service14');
test_queries = [{'q': {'features': {
'Pclass': '200',
'Sex': 'male',
'Age': '22',
'Embarked': 'S'
}}}]
# run existing test queries on deployement endpoint (if unique, else error)
test_queries_result = deployment.run_test_queries()
# run specified test queries on deployement "survived" endpoint
test_queries_result = deployment.run_test_queries(endpoint_id="survived", test_queries=test_queries)
# run existing test queries on deployement "survived" endpoint
test_queries_result = deployment.run_test_queries(endpoint_id="survived")
# run specified test queries on deployement endpoint (if unique, else error)
test_queries_result = deployment.run_test_queries(test_queries=test_queries)
"""
settings = {}
if endpoint_id is not None:
settings["endpointIdParam"] = endpoint_id
if test_queries is not None:
settings["testQueriesParam"] = json.dumps(test_queries)
return self.client._perform_json("POST", "/api-deployer/deployments/%s/actions/run-test-queries" % self.deployment_id, params=settings)
class DSSAPIDeployerDeploymentSettings(object):
"""
The settings of an API Deployer deployment.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_settings`
"""
def __init__(self, client, deployment_id, settings):
self.client = client
self.deployment_id = deployment_id
self.settings = settings
def get_raw(self):
"""
Gets the raw settings of this deployment. This returns a reference to the raw settings, not a copy,
so changes made to the returned object will be reflected when saving.
:rtype: dict
"""
return self.settings
def set_enabled(self, enabled):
"""
Enables or disables this deployment
:param bool enabled: True/False to Enable/Disable this deployment
"""
self.settings["enabled"] = enabled
def set_single_version(self, version):
"""
Sets this deployment to target a single version of the API service
:param str version: Identifier of the version to set
"""
self.settings["generationsMapping"] = {
"mode": "SINGLE_GENERATION",
"generation": version
}
def save(self, ignore_warnings=False):
"""
Saves back these settings to the deployment
:param boolean ignore_warnings: ignore warnings concerning the governance status of the model version(s) to deploy
"""
self.client._perform_empty(
"PUT", "/api-deployer/deployments/%s/settings" % (self.deployment_id),
params = { "ignoreWarnings" : ignore_warnings },
body = self.settings)
class DSSAPIDeployerDeploymentStatus(object):
"""
The status of an API Deployer deployment.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_status`
"""
def __init__(self, client, deployment_id, light_status, heavy_status):
self.client = client
self.deployment_id = deployment_id
self.light_status = light_status
self.heavy_status = heavy_status
def get_light(self):
"""
Gets the 'light' (summary) status. This returns a dictionary with various information about the deployment,
but not the actual health of the deployment
:rtype: dict
"""
return self.light_status
def get_heavy(self):
"""
Gets the 'heavy' (full) status. This returns a dictionary with various information about the deployment
:rtype: dict
"""
return self.heavy_status
def get_service_urls(self):
"""
Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)
:returns: a list of service-level URLs for this deployment
:rtype: list
"""
if "deployedServiceId" in self.light_status["deploymentBasicInfo"]:
service_id = self.light_status["deploymentBasicInfo"]["deployedServiceId"]
else:
service_id = self.light_status["deploymentBasicInfo"]["publishedServiceId"]
if "apiNodes" in self.heavy_status:
return ["%s/public/api/v1/%s" % (x["url"], service_id) for x in self.heavy_status["apiNodes"]]
elif "publicURL" in self.heavy_status:
return ["%s/public/api/v1/%s" % (self.heavy_status["publicURL"], service_id)]
else:
raise ValueError("PublicURL not available for this deployment. It might still be initializing")
def get_health(self):
"""
Returns the health of this deployment as a string
:returns: HEALTHY if the deployment is working properly, various other status otherwise
:rtype: string
"""
return self.heavy_status["health"]
def get_health_messages(self):
"""Returns messages about the health of this deployment"""
return self.heavy_status["healthMessages"]
class DSSAPIDeployerDeploymentOpenApi(object):
"""
The OpenAPI document of an API Deployer deployment.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_open_api`
"""
def __init__(self, open_api_doc_json):
self.open_api_doc_json = open_api_doc_json
def get(self):
"""
Gets the OpenAPI document as dict.
:rtype: dict
"""
return json.loads(self.open_api_doc_json)
def get_raw(self):
"""
Gets the OpenAPI document raw.
:rtype: string
"""
return self.open_api_doc_json
###############################################
# Published Service
###############################################
class DSSAPIDeployerService(object):
"""
An API service on the API Deployer
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_service`
"""
def __init__(self, client, service_id):
self.client = client
self.service_id = service_id
@property
def id(self):
return CallableStr(self.service_id)
def get_status(self):
"""
Returns status information about this service. This is used mostly to get information about
which versions are available and which deployments are exposing this service
:rtype: dataikuapi.dss.apideployer.DSSAPIDeployerServiceStatus
"""
light = self.client._perform_json("GET", "/api-deployer/services/%s" % (self.service_id))
return DSSAPIDeployerServiceStatus(self.client, self.service_id, light)
def import_version(self, fp):
"""
Imports a new version for an API service from a file-like object pointing
to a version package Zip file
:param string fp: A file-like object pointing to a version package Zip file
"""
return self.client._perform_empty("POST",
"/api-deployer/services/%s/versions" % (self.service_id), files={"file":fp})
def get_settings(self):
"""
Gets the settings of this service. If you want to modify the settings, you need to
call :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerServiceSettings.save` on the returned
object.
The main things that can be modified in a service settings are permissions
:returns: a :class:`dataikuapi.dss.apideployer.DSSAPIDeployerServiceSettings`
"""
settings = self.client._perform_json(
"GET", "/api-deployer/services/%s/settings" % (self.service_id))
return DSSAPIDeployerServiceSettings(self.client, self.service_id, settings)
def delete_version(self, version):
"""
Deletes a version from this service
:param string version: The version to delete
"""
self.client._perform_empty(
"DELETE", "/api-deployer/services/%s/versions/%s" % (self.service_id, version))
def get_version_stream(self, version_id):
"""
Download a version of a service as a stream.
The archive of this version can then be deployed in a DSS API Node.
.. warning::
This call will monopolize the DSSClient until the stream it returns is closed.
.. code-block:: python
with api_deployer_service.get_version_stream('v1') as fp:
# use fp
# or explicitly close the stream after use
fp = api_deployer_service.get_version_stream('v1')
# use fp, then close
fp.close()
:param string version_id: version (identifier) of the package to download
:return: the package archive, as an HTTP stream
:rtype: file-like
"""
return self.client._perform_raw(
"GET", "/api-deployer/services/%s/versions/%s" % (self.service_id, version_id))
def download_version_to_file(self, version_id, path):
"""
Download an archive of a version to a local file.
The archive can then be deployed in a DSS API Node.
:param string version_id: version (identifier) of the package to download
:param string path: absolute or relative path to a file in which the package is downloaded
"""
with self.get_version_stream(version_id) as version_stream:
with open(path, 'wb') as f:
for chunk in version_stream.iter_content(chunk_size=10000):
if chunk:
f.write(chunk)
f.flush()
def delete(self):
"""
Deletes this service
You may only delete a service if it has no deployments on it anymore.
"""
self.client._perform_empty(
"DELETE", "/api-deployer/services/%s" % (self.service_id))
class DSSAPIDeployerServiceSettings(object):
"""
The settings of an API Deployer Service.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_settings`
"""
def __init__(self, client, service_id, settings):
self.client = client
self.service_id = service_id
self.settings = settings
def get_raw(self):
"""
Gets the raw settings of this deployment. This returns a reference to the raw settings, not a copy,
so changes made to the returned object will be reflected when saving.
:rtype: dict
"""
return self.settings
def save(self):
"""
Saves back these settings to the API service
"""
self.client._perform_empty(
"PUT", "/api-deployer/services/%s/settings" % (self.service_id),
body = self.settings)
class DSSAPIDeployerServiceStatus(object):
"""
The status of an API Deployer Service.
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_status`
"""
def __init__(self, client, service_id, light_status):
self.client = client
self.service_id = service_id
self.light_status = light_status
def get_deployments(self, infra_id=None):
"""
Returns the deployments that have been created from this published project
:param str infra_id: Identifier of an infra, allows to only keep in the returned list the deployments on this infra.
If not set, the list contains all the deployments using this published project, across every infra of the Project Deployer.
:returns: a list of deployments
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
"""
if infra_id is None:
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment["infraId"]]
def get_versions(self):
"""
Returns the versions of this service that have been published on the API Service
Each version is a dict that contains at least a "id" field, which is the version identifier
:returns: a list of versions, each as a dict containing a "id" field
:rtype: list of dicts
"""
return self.light_status["packages"]
def get_raw(self):
"""
Gets the raw status information. This returns a dictionary with various information about the service,
:rtype: dict
"""
return self.light_status