コード例 #1
0
ファイル: post.py プロジェクト: sudo-k-runner/kubeflow
def post_pvc(namespace):
    body = request.get_json()
    log.info(f"Got body: {body}")

    notebook = helpers.load_param_yaml(
        utils.NOTEBOOK_TEMPLATE_YAML,
        name=body["name"],
        namespace=namespace,
        serviceAccount="default-editor",
    )

    defaults = utils.load_spawner_ui_config()

    form.set_notebook_image(notebook, body, defaults)
    form.set_notebook_image_pull_policy(notebook, body, defaults)
    form.set_notebook_cpu(notebook, body, defaults)
    form.set_notebook_memory(notebook, body, defaults)
    form.set_notebook_gpus(notebook, body, defaults)
    form.set_notebook_tolerations(notebook, body, defaults)
    form.set_notebook_affinity(notebook, body, defaults)
    form.set_notebook_configurations(notebook, body, defaults)

    # Workspace Volume
    workspace_vol = form.get_workspace_vol(body, defaults)
    if not body.get("noWorkspace", False) and workspace_vol["type"] == "New":
        # Create the PVC
        ws_pvc = utils.pvc_from_dict(workspace_vol, namespace)

        log.info("Creating Workspace Volume: %s", ws_pvc.to_dict())
        api.create_pvc(ws_pvc, namespace)

    if not body.get("noWorkspace", False) and workspace_vol["type"] != "None":
        form.add_notebook_volume(
            notebook,
            workspace_vol["name"],
            workspace_vol["name"],
            "/home/jovyan",
        )

    # Add the Data Volumes
    for vol in form.get_data_vols(body, defaults):
        if vol["type"] == "New":
            # Create the PVC
            dtvol_pvc = utils.pvc_from_dict(vol, namespace)

            log.info("Creating Data Volume: %s", dtvol_pvc)
            api.create_pvc(dtvol_pvc, namespace=namespace)

        form.add_notebook_volume(notebook, vol["name"], vol["name"],
                                 vol["path"])

    # shm
    form.set_notebook_shm(notebook, body, defaults)

    log.info("Creating Notebook: %s", notebook)
    api.create_notebook(notebook, namespace)

    return api.success_response("message", "Notebook created successfully.")
コード例 #2
0
ファイル: get.py プロジェクト: sudo-k-runner/kubeflow
def get_poddefaults(namespace):
    pod_defaults = api.list_poddefaults(namespace)

    # Return a list of (label, desc) with the pod defaults
    contents = []
    for pd in pod_defaults["items"]:
        label = list(pd["spec"]["selector"]["matchLabels"].keys())[0]
        if "desc" in pd["spec"]:
            desc = pd["spec"]["desc"]
        else:
            desc = pd["metadata"]["name"]

        contents.append({"label": label, "desc": desc})

    log.info("Found poddefaults: %s", contents)
    return api.success_response("poddefaults", contents)
コード例 #3
0
def patch_notebook(namespace, notebook):
    request_body = request.get_json()
    log.info("Got body: %s", request_body)

    if request_body is None:
        raise exceptions.BadRequest("Request doesn't have a body.")

    # Ensure request has at least one valid command
    if not any(attr in ATTRIBUTES for attr in request_body.keys()):
        raise exceptions.BadRequest(
            "Request body must include at least one supported key: %s" %
            list(ATTRIBUTES))

    # start/stop a notebook
    if STOP_ATTR in request_body:
        start_stop_notebook(namespace, notebook, request_body)

    return api.success_response()
コード例 #4
0
ファイル: delete.py プロジェクト: sudo-k-runner/kubeflow
def delete_notebook(notebook, namespace):
    log.info(f"Deleting Notebook '{namespace}/{notebook}'")
    api.delete_notebook(notebook, namespace)

    return api.success_response("message",
                                f"Notebook {notebook} successfully deleted.")
コード例 #5
0
ファイル: post.py プロジェクト: sudo-k-runner/kubeflow
def post_notebook(namespace):
    body = request.get_json()
    log.info(f"Got body: {body}")

    notebook = helpers.load_param_yaml(
        utils.NOTEBOOK_TEMPLATE_YAML,
        name=body["name"],
        namespace=namespace,
        serviceAccount="default-editor",
    )

    defaults = utils.load_spawner_ui_config()

    form.set_notebook_image(notebook, body, defaults)
    form.set_notebook_image_pull_policy(notebook, body, defaults)
    form.set_notebook_cpu(notebook, body, defaults)
    form.set_notebook_memory(notebook, body, defaults)
    form.set_notebook_gpus(notebook, body, defaults)
    form.set_notebook_tolerations(notebook, body, defaults)
    form.set_notebook_affinity(notebook, body, defaults)
    form.set_notebook_configurations(notebook, body, defaults)
    form.set_notebook_environment(notebook, body, defaults)

    # Workspace Volume
    ws_pvc = None
    workspace_vol = form.get_workspace_vol(body, defaults)
    if not body.get("noWorkspace", False) and workspace_vol["type"] != "None":
        ws_pvc = rok_common.rok_pvc_from_dict(workspace_vol, namespace)

        rok_common.add_workspace_volume_annotations(ws_pvc, workspace_vol)

        form.add_notebook_volume(
            notebook,
            ws_pvc.metadata.name,
            ws_pvc.metadata.name,
            "/home/jovyan",
        )

    # Add the Data Volumes
    dtvol_pvcs = []
    for vol in form.get_data_vols(body, defaults):
        dtvol_pvc = rok_common.rok_pvc_from_dict(vol, namespace)
        dtvol_pvcs.append(dtvol_pvc)

        rok_common.add_data_volume_annotations(dtvol_pvc, vol)

        form.add_notebook_volume(
            notebook,
            dtvol_pvc.metadata.name,
            dtvol_pvc.metadata.name,
            vol["path"],
        )

    # shm
    form.set_notebook_shm(notebook, body, defaults)

    # Create the Notebook before creating the PVCs
    log.info("Creating Notebook: %s", notebook)
    notebook = api.create_notebook(notebook, namespace)

    # Create the PVCs with owner references to the Notebook
    if ws_pvc is not None:
        rok_common.add_owner_reference(ws_pvc, notebook)
        log.info("Creating Workspace Volume: %s", ws_pvc.to_dict())
        api.create_pvc(ws_pvc, namespace)

    for dtvol_pvc in dtvol_pvcs:
        rok_common.add_owner_reference(dtvol_pvc, notebook)
        log.info("Creating Data Volume %s:", dtvol_pvc)
        api.create_pvc(dtvol_pvc, namespace=namespace)

    return api.success_response("message", "Notebook created successfully.")
コード例 #6
0
ファイル: get.py プロジェクト: sudo-k-runner/kubeflow
def get_config():
    config = utils.load_spawner_ui_config()
    return api.success_response("config", config)
コード例 #7
0
ファイル: get.py プロジェクト: sudo-k-runner/kubeflow
def get_notebooks(namespace):
    notebooks = api.list_notebooks(namespace)["items"]
    contents = [utils.notebook_dict_from_k8s_obj(nb) for nb in notebooks]

    return api.success_response("notebooks", contents)
コード例 #8
0
ファイル: get.py プロジェクト: sudo-k-runner/kubeflow
def get_pvcs(namespace):
    pvcs = api.list_pvcs(namespace).items
    contents = [utils.pvc_dict_from_k8s_obj(pvc) for pvc in pvcs]

    return api.success_response("pvcs", contents)