Skip to content

Commit de101a2

Browse files
committed
WIP
1 parent dc5e5dd commit de101a2

File tree

4 files changed

+204
-2
lines changed

4 files changed

+204
-2
lines changed

dataikuapi/dss/admin.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .future import DSSFuture
22
import json, warnings
3+
from datetime import datetime
34

45
class DSSConnectionInfo(dict):
56
"""A class holding read-only information about a connection.
@@ -1271,3 +1272,80 @@ def total_scenarios_count(self):
12711272
@property
12721273
def total_active_with_trigger_scenarios_count(self):
12731274
return self.data["scenarios"]["activeWithTriggers"]
1275+
1276+
1277+
class DSSKubikleTemplateListItem(object):
1278+
"""An item in a list of datasets. Do not instantiate this class, use :meth:`dataikuapi.dss.project.DSSProject.list_datasets`"""
1279+
def __init__(self, client, data):
1280+
self.client = client
1281+
self._data = data
1282+
1283+
def to_kubikle_template(self):
1284+
"""Gets the :class:`DSSKubikleTemplate` corresponding to this kubikle template """
1285+
return DSSKubikleTemplate(self.client, self._data["id"])
1286+
1287+
@property
1288+
def name(self):
1289+
return self._data["name"]
1290+
@property
1291+
def id(self):
1292+
return self._data["id"]
1293+
@property
1294+
def type(self):
1295+
return self._data["type"]
1296+
@property
1297+
def type_label(self):
1298+
return self._data.get("desc", {}).get("label", self._data["type"])
1299+
@property
1300+
def type_description(self):
1301+
return self._data.get("desc", {}).get("description", self._data["type"])
1302+
@property
1303+
def build_for_configs(self):
1304+
return self._data.get("buildFor", [])
1305+
@property
1306+
def last_built(self):
1307+
ts = self._data.get("lastBuilt", 0)
1308+
if ts > 0:
1309+
return datetime.fromtimestamp(ts / 1000)
1310+
else:
1311+
return None
1312+
1313+
class DSSKubikleTemplate(object):
1314+
"""
1315+
A handle to interact with a kubikle template on the DSS instance
1316+
"""
1317+
def __init__(self, client, template_id):
1318+
"""Do not call that directly, use :meth:`dataikuapi.DSSClient.get_kubikle_template`"""
1319+
self.client = client
1320+
self.template_id = template_id
1321+
1322+
########################################################
1323+
# Template description
1324+
########################################################
1325+
1326+
def get_settings(self):
1327+
"""
1328+
Get the template's settings.
1329+
1330+
:returns: a :class:`DSSKubikleTemplateSettings` object to interact with kubikle template settings
1331+
:rtype: :class:`DSSKubikleTemplateSettings`
1332+
"""
1333+
settings = self.client._perform_json("GET", "/admin/kubikles/%s" % (self.template_id))
1334+
return DSSKubikleTemplateSettings(self.client, self.template_id, settings)
1335+
1336+
class DSSKubikleTemplateSettings(object):
1337+
"""
1338+
The settings of a kubikle template
1339+
"""
1340+
def __init__(self, client, template_id, settings):
1341+
"""Do not call directly, use :meth:`DSSKubikleTemplate.get_settings`"""
1342+
self.client = client
1343+
self.template_id = template_id
1344+
self.settings = settings
1345+
1346+
def get_raw(self):
1347+
"""
1348+
Gets all settings as a raw dictionary. This returns a reference to the raw settings, not a copy,
1349+
"""
1350+
return self.settings
1351+

dataikuapi/dss/kubikle.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from ..utils import DataikuException
2+
import json
3+
4+
class DSSKubikleObject(object):
5+
"""
6+
A handle to manage a kubikle object of a project
7+
"""
8+
def __init__(self, client, project_key, kubikle_object_id):
9+
"""Do not call directly, use :meth:`dataikuapi.dss.project.DSSProject.get_kubikle_object`"""
10+
self.client = client
11+
self.project_key = project_key
12+
self.kubikle_object_id = kubikle_object_id
13+
14+
def get_settings(self):
15+
"""
16+
Get the kubikle object's settings
17+
18+
:returns: a handle to manage the wiki settings (taxonomy, home article)
19+
:rtype: :class:`dataikuapi.dss.kubikle.DSSKubikleObjectSettings`
20+
"""
21+
settings = self.client._perform_json("GET", "/projects/%s/kubikles/%s" % (self.project_key, self.kubikle_object_id))
22+
return DSSKubikleObjectSettings(self.client, self.project_key, self.kubikle_object_id, settings)
23+
24+
25+
class DSSKubikleObjectSettings(object):
26+
"""
27+
Settings for the kubikle object
28+
"""
29+
def __init__(self, client, project_key, kubikle_object_id, settings):
30+
"""Do not call directly, use :meth:`dataikuapi.dss.kubikle.DSSKubikleObject.get_settings`"""
31+
self.client = client
32+
self.project_key = project_key
33+
self.kubikle_object_id = kubikle_object_id
34+
self.settings = settings
35+
36+
def get_raw(self):
37+
"""
38+
Gets all settings as a raw dictionary. This returns a reference to the raw settings, not a copy,
39+
"""
40+
return self.settings
41+

dataikuapi/dss/project.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .analysis import DSSAnalysis
2626
from .flow import DSSProjectFlow
2727
from .app import DSSAppManifest
28-
28+
from .kubikle import DSSKubikleObject
2929

3030
class DSSProject(object):
3131
"""
@@ -1606,6 +1606,7 @@ def get_app_manifest(self):
16061606
raw_data = self.client._perform_json("GET", "/projects/%s/app-manifest" % self.project_key)
16071607
return DSSAppManifest(self.client, raw_data, self.project_key)
16081608

