Skip to content

Project deployer: update some PDPL methods #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 18, 2021
43 changes: 41 additions & 2 deletions dataikuapi/dss/apideployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
"""
Expand All @@ -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
Expand All @@ -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`
"""
Expand Down Expand Up @@ -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
###############################################
Expand Down
14 changes: 13 additions & 1 deletion dataikuapi/dss/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
119 changes: 96 additions & 23 deletions dataikuapi/dss/projectdeployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -160,7 +177,7 @@ def get_project(self, project_key):

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`
"""
Expand All @@ -171,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
Expand All @@ -194,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`
"""
Expand All @@ -219,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
###############################################
Expand Down Expand Up @@ -302,8 +357,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)
Expand Down Expand Up @@ -375,24 +450,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
Expand Down Expand Up @@ -425,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.

Expand Down Expand Up @@ -452,7 +510,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`
"""
Expand All @@ -461,6 +520,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
Expand All @@ -477,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
return self.light_status