|
1 | 1 | from .future import DSSFuture |
2 | 2 | import json, warnings |
| 3 | +from datetime import datetime |
3 | 4 |
|
4 | 5 | class DSSConnectionInfo(dict): |
5 | 6 | """A class holding read-only information about a connection. |
@@ -1271,3 +1272,80 @@ def total_scenarios_count(self): |
1271 | 1272 | @property |
1272 | 1273 | def total_active_with_trigger_scenarios_count(self): |
1273 | 1274 | 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 | + |
0 commit comments