|
6 | 6 | from .dss.future import DSSFuture |
7 | 7 | from .dss.project import DSSProject |
8 | 8 | from .dss.plugin import DSSPlugin |
9 | | -from .dss.admin import DSSUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey |
| 9 | +from .dss.admin import DSSUser, DSSGroup, DSSConnection, DSSGeneralSettings, DSSCodeEnv, DSSGlobalApiKey, DSSCluster |
10 | 10 | from .dss.meaning import DSSMeaning |
11 | 11 | from .dss.sqlquery import DSSSQLQuery |
12 | 12 | from .dss.notebook import DSSNotebook |
@@ -394,6 +394,55 @@ def create_code_env(self, env_lang, env_name, deployment_mode, params=None): |
394 | 394 | raise Exception('Env creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
395 | 395 | return DSSCodeEnv(self, env_lang, env_name) |
396 | 396 |
|
| 397 | + ######################################################## |
| 398 | + # Clusters |
| 399 | + ######################################################## |
| 400 | + |
| 401 | + def list_clusters(self): |
| 402 | + """ |
| 403 | + List all clusters setup on the DSS instance |
| 404 | +
|
| 405 | + Returns: |
| 406 | + List clusters (name, type, state) |
| 407 | + """ |
| 408 | + return self._perform_json( |
| 409 | + "GET", "/admin/clusters/") |
| 410 | + |
| 411 | + def get_cluster(self, cluster_id): |
| 412 | + """ |
| 413 | + Get a handle to interact with a specific cluster |
| 414 | + |
| 415 | + Args: |
| 416 | + name: the name of the desired cluster |
| 417 | + |
| 418 | + Returns: |
| 419 | + A :class:`dataikuapi.dss.admin.DSSCluster` cluster handle |
| 420 | + """ |
| 421 | + return DSSCluster(self, cluster_id) |
| 422 | + |
| 423 | + def create_cluster(self, cluster_name, cluster_type='manual', params=None): |
| 424 | + """ |
| 425 | + Create a cluster, and return a handle to interact with it |
| 426 | +
|
| 427 | + :param cluster_name: the name of the new cluster |
| 428 | + :param cluster_type: the type of the new cluster |
| 429 | + :param params: the parameters of the new cluster, as a JSON object |
| 430 | + |
| 431 | + :returns: A :class:`dataikuapi.dss.admin.DSSCluster` cluster handle |
| 432 | + |
| 433 | + """ |
| 434 | + definition = {} |
| 435 | + definition['name'] = cluster_name |
| 436 | + definition['type'] = cluster_type |
| 437 | + definition['params'] = params if params is not None else {} |
| 438 | + resp = self._perform_json( |
| 439 | + "POST", "/admin/clusters/", body=definition) |
| 440 | + if resp is None: |
| 441 | + raise Exception('Cluster creation returned no data') |
| 442 | + if resp.get('messages', {}).get('error', False): |
| 443 | + raise Exception('Cluster creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 444 | + return DSSCluster(self, resp['id']) |
| 445 | + |
397 | 446 | ######################################################## |
398 | 447 | # Global API Keys |
399 | 448 | ######################################################## |
|
0 commit comments