From 056cd0f6530d2d3aba24305157da05373ebd9d11 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Thu, 11 Feb 2021 11:51:41 +0100 Subject: [PATCH 01/13] Update import_bundle call Rename Adapt to new Public API implem Move inside DSSProjectDeployer --- dataikuapi/dss/projectdeployer.py | 35 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index ee8919c0..7c2b3a7b 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -152,6 +152,23 @@ def get_project(self, project_key): """ return DSSProjectDeployerProject(self.client, project_key) + def upload_bundle(self, fp, project_key=None): + """ + Uploads a new version for a project from a file-like object pointing + to a bundle Zip file. + :param string fp: A file-like object pointing to a bundle Zip file + :param string project_key: The key of the published project where the bundle will be uploaded. If the project does not exist, it is created. + If not set, the key of the bundle's source project is used. + + """ + if project_key is None: + params = None + else: + params = { + "projectKey": project_key, + } + return self.client._perform_empty("POST", + "/project-deployer/projects/bundles", params=params, files={"file":fp}) ############################################### # Infrastructures @@ -375,24 +392,6 @@ def get_status(self): light = self.client._perform_json("GET", "/project-deployer/projects/%s" % (self.project_key)) return DSSProjectDeployerProjectStatus(self.client, self.project_key, light) - def import_bundle(self, fp, design_node_url=None, design_node_id=None): - """ - Imports a new version for a project from a file-like object pointing - to a bundle Zip file. - :param string fp: A file-like object pointing to a bundle Zip file - :param string design_node_url: The URL of the Design node where the bundle was created - :param design_node_id: The identifier of the Design node where the bundle was created - """ - if design_node_url is None and design_node_id is None: - params = None - else: - params = { - "designNodeId": design_node_id, - "designNodeUrl": design_node_url - } - return self.client._perform_empty("POST", - "/project-deployer/projects/%s/bundles" % (self.project_key), params=params, files={"file":fp}) - def get_settings(self): """ Gets the settings of this project. If you want to modify the settings, you need to From 1c916e5e1b7339d2e4ac1c32d4b593e2e6047f3b Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Thu, 11 Feb 2021 14:01:16 +0100 Subject: [PATCH 02/13] Add helper methods to set/get bundle id --- dataikuapi/dss/projectdeployer.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 7c2b3a7b..7cad753a 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -319,8 +319,28 @@ def get_raw(self): """ return self.settings + def get_bundle_id(self): + """ + Gets the bundle id currently used by this deployment. + + :rtype: str + """ + return self.settings["bundleId"] + + def set_bundle_id(self, new_bundle_id): + """ + Sets a new bundle id for this deployment. You need to call :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployerDeployment.get_settings` + afterwards for the change to be effective. + + :param str new_bundle_id: Identifier of the bundle to be set + """ + self.settings["bundleId"] = new_bundle_id + + def save(self): - """Saves back these settings to the deployment""" + """ + Saves back these settings to the deployment + """ self.client._perform_empty( "PUT", "/project-deployer/deployments/%s/settings" % (self.deployment_id), body = self.settings) From 04907d5c0592c50bd5c6bd4bff88bc2aa33187f9 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Thu, 11 Feb 2021 14:20:12 +0100 Subject: [PATCH 03/13] Add a DSSProjectDeployerProjectStatus#list_deployments method --- dataikuapi/dss/projectdeployer.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 7cad753a..d840f5d9 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -471,7 +471,8 @@ def save(self): class DSSProjectDeployerProjectStatus(object): - """The status of a published project. + """ + The status of a published project. Do not create this directly, use :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployerProject.get_status` """ @@ -480,6 +481,20 @@ def __init__(self, client, project_key, light_status): self.project_key = project_key self.light_status = light_status + def list_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.projectdeployer.DSSProjectDeployerDeployment` + """ + if infra_id is None: + return [DSSProjectDeployerDeployment(self.client, deployment.id) for deployment in self.light_status["deployments"]] + return [DSSProjectDeployerDeployment(self.client, deployment.id) for deployment in self.light_status["deployments"] if infra_id == deployment.infraId] + def get_bundles(self): """ Returns the bundles that have been published on this project From 336cc0ccbd9b428ae7b4e321e97a231c7dbb792e Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Thu, 11 Feb 2021 20:20:16 +0100 Subject: [PATCH 04/13] Add infra status wrapper class --- dataikuapi/dss/apideployer.py | 43 +++++++++++++++++++++++++++-- dataikuapi/dss/projectdeployer.py | 45 ++++++++++++++++++++++++++++--- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/dataikuapi/dss/apideployer.py b/dataikuapi/dss/apideployer.py index 339ae2bf..4a31b433 100644 --- a/dataikuapi/dss/apideployer.py +++ b/dataikuapi/dss/apideployer.py @@ -152,7 +152,7 @@ def get_service(self, service_id): class DSSAPIDeployerInfra(object): """ - A Deployment infrastructure on the API Deployer + An API Deployer infrastructure. Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployer.get_infra` """ @@ -163,6 +163,16 @@ def __init__(self, client, infra_id): def id(self): return self.infra_id + def get_status(self): + """ + Returns status information about this infrastructure + + :rtype: a :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 @@ -186,7 +196,8 @@ def delete(self): class DSSAPIDeployerInfraSettings(object): - """The settings of an API Deployer Infra. + """ + The settings of an API Deployer infrastructure Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerInfra.get_settings` """ @@ -238,6 +249,34 @@ def save(self): 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 list_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 ############################################### diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index d840f5d9..49cc3f5a 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -177,7 +177,7 @@ def upload_bundle(self, fp, project_key=None): class DSSProjectDeployerInfra(object): """ - A Deployment infrastructure on the Project Deployer + An Automation infrastructure on the Project Deployer Do not create this directly, use :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployer.get_infra` """ @@ -188,6 +188,16 @@ def __init__(self, client, infra_id): def id(self): return self.infra_id + def get_status(self): + """ + Returns status information about this infrastructure + + :rtype: a :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerInfraStatus` + """ + light = self.client._perform_json("GET", "/project-deployer/infras/%s" % (self.infra_id)) + + return DSSProjectDeployerInfraStatus(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 @@ -211,7 +221,8 @@ def delete(self): class DSSProjectDeployerInfraSettings(object): - """The settings of a Project Deployer Infra. + """ + The settings of an Automation infrastructure. Do not create this directly, use :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployerInfra.get_settings` """ @@ -236,6 +247,33 @@ def save(self): body = self.settings) +class DSSProjectDeployerInfraStatus(object): + """ + The status of an Automation infrastructure. + + Do not create this directly, use :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployerInfra.get_status` + """ + def __init__(self, client, infra_id, light_status): + self.client = client + self.infra_id = infra_id + self.light_status = light_status + + def list_deployments(self): + """ + Returns the deployments that are deployed on this infrastructure + + :returns: a list of deployments + :rtype: list of :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerDeployment` + """ + return [DSSProjectDeployerDeployment(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 ############################################### @@ -444,6 +482,7 @@ def delete(self): return self.client._perform_empty( "DELETE", "/project-deployer/projects/%s" % (self.project_key)) + class DSSProjectDeployerProjectSettings(object): """The settings of a published project. @@ -511,4 +550,4 @@ def get_raw(self): Gets the raw status information. This returns a dictionary with various information about the project :rtype: dict """ - return self.light_status \ No newline at end of file + return self.light_status From 89f4e8d01e0e0980c40b616af546bd47d4650b64 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Thu, 11 Feb 2021 20:24:19 +0100 Subject: [PATCH 05/13] Add a DSSProject#publish_bundle method --- dataikuapi/dss/project.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/dataikuapi/dss/project.py b/dataikuapi/dss/project.py index 6557e8b6..31fe7827 100644 --- a/dataikuapi/dss/project.py +++ b/dataikuapi/dss/project.py @@ -936,7 +936,7 @@ def get_api_service(self, service_id): return DSSAPIService(self.client, self.project_key, service_id) ######################################################## - # Bundles / Export (Design node) + # Bundles / Export and Publish (Design node) ######################################################## def list_exported_bundles(self): @@ -971,6 +971,18 @@ def download_exported_bundle_archive_to_file(self, bundle_id, path): f.flush() stream.close() + def publish_bundle(self, bundle_id, published_project_key=None): + """ + Publish a bundle on the Project Deployer. + :param string bundle_id: The identifier of the bundle + :param string published_project_key: The key of the project on the Project Deployer where the bundle will be published. + A new published project will be created if none matches the key. + If the parameter is not set, the key from the current :class:`DSSProject` is used. + """ + params = None + if published_project_key is not None: + params = {"publishedProjectKey": published_project_key} + return self.client._perform_json("GET", "/projects/%s/bundles/%s/publish" % (self.project_key, bundle_id), params=params) ######################################################## # Bundles / Import (Automation node) From 0ff6efc4960a656d2a8553a810e41e882f57c718 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Fri, 12 Feb 2021 12:05:01 +0100 Subject: [PATCH 06/13] Retrieve id properly --- dataikuapi/dss/apideployer.py | 2 +- dataikuapi/dss/projectdeployer.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dataikuapi/dss/apideployer.py b/dataikuapi/dss/apideployer.py index 4a31b433..b1474df1 100644 --- a/dataikuapi/dss/apideployer.py +++ b/dataikuapi/dss/apideployer.py @@ -267,7 +267,7 @@ def list_deployments(self): :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"]] + return [DSSAPIDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]] def get_raw(self): """ diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 49cc3f5a..040e34bc 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -265,7 +265,7 @@ def list_deployments(self): :returns: a list of deployments :rtype: list of :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerDeployment` """ - return [DSSProjectDeployerDeployment(self.client, deployment.id) for deployment in self.light_status["deployments"]] + return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]] def get_raw(self): """ @@ -531,8 +531,8 @@ def list_deployments(self, infra_id=None): :rtype: list of :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerDeployment` """ if infra_id is None: - return [DSSProjectDeployerDeployment(self.client, deployment.id) for deployment in self.light_status["deployments"]] - return [DSSProjectDeployerDeployment(self.client, deployment.id) for deployment in self.light_status["deployments"] if infra_id == deployment.infraId] + return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]] + return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment.infraId] def get_bundles(self): """ From 7af06bac83d0eea3db6f1a6536546c202c607576 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Fri, 12 Feb 2021 14:40:37 +0100 Subject: [PATCH 07/13] Retrieve ALL the ids properly :facepalm: --- dataikuapi/dss/projectdeployer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 040e34bc..e28f2c10 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -532,7 +532,7 @@ def list_deployments(self, infra_id=None): """ if infra_id is None: return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"]] - return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment.infraId] + return [DSSProjectDeployerDeployment(self.client, deployment["id"]) for deployment in self.light_status["deployments"] if infra_id == deployment["infraId"]] def get_bundles(self): """ From 067f3eb6683c524a8d4f5861ec9424d04130327d Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 12:01:15 +0100 Subject: [PATCH 08/13] Use properties for ids iinstead of methods --- dataikuapi/dss/projectdeployer.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index e28f2c10..3c816326 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -185,6 +185,7 @@ def __init__(self, client, infra_id): self.client = client self.infra_id = infra_id + @property def id(self): return self.infra_id @@ -289,6 +290,7 @@ def __init__(self, client, deployment_id): self.client = client self.deployment_id = deployment_id + @property def id(self): return self.deployment_id @@ -357,7 +359,8 @@ def get_raw(self): """ return self.settings - def get_bundle_id(self): + @property + def bundle_id(self): """ Gets the bundle id currently used by this deployment. @@ -365,16 +368,6 @@ def get_bundle_id(self): """ return self.settings["bundleId"] - def set_bundle_id(self, new_bundle_id): - """ - Sets a new bundle id for this deployment. You need to call :meth:`~dataikuapi.dss.projectdeployer.DSSProjectDeployerDeployment.get_settings` - afterwards for the change to be effective. - - :param str new_bundle_id: Identifier of the bundle to be set - """ - self.settings["bundleId"] = new_bundle_id - - def save(self): """ Saves back these settings to the deployment @@ -437,6 +430,7 @@ def __init__(self, client, project_key): self.client = client self.project_key = project_key + @property def id(self): return self.project_key From 7bb05843fc52dd8bb3b2f0304765ae6f8fdc0325 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 12:32:47 +0100 Subject: [PATCH 09/13] Miinor python doc fixes/improvements --- dataikuapi/dss/apideployer.py | 42 ++++++++++++++++++++++--------- dataikuapi/dss/project.py | 4 ++- dataikuapi/dss/projectdeployer.py | 27 ++++++++++++++------ 3 files changed, 53 insertions(+), 20 deletions(-) diff --git a/dataikuapi/dss/apideployer.py b/dataikuapi/dss/apideployer.py index b1474df1..92384660 100644 --- a/dataikuapi/dss/apideployer.py +++ b/dataikuapi/dss/apideployer.py @@ -60,7 +60,7 @@ def list_stages(self): """ Lists infrastructure stages of the API Deployer - :rtype: a list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description. + :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") @@ -167,7 +167,7 @@ def get_status(self): """ Returns status information about this infrastructure - :rtype: a :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus` + :rtype: :class:`dataikuapi.dss.apideployer.DSSAPIDeployerInfraStatus` """ light = self.client._perform_json("GET", "/api-deployer/infras/%s" % (self.infra_id)) @@ -272,6 +272,7 @@ def list_deployments(self): 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 @@ -295,7 +296,8 @@ def id(self): return self.deployment_id def get_status(self): - """Returns status information about this deployment + """ + Returns status information about this deployment :rtype: dataikuapi.dss.apideployer.DSSAPIDeployerDeploymentStatus """ @@ -341,7 +343,8 @@ def delete(self): class DSSAPIDeployerDeploymentSettings(object): - """The settings of an API Deployer deployment. + """ + The settings of an API Deployer deployment. Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_settings` """ @@ -360,7 +363,9 @@ def get_raw(self): return self.settings def set_enabled(self, enabled): - """Enables or disables this deployment""" + """ + Enables or disables this deployment + """ self.settings["enabled"] = enabled def set_single_version(self, version): @@ -375,14 +380,17 @@ def set_single_version(self, version): } def save(self): - """Saves back these settings to the deployment""" + """ + Saves back these settings to the deployment + """ self.client._perform_empty( "PUT", "/api-deployer/deployments/%s/settings" % (self.deployment_id), body = self.settings) class DSSAPIDeployerDeploymentStatus(object): - """The status of an API Deployer deployment. + """ + The status of an API Deployer deployment. Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerDeployment.get_status` """ @@ -404,12 +412,15 @@ def get_light(self): 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 service-level URLs for this deployment (ie without the enpdoint-specific suffix) + """ if "deployedServiceId" in self.light_status["deploymentBasicInfo"]: service_id = self.light_status["deploymentBasicInfo"]["deployedServiceId"] @@ -424,7 +435,8 @@ def get_service_urls(self): 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 the health of this deployment as a string :returns: HEALTHY if the deployment is working properly, various other status otherwise :rtype: string @@ -491,6 +503,7 @@ def get_settings(self): def delete_version(self, version): """ Deletes a version from this service + :param string version: The version to delete """ self.client._perform_empty( @@ -507,7 +520,8 @@ def delete(self): class DSSAPIDeployerServiceSettings(object): - """The settings of an API Deployer Service. + """ + The settings of an API Deployer Service. Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_settings` """ @@ -526,14 +540,17 @@ def get_raw(self): return self.settings def save(self): - """Saves back these settings to the API service""" + """ + 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. + """ + The status of an API Deployer Service. Do not create this directly, use :meth:`~dataikuapi.dss.apideployer.DSSAPIDeployerService.get_status` """ @@ -556,6 +573,7 @@ def get_versions(self): 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 diff --git a/dataikuapi/dss/project.py b/dataikuapi/dss/project.py index 31fe7827..0ac4d46a 100644 --- a/dataikuapi/dss/project.py +++ b/dataikuapi/dss/project.py @@ -958,7 +958,8 @@ def get_exported_bundle_archive_stream(self, bundle_id): def download_exported_bundle_archive_to_file(self, bundle_id, path): """ Download a bundle archive that can be deployed in a DSS automation Node into the given output file. - @param path if "-", will write to /dev/stdout + + :param path if "-", will write to /dev/stdout """ if path == "-": path= "/dev/stdout" @@ -974,6 +975,7 @@ def download_exported_bundle_archive_to_file(self, bundle_id, path): def publish_bundle(self, bundle_id, published_project_key=None): """ Publish a bundle on the Project Deployer. + :param string bundle_id: The identifier of the bundle :param string published_project_key: The key of the project on the Project Deployer where the bundle will be published. A new published project will be created if none matches the key. diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 3c816326..06560005 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -69,7 +69,7 @@ def list_stages(self): """ Lists infrastructure stages of the Project Deployer - :rtype: a list of dict. Each dict contains a field "id" for the stage identifier and "desc" for its description. + :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", "/project-deployer/stages") @@ -156,6 +156,7 @@ def upload_bundle(self, fp, project_key=None): """ Uploads a new version for a project from a file-like object pointing to a bundle Zip file. + :param string fp: A file-like object pointing to a bundle Zip file :param string project_key: The key of the published project where the bundle will be uploaded. If the project does not exist, it is created. If not set, the key of the bundle's source project is used. @@ -193,7 +194,7 @@ def get_status(self): """ Returns status information about this infrastructure - :rtype: a :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerInfraStatus` + :rtype: :class:`dataikuapi.dss.projectdeployer.DSSProjectDeployerInfraStatus` """ light = self.client._perform_json("GET", "/project-deployer/infras/%s" % (self.infra_id)) @@ -242,7 +243,9 @@ def get_raw(self): return self.settings def save(self): - """Saves back these settings to the infra""" + """ + Saves back these settings to the infra + """ self.client._perform_empty( "PUT", "/project-deployer/infras/%s/settings" % (self.infra_id), body = self.settings) @@ -271,6 +274,7 @@ def list_deployments(self): 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 @@ -295,7 +299,8 @@ def id(self): return self.deployment_id def get_status(self): - """Returns status information about this deployment + """ + Returns status information about this deployment :rtype: dataikuapi.dss.apideployer.DSSProjectDeployerDeploymentStatus """ @@ -400,12 +405,14 @@ def get_light(self): 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_health(self): - """Returns the health of this deployment as a string + """ + Returns the health of this deployment as a string :returns: HEALTHY if the deployment is working properly, various other status otherwise :rtype: string @@ -413,7 +420,9 @@ def get_health(self): return self.heavy_status["health"] def get_health_messages(self): - """Returns messages about the health of this deployment""" + """ + Returns messages about the health of this deployment + """ return self.heavy_status["healthMessages"] ############################################### @@ -462,6 +471,7 @@ def get_settings(self): def delete_bundle(self, bundle_id): """ Deletes a bundle from this project + :param string bundle_id: The identifier of the bundle to delete """ self.client._perform_empty( @@ -497,7 +507,9 @@ def get_raw(self): return self.settings def save(self): - """Saves back these settings to the project""" + """ + Saves back these settings to the project + """ self.client._perform_empty( "PUT", "/project-deployer/projects/%s/settings" % (self.project_key), body = self.settings) @@ -542,6 +554,7 @@ def get_bundles(self): def get_raw(self): """ Gets the raw status information. This returns a dictionary with various information about the project + :rtype: dict """ return self.light_status From a4e34e4854b7e0413818d7ee0b949188a340758d Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 13:48:14 +0100 Subject: [PATCH 10/13] Rename list_deployments --> get_deployments Add DSSAPIDeployerServiceStatus#get_deployments --- dataikuapi/dss/apideployer.py | 16 +++++++++++++++- dataikuapi/dss/projectdeployer.py | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dataikuapi/dss/apideployer.py b/dataikuapi/dss/apideployer.py index 92384660..41a9804e 100644 --- a/dataikuapi/dss/apideployer.py +++ b/dataikuapi/dss/apideployer.py @@ -260,7 +260,7 @@ def __init__(self, client, infra_id, light_status): self.infra_id = infra_id self.light_status = light_status - def list_deployments(self): + def get_deployments(self): """ Returns the deployments that are deployed on this infrastructure @@ -559,6 +559,20 @@ def __init__(self, client, service_id, light_status): 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 diff --git a/dataikuapi/dss/projectdeployer.py b/dataikuapi/dss/projectdeployer.py index 06560005..6ca50917 100644 --- a/dataikuapi/dss/projectdeployer.py +++ b/dataikuapi/dss/projectdeployer.py @@ -262,7 +262,7 @@ def __init__(self, client, infra_id, light_status): self.infra_id = infra_id self.light_status = light_status - def list_deployments(self): + def get_deployments(self): """ Returns the deployments that are deployed on this infrastructure @@ -526,7 +526,7 @@ def __init__(self, client, project_key, light_status): self.project_key = project_key self.light_status = light_status - def list_deployments(self, infra_id=None): + def get_deployments(self, infra_id=None): """ Returns the deployments that have been created from this published project From 54a1eb57aab24c2d6d0fc20493db577fa81c6d64 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 13:57:06 +0100 Subject: [PATCH 11/13] Use properties for id Add utils#CallableStr for backward compatibility --- dataikuapi/dss/apideployer.py | 11 +++++++---- dataikuapi/utils.py | 7 +++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dataikuapi/dss/apideployer.py b/dataikuapi/dss/apideployer.py index 41a9804e..5f96c7b7 100644 --- a/dataikuapi/dss/apideployer.py +++ b/dataikuapi/dss/apideployer.py @@ -1,6 +1,6 @@ import json from .future import DSSFuture - +from ..utils import CallableStr class DSSAPIDeployer(object): """ @@ -160,8 +160,9 @@ def __init__(self, client, infra_id): self.client = client self.infra_id = infra_id + @property def id(self): - return self.infra_id + return CallableStr(self.infra_id) def get_status(self): """ @@ -292,8 +293,9 @@ def __init__(self, client, deployment_id): self.client = client self.deployment_id = deployment_id + @property def id(self): - return self.deployment_id + return CallableStr(self.deployment_id) def get_status(self): """ @@ -462,8 +464,9 @@ def __init__(self, client, service_id): self.client = client self.service_id = service_id + @property def id(self): - return self.service_id + return CallableStr(self.service_id) def get_status(self): """ diff --git a/dataikuapi/utils.py b/dataikuapi/utils.py index 74f15380..e4512acc 100644 --- a/dataikuapi/utils.py +++ b/dataikuapi/utils.py @@ -94,3 +94,10 @@ def str_to_bool(s): doublequote=True): yield [none_if_throws(caster)(val) for (caster, val) in dku_zip_longest(casters, uncasted_tuple)] + +class CallableStr(str): + def __init__(self, val): + self.val = val + + def __call__(self): + return self.val From 8b4fe3041b5b2cc3344b8616da05fa3fe4a114c9 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 14:02:18 +0100 Subject: [PATCH 12/13] Add description of returned dict by publish_bundle --- dataikuapi/dss/project.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dataikuapi/dss/project.py b/dataikuapi/dss/project.py index 0ac4d46a..5e90d46d 100644 --- a/dataikuapi/dss/project.py +++ b/dataikuapi/dss/project.py @@ -980,6 +980,10 @@ def publish_bundle(self, bundle_id, published_project_key=None): :param string published_project_key: The key of the project on the Project Deployer where the bundle will be published. A new published project will be created if none matches the key. If the parameter is not set, the key from the current :class:`DSSProject` is used. + + :rtype: dict + :return: a dict with info on the bundle state once published. It contains the keys "publishedOn" for the date on which the publication was done, + "publishedBy" for the user whom performed it, "publishedProjectKey" for the key of the Project Deployer project used. """ params = None if published_project_key is not None: From 105f078bb796504692ad2cf63d6a22482a822733 Mon Sep 17 00:00:00 2001 From: Agathe Guillemot Date: Tue, 16 Feb 2021 14:43:05 +0100 Subject: [PATCH 13/13] Better wording --- dataikuapi/dss/project.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dataikuapi/dss/project.py b/dataikuapi/dss/project.py index 5e90d46d..4831936d 100644 --- a/dataikuapi/dss/project.py +++ b/dataikuapi/dss/project.py @@ -982,8 +982,8 @@ def publish_bundle(self, bundle_id, published_project_key=None): If the parameter is not set, the key from the current :class:`DSSProject` is used. :rtype: dict - :return: a dict with info on the bundle state once published. It contains the keys "publishedOn" for the date on which the publication was done, - "publishedBy" for the user whom performed it, "publishedProjectKey" for the key of the Project Deployer project used. + :return: a dict with info on the bundle state once published. It contains the keys "publishedOn" for the publish date, + "publishedBy" for the user who published the bundle, and "publishedProjectKey" for the key of the Project Deployer project used. """ params = None if published_project_key is not None: