Skip to content

Commit a52cf37

Browse files
authored
Merge PR #122 Project deployer enhancements
from task/dss90-update-pdpl-methods [ch59800]
2 parents f058695 + 105f078 commit a52cf37

File tree

4 files changed

+227
-48
lines changed

4 files changed

+227
-48
lines changed

dataikuapi/dss/apideployer.py

Lines changed: 91 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from .future import DSSFuture
3-
3+
from ..utils import CallableStr
44

55
class DSSAPIDeployer(object):
66
"""
@@ -60,7 +60,7 @@ def list_stages(self):
6060
"""
6161
Lists infrastructure stages of the API Deployer
6262
63-
:rtype: a list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description.
63+
:rtype: list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description.
6464
:rtype: list
6565
"""
6666
return self.client._perform_json("GET", "/api-deployer/stages")
@@ -152,16 +152,27 @@ def get_service(self, service_id):
152152

153153
class DSSAPIDeployerInfra(object):
154154
"""
155-
A Deployment infrastructure on the API Deployer
155+
An API Deployer infrastructure.
156156
157157
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_infra`
158158
"""
159159
def __init__(self, client, infra_id):
160160
self.client = client
161161
self.infra_id = infra_id
162162

163+
@property
163164
def id(self):
164-
return self.infra_id
165+
return CallableStr(self.infra_id)
166+
167+
def get_status(self):
168+
"""
169+
Returns status information about this infrastructure
170+
171+
:rtype: :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus`
172+
"""
173+
light = self.client._perform_json("GET", "/api-deployer/infras/%s" % (self.infra_id))
174+
175+
return DSSAPIDeployerInfraStatus(self.client, self.infra_id, light)
165176

166177
def get_settings(self):
167178
"""
@@ -186,7 +197,8 @@ def delete(self):
186197

187198

188199
class DSSAPIDeployerInfraSettings(object):
189-
"""The settings of an API Deployer Infra.
200+
"""
201+
The settings of an API Deployer infrastructure
190202
191203
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_settings`
192204
"""
@@ -238,6 +250,35 @@ def save(self):
238250
body = self.settings)
239251

240252

253+
class DSSAPIDeployerInfraStatus(object):
254+
"""
255+
The status of an API Deployer infrastructure.
256+
257+
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_status`
258+
"""
259+
def __init__(self, client, infra_id, light_status):
260+
self.client = client
261+
self.infra_id = infra_id
262+
self.light_status = light_status
263+
264+
def get_deployments(self):
265+
"""
266+
Returns the deployments that are deployed on this infrastructure
267+
268+
:returns: a list of deployments
269+
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
270+
"""
271+
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]
272+
273+
def get_raw(self):
274+
"""
275+
Gets the raw status information. This returns a dictionary with various information about the infrastructure
276+
277+
:rtype: dict
278+
"""
279+
return self.light_status
280+
281+
241282
###############################################
242283
# Deployments
243284
###############################################
@@ -252,11 +293,13 @@ def __init__(self, client, deployment_id):
252293
self.client = client
253294
self.deployment_id = deployment_id
254295

296+
@property
255297
def id(self):
256-
return self.deployment_id
298+
return CallableStr(self.deployment_id)
257299

258300
def get_status(self):
259-
"""Returns status information about this deployment
301+
"""
302+
Returns status information about this deployment
260303
261304
:rtype: dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus
262305
"""
@@ -302,7 +345,8 @@ def delete(self):
302345

303346

