|
1 | 1 | from .future import DSSFuture |
| 2 | +import json |
2 | 3 |
|
3 | 4 | class DSSConnection(object): |
4 | 5 | """ |
@@ -417,3 +418,85 @@ def group_regexp(self, regexp, unix_user, hadoop_user=None): |
417 | 418 | self.raw['targetUnix'] = unix_user |
418 | 419 | self.raw['targetHadoop'] = hadoop_user |
419 | 420 | return self |
| 421 | + |
| 422 | +class DSSCodeEnv(object): |
| 423 | + """ |
| 424 | + A code env on the DSS instance |
| 425 | + """ |
| 426 | + def __init__(self, client, env_lang, env_name): |
| 427 | + self.client = client |
| 428 | + self.env_lang = env_lang |
| 429 | + self.env_name = env_name |
| 430 | + |
| 431 | + ######################################################## |
| 432 | + # Env deletion |
| 433 | + ######################################################## |
| 434 | + |
| 435 | + def delete(self): |
| 436 | + """ |
| 437 | + Delete the connection |
| 438 | +
|
| 439 | + Note: this call requires an API key with admin rights |
| 440 | + """ |
| 441 | + resp = self.client._perform_json( |
| 442 | + "DELETE", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name)) |
| 443 | + if resp is None: |
| 444 | + raise Exception('Env deletion returned no data') |
| 445 | + if resp.get('messages', {}).get('error', False): |
| 446 | + raise Exception('Env deletion failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 447 | + |
| 448 | + |
| 449 | + ######################################################## |
| 450 | + # Code env description |
| 451 | + ######################################################## |
| 452 | + |
| 453 | + def get_definition(self): |
| 454 | + """ |
| 455 | + Get the code env's definition |
| 456 | +
|
| 457 | + Note: this call requires an API key with admin rights |
| 458 | + |
| 459 | + Returns: |
| 460 | + the code env definition, as a JSON object |
| 461 | + """ |
| 462 | + return self.client._perform_json( |
| 463 | + "GET", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name)) |
| 464 | + |
| 465 | + ######################################################## |
| 466 | + # Code env modification |
| 467 | + ######################################################## |
| 468 | + def update(self, external_conda_name=None, conda_spec=None, spec=None): |
| 469 | + """ |
| 470 | + Update the code env definition and apply the changes |
| 471 | + |
| 472 | + Note: this call requires an API key with admin rights |
| 473 | + |
| 474 | + :param external_conda_name: name of an external conda env |
| 475 | + :param conda_spec: spec of the conda env |
| 476 | + :param spec: list of pip or R packages |
| 477 | + """ |
| 478 | + modifications = {'externalCondaEnvName':external_conda_name,'condaSpec':conda_spec,'spec':spec} |
| 479 | + resp = self.client._perform_json( |
| 480 | + "PUT", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name), |
| 481 | + body = modifications) |
| 482 | + if resp is None: |
| 483 | + raise Exception('Env update returned no data') |
| 484 | + if resp.get('messages', {}).get('error', False): |
| 485 | + raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 486 | + |
| 487 | + def set_jupyter_support(self, active): |
| 488 | + """ |
| 489 | + Update the code env jupyter support |
| 490 | + |
| 491 | + Note: this call requires an API key with admin rights |
| 492 | + |
| 493 | + :param active: True to activate jupyter support, False to deactivate |
| 494 | + """ |
| 495 | + resp = self.client._perform_json( |
| 496 | + "POST", "/admin/code-envs/%s/%s/jupyter" % (self.env_lang, self.env_name), |
| 497 | + params = {'active':active}) |
| 498 | + if resp is None: |
| 499 | + raise Exception('Env update returned no data') |
| 500 | + if resp.get('messages', {}).get('error', False): |
| 501 | + raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 502 | + |
0 commit comments