1609+
########################################################
16091610
# MLflow experiment tracking
16101611
########################################################
16111612
def setup_mlflow(self, managed_folder, host=None):
@@ -1626,6 +1627,55 @@ def get_mlflow_extension(self):
16261627
"""
16271628
return DSSMLflowExtension(client=self.client, project_key=self.project_key)
16281629

1630+
1631+
1632+
########################################################
1633+
# Kubikles
1634+
########################################################
1635+
def list_kubikle_objects(self):
1636+
"""
1637+
List the kubikle objects in this project
1638+
1639+
Returns:
1640+
the list of the kubikle objects, each one as a JSON object
1641+
"""
1642+
return self.client._perform_json(
1643+
"GET", "/projects/%s/kubikles/" % self.project_key)
1644+
1645+
def get_kubikle_object(self, kubikle_object_id):
1646+
"""
1647+
Get a handle to interact with a specific kubikle object
1648+
1649+
Args:
1650+
kubikle_object_id: the identifier of the desired kubikle object
1651+
1652+
Returns:
1653+
A :class:`dataikuapi.dss.kubikle.DSSKubikleObject` kubikle object handle
1654+
"""
1655+
return DSSKubikleObject(self.client, self.project_key, kubikle_object_id)
1656+
1657+
def create_kubikle_object(self, name, template_id):
1658+
"""
1659+
Create a new kubikle object in the project, and return a handle to interact with it
1660+
1661+
Args:
1662+
name: the name of the kubikle object
1663+
template_id: the identifier of a kubikle template
1664+
1665+
Returns:
1666+
A :class:`dataikuapi.dss.kubikle.DSSKubikleObject` kubikle object handle
1667+
"""
1668+
obj = {
1669+
"name" : name,
1670+
"projectKey" : self.project_key,
1671+
"templateId" : template_id
1672+
}
1673+
res = self.client._perform_json("POST", "/projects/%s/kubikles/" % self.project_key, body = obj)
1674+
kubikle_object_id = res['id']
1675+
return DSSKubikleObject(self.client, self.project_key, kubikle_object_id)
1676+
1677+
1678+
16291679
class TablesImportDefinition(object):
16301680
"""
16311681
Temporary structure holding the list of tables to import

dataikuapi/dssclient.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .dss.project import DSSProject
1212
from .dss.app import DSSApp
1313
from .dss.plugin import DSSPlugin
14-
from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSGlobalUsageSummary, DSSInstanceVariables
14+
from .dss.admin import DSSUser, DSSOwnUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster, DSSKubikleTemplate, DSSKubikleTemplateListItem, DSSGlobalUsageSummary, DSSInstanceVariables
1515
from .dss.meaning import DSSMeaning
1616
from .dss.sqlquery import DSSSQLQuery
1717
from .dss.discussion import DSSObjectDiscussions
@@ -593,6 +593,39 @@ def create_cluster(self, cluster_name, cluster_type='manual', params=None):
593593
raise Exception('Cluster creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {}))))
594594
return DSSCluster(self, resp['id'])
595595

596+
597+
########################################################
598+
# Kubikle templates
599+
########################################################
600+
601+
def list_kubikle_templates(self, as_type='listitems'):
602+
"""
603+
List all kubikle templates on the DSS instance
604+
605+
Returns:
606+
List of templates (name, type)
607+
"""
608+
items = self._perform_json("GET", "/admin/kubikles/")
609+
if as_type == "listitems" or as_type == "listitem":
610+
return [DSSKubikleTemplateListItem(self, item) for item in items]
611+
elif as_type == "objects" or as_type == "object":
612+
return [DSSKubikleTemplate(self, item["id"]) for item in items]
613+
else:
614+
raise ValueError("Unknown as_type")
615+
616+
def get_kubikle_template(self, template_id):
617+
"""
618+
Get a handle to interact with a specific kubikle template
619+
620+
Args:
621+
template_id: the template id of the desired kubikle template
622+
623+
Returns:
624+
A :class:`dataikuapi.dss.admin.DSSKubikleTemplate` kubikle template handle
625+
"""
626+
return DSSKubikleTemplate(self, template_id)
627+
628+
596629
########################################################
597630
# Global API Keys
598631
########################################################

0 commit comments

Comments
 (0)