Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapte to VVP API change #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions jupytervvp/deployments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import random
import string

from jupytervvp.deploymentapiconstants import sql_deployment_create_endpoint, deployment_defaults_endpoint
from jupytervvp.deploymentoutput import DeploymentOutput
Expand Down Expand Up @@ -26,6 +28,8 @@ def make_deployment(cls, cell, session, shell, args):
endpoint = sql_deployment_create_endpoint(session.get_namespace())
body = cls._build_deployment_request(cell, session, parameters)
deployment_creation_response = session.submit_post_request(endpoint=endpoint, requestbody=json.dumps(body))
# print("Request body: " + str(body), file=open('dbg.log', 'a')) # dbg
# print("Response body: " + str(deployment_creation_response.text), file=open('dbg.log', 'a')) # dbg
if deployment_creation_response.status_code == 201:
deployment_id = json.loads(deployment_creation_response.text)['metadata']['id']
DeploymentOutput(deployment_id, session).show_output()
Expand All @@ -46,10 +50,10 @@ def handle_deployment_error(cls, deployment_creation_response):
def _get_deployment_target(session):
endpoint = deployment_defaults_endpoint(session.get_namespace())
response = session.execute_get_request(endpoint)
deployment_target_id = json.loads(response.text)["spec"].get("deploymentTargetId")
if deployment_target_id is None:
deployment_target_name = json.loads(response.text)["spec"].get("deploymentTargetName")
if deployment_target_name is None:
raise VvpConfigurationException(NO_DEFAULT_DEPLOYMENT_MESSAGE)
return deployment_target_id
return deployment_target_name

@classmethod
def _build_deployment_request(cls, cell, session, override_parameters):
Expand All @@ -69,8 +73,8 @@ def _build_deployment_request(cls, cell, session, override_parameters):
}
}
}
base_body['metadata']['name'] = cell
base_body['spec']['deploymentTargetId'] = cls._get_deployment_target(session)
base_body['metadata']['name'] = "jupyter-" + cls.get_random_suffix()
base_body['spec']['deploymentTargetName'] = cls._get_deployment_target(session)
cls.set_values_from_flat_parameters(base_body, REQUIRED_DEFAULT_PARAMETERS)

if override_parameters is not None:
Expand Down Expand Up @@ -137,6 +141,10 @@ def get_deployment_parameters(shell, args):
parameters_variable = args.parameters
return shell.user_ns.get(parameters_variable, None)

@staticmethod
def get_random_suffix():
characters = string.ascii_lowercase + string.digits
return ''.join(random.choice(characters) for _ in range(6))

class DeploymentException(Exception):
def __init__(self, message="", sql=None, response=None):
Expand Down