|
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 |
@@ -412,6 +412,55 @@ def create_code_env(self, env_lang, env_name, deployment_mode, params=None): |
412 | 412 | raise Exception('Env creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
413 | 413 | return DSSCodeEnv(self, env_lang, env_name) |
414 | 414 |
|
| 415 | + ######################################################## |
| 416 | + # Clusters |
| 417 | + ######################################################## |
| 418 | + |
| 419 | + def list_clusters(self): |
| 420 | + """ |
| 421 | + List all clusters setup on the DSS instance |
| 422 | +
|
| 423 | + Returns: |
| 424 | + List clusters (name, type, state) |
| 425 | + """ |
| 426 | + return self._perform_json( |
| 427 | + "GET", "/admin/clusters/") |
| 428 | + |
| 429 | + def get_cluster(self, cluster_id): |
| 430 | + """ |
| 431 | + Get a handle to interact with a specific cluster |
| 432 | + |
| 433 | + Args: |
| 434 | + name: the name of the desired cluster |
| 435 | + |
| 436 | + Returns: |
| 437 | + A :class:`dataikuapi.dss.admin.DSSCluster` cluster handle |
| 438 | + """ |
| 439 | + return DSSCluster(self, cluster_id) |
| 440 | + |
| 441 | + def create_cluster(self, cluster_name, cluster_type='manual', params=None): |
| 442 | + """ |
| 443 | + Create a cluster, and return a handle to interact with it |
| 444 | +
|
| 445 | + :param cluster_name: the name of the new cluster |
| 446 | + :param cluster_type: the type of the new cluster |
| 447 | + :param params: the parameters of the new cluster, as a JSON object |
| 448 | + |
| 449 | + :returns: A :class:`dataikuapi.dss.admin.DSSCluster` cluster handle |
| 450 | + |
| 451 | + """ |
| 452 | + definition = {} |
| 453 | + definition['name'] = cluster_name |
| 454 | + definition['type'] = cluster_type |
| 455 | + definition['params'] = params if params is not None else {} |
| 456 | + resp = self._perform_json( |
| 457 | + "POST", "/admin/clusters/", body=definition) |
| 458 | + if resp is None: |
| 459 | + raise Exception('Cluster creation returned no data') |
| 460 | + if resp.get('messages', {}).get('error', False): |
| 461 | + raise Exception('Cluster creation failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 462 | + return DSSCluster(self, resp['id']) |
| 463 | + |
415 | 464 | ######################################################## |
416 | 465 | # Global API Keys |
417 | 466 | ######################################################## |
|
0 commit comments