|
1 | 1 | from .future import DSSFuture |
| 2 | +import json |
2 | 3 |
|
3 | 4 | class DSSConnection(object): |
4 | 5 | """ |
@@ -417,3 +418,113 @@ 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 | + return resp |
| 448 | + |
| 449 | + |
| 450 | + ######################################################## |
| 451 | + # Code env description |
| 452 | + ######################################################## |
| 453 | + |
| 454 | + def get_definition(self): |
| 455 | + """ |
| 456 | + Get the code env's definition |
| 457 | +
|
| 458 | + Note: this call requires an API key with admin rights |
| 459 | + |
| 460 | + Returns: |
| 461 | + the code env definition, as a JSON object |
| 462 | + """ |
| 463 | + return self.client._perform_json( |
| 464 | + "GET", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name)) |
| 465 | + |
| 466 | + def set_definition(self, env): |
| 467 | + """ |
| 468 | + Set the code env's definition. The definition should come from a call to the get_definition() |
| 469 | + method. |
| 470 | +
|
| 471 | + Fields that can be updated in design node: |
| 472 | +
|
| 473 | + * env.permissions, env.usableByAll, env.desc.owner |
| 474 | + * env.specCondaEnvironment, env.specPackageList, env.externalCondaEnvName, env.desc.installCorePackages, |
| 475 | + env.desc.installJupyterSupport, env.desc.yarnPythonBin |
| 476 | +
|
| 477 | + Fields that can be updated in automation node (where {version} is the updated version): |
| 478 | +
|
| 479 | + * env.permissions, env.usableByAll, env.owner |
| 480 | + * env.{version}.specCondaEnvironment, env.{version}.specPackageList, env.{version}.externalCondaEnvName, |
| 481 | + env.{version}.desc.installCorePackages, env.{version}.desc.installJupyterSupport, env.{version}.desc.yarnPythonBin |
| 482 | +
|
| 483 | +
|
| 484 | +
|
| 485 | + Note: this call requires an API key with admin rights |
| 486 | + |
| 487 | + :param data: a code env definition |
| 488 | +
|
| 489 | + Returns: |
| 490 | + the updated code env definition, as a JSON object |
| 491 | + """ |
| 492 | + return self.client._perform_json( |
| 493 | + "PUT", "/admin/code-envs/%s/%s" % (self.env_lang, self.env_name), body=env) |
| 494 | + |
| 495 | + |
| 496 | + ######################################################## |
| 497 | + # Code env actions |
| 498 | + ######################################################## |
| 499 | + |
| 500 | + def set_jupyter_support(self, active): |
| 501 | + """ |
| 502 | + Update the code env jupyter support |
| 503 | + |
| 504 | + Note: this call requires an API key with admin rights |
| 505 | + |
| 506 | + :param active: True to activate jupyter support, False to deactivate |
| 507 | + """ |
| 508 | + resp = self.client._perform_json( |
| 509 | + "POST", "/admin/code-envs/%s/%s/jupyter" % (self.env_lang, self.env_name), |
| 510 | + params = {'active':active}) |
| 511 | + if resp is None: |
| 512 | + raise Exception('Env update returned no data') |
| 513 | + if resp.get('messages', {}).get('error', False): |
| 514 | + raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 515 | + return resp |
| 516 | + |
| 517 | + def update_packages(self): |
| 518 | + """ |
| 519 | + Update the code env packages so that it matches its spec |
| 520 | + |
| 521 | + Note: this call requires an API key with admin rights |
| 522 | + """ |
| 523 | + resp = self.client._perform_json( |
| 524 | + "POST", "/admin/code-envs/%s/%s/packages" % (self.env_lang, self.env_name)) |
| 525 | + if resp is None: |
| 526 | + raise Exception('Env update returned no data') |
| 527 | + if resp.get('messages', {}).get('error', False): |
| 528 | + raise Exception('Env update failed : %s' % (json.dumps(resp.get('messages', {}).get('messages', {})))) |
| 529 | + return resp |
| 530 | + |
0 commit comments