11import json
22from .future import DSSFuture
3-
3+ from .. utils import CallableStr
44
55class 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
153153class 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
188199class 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
304347class 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
345393class 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
470525class 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
496554class 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
0 commit comments