304347
class DSSAPIDeployerDeploymentSettings(object):
305-
"""The settings of an API Deployer deployment.
348+
"""
349+
The settings of an API Deployer deployment.
306350
307351
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_settings`
308352
"""
@@ -321,7 +365,9 @@ def get_raw(self):
321365
return self.settings
322366

323367
def set_enabled(self, enabled):
324-
"""Enables or disables this deployment"""
368+
"""
369+
Enables or disables this deployment
370+
"""
325371
self.settings["enabled"] = enabled
326372

327373
def set_single_version(self, version):
@@ -336,14 +382,17 @@ def set_single_version(self, version):
336382
}
337383

338384
def save(self):
339-
"""Saves back these settings to the deployment"""
385+
"""
386+
Saves back these settings to the deployment
387+
"""
340388
self.client._perform_empty(
341389
"PUT", "/api-deployer/deployments/%s/settings" % (self.deployment_id),
342390
body = self.settings)
343391

344392

345393
class DSSAPIDeployerDeploymentStatus(object):
346-
"""The status of an API Deployer deployment.
394+
"""
395+
The status of an API Deployer deployment.
347396
348397
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_status`
349398
"""
@@ -365,12 +414,15 @@ def get_light(self):
365414
def get_heavy(self):
366415
"""
367416
Gets the 'heavy' (full) status. This returns a dictionary with various information about the deployment
417+
368418
:rtype: dict
369419
"""
370420
return self.heavy_status
371421

372422
def get_service_urls(self):
373-
"""Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)"""
423+
"""
424+
Returns service-level URLs for this deployment (ie without the enpdoint-specific suffix)
425+
"""
374426

375427
if "deployedServiceId" in self.light_status["deploymentBasicInfo"]:
376428
service_id = self.light_status["deploymentBasicInfo"]["deployedServiceId"]
@@ -385,7 +437,8 @@ def get_service_urls(self):
385437
raise ValueError("PublicURL not available for this deployment. It might still be initializing")
386438

387439
def get_health(self):
388-
"""Returns the health of this deployment as a string
440+
"""
441+
Returns the health of this deployment as a string
389442
390443
:returns: HEALTHY if the deployment is working properly, various other status otherwise
391444
:rtype: string
@@ -411,8 +464,9 @@ def __init__(self, client, service_id):
411464
self.client = client
412465
self.service_id = service_id
413466

467+
@property
414468
def id(self):
415-
return self.service_id
469+
return CallableStr(self.service_id)
416470

417471
def get_status(self):
418472
"""
@@ -452,6 +506,7 @@ def get_settings(self):
452506
def delete_version(self, version):
453507
"""
454508
Deletes a version from this service
509+
455510
:param string version: The version to delete
456511
"""
457512
self.client._perform_empty(
@@ -468,7 +523,8 @@ def delete(self):
468523

469524

470525
class DSSAPIDeployerServiceSettings(object):
471-
"""The settings of an API Deployer Service.
526+
"""
527+
The settings of an API Deployer Service.
472528
473529
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_settings`
474530
"""
@@ -487,14 +543,17 @@ def get_raw(self):
487543
return self.settings
488544

489545
def save(self):
490-
"""Saves back these settings to the API service"""
546+
"""
547+
Saves back these settings to the API service
548+
"""
491549
self.client._perform_empty(
492550
"PUT", "/api-deployer/services/%s/settings" % (self.service_id),
493551
body = self.settings)
494552

495553

496554
class DSSAPIDeployerServiceStatus(object):
497-
"""The status of an API Deployer Service.
555+
"""
556+
The status of an API Deployer Service.
498557
499558
Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_status`
500559
"""
@@ -503,6 +562,20 @@ def __init__(self, client, service_id, light_status):
503562
self.service_id = service_id
504563
self.light_status = light_status
505564

565+
def get_deployments(self, infra_id=None):
566+
"""
567+
Returns the deployments that have been created from this published project
568+
569+
:param str infra_id: Identifier of an infra, allows to only keep in the returned list the deployments on this infra.
570+
If not set, the list contains all the deployments using this published project, across every infra of the Project Deployer.
571+
572+
:returns: a list of deployments
573+
:rtype: list of :class:`dataikuapi.dss.apideployer.DSSAPIDeployerDeployment`
574+
"""
575+
if infra_id is None:
576+
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]]
577+
return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment["infraId"]]
578+
506579
def get_versions(self):
507580
"""
508581
Returns the versions of this service that have been published on the API Service
@@ -517,6 +590,7 @@ def get_versions(self):
517590
def get_raw(self):
518591
"""
519592
Gets the raw status information. This returns a dictionary with various information about the service,
593+
520594
:rtype: dict
521595
"""
522596
return self.light_status

dataikuapi/dss/project.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ def get_api_service(self, service_id):
987987
return DSSAPIService(self.client, self.project_key, service_id)
988988

989989
########################################################
990-
# Bundles / Export (Design node)
990+
# Bundles / Export and Publish (Design node)
991991
########################################################
992992

993993
def list_exported_bundles(self):
@@ -1009,7 +1009,8 @@ def get_exported_bundle_archive_stream(self, bundle_id):
10091009
def download_exported_bundle_archive_to_file(self, bundle_id, path):
10101010
"""
10111011
Download a bundle archive that can be deployed in a DSS automation Node into the given output file.
1012-
@param path if "-", will write to /dev/stdout
1012+
1013+
:param path if "-", will write to /dev/stdout
10131014
"""
10141015
if path == "-":
10151016
path= "/dev/stdout"
@@ -1022,6 +1023,23 @@ def download_exported_bundle_archive_to_file(self, bundle_id, path):
10221023
f.flush()
10231024
stream.close()
10241025

1026+
def publish_bundle(self, bundle_id, published_project_key=None):
1027+
"""
1028+
Publish a bundle on the Project Deployer.
1029+
1030+
:param string bundle_id: The identifier of the bundle
1031+
:param string published_project_key: The key of the project on the Project Deployer where the bundle will be published.
1032+
A new published project will be created if none matches the key.
1033+
If the parameter is not set, the key from the current :class:`DSSProject` is used.
1034+
1035+
:rtype: dict
1036+
:return: a dict with info on the bundle state once published. It contains the keys "publishedOn" for the publish date,
1037+
"publishedBy" for the user who published the bundle, and "publishedProjectKey" for the key of the Project Deployer project used.
1038+
"""
1039+
params = None
1040+
if published_project_key is not None:
1041+
params = {"publishedProjectKey": published_project_key}
1042+
return self.client._perform_json("GET", "/projects/%s/bundles/%s/publish" % (self.project_key, bundle_id), params=params)
10251043

10261044
########################################################
10271045
# Bundles / Import (Automation node)

0 commit comments

Comments
 (0)