예제 #1
0
def logs(client: ModelTrainingClient, train_id: str, file: str, follow: bool):
    """
    \b
    Stream training logs.
    For this command, you must provide a training ID or path to file with one training.
    The file must contain only one training.
    \b
    Usage example:
        * odahuflowctl train delete --id examples-git
        * odahuflowctl train delete -f train.yaml
    \f
    :param follow: Follow logs stream
    :param client: Model training HTTP client
    :param train_id: Model training ID
    :param file: Path to the file with only one training
    """
    check_id_or_file_params_present(train_id, file)

    if file:
        train = parse_resources_file_with_one_item(file).resource
        if not isinstance(train, ModelTraining):
            raise ValueError(
                f'Model training expected, but {type(train)} provided')

        train_id = train.id

    for msg in client.log(train_id, follow):
        print_logs(msg)
예제 #2
0
def delete(client: ModelRouteClient, mr_id: str, file: str,
           ignore_not_found: bool):
    """
    Delete a model route.\n
    For this command, you must provide a model route ID or path to file with one model route.
    The file must contain only one model route.
    If you want to delete multiples routes than you should use "odahuflowctl res delete" instead.
    For now, CLI supports yaml and JSON file formats.
    The command will be failed if you provide both arguments.\n
    Usage example:\n
        * odahuflowctl route delete --id examples-git\n
        * odahuflowctl route delete -f route.yaml
    \f
    :param client: ModelRoute HTTP client
    :param mr_id: ModelRoute ID
    :param file: Path to the file with only one model route
    :param ignore_not_found: ignore if Model Deployment is not found
    """
    check_id_or_file_params_present(mr_id, file)

    if file:
        route_resource = parse_resources_file_with_one_item(file).resource
        if not isinstance(route_resource, ModelRoute):
            raise ValueError(
                f'ModelRoute expected, but {type(route_resource)} provided')

        mr_id = route_resource.id

    try:
        click.echo(client.delete(mr_id))
    except WrongHttpStatusCode as e:
        if e.status_code != 404 or not ignore_not_found:
            raise e

        click.echo(f'Model route {mr_id} was not found. Ignore')
예제 #3
0
    def deployment_post(payload_file, image=None):
        api_object = parse_resources_file_with_one_item(payload_file).resource

        if image:
            api_object.spec.image = image

        return ModelDeploymentClient().create(api_object)
def edit(client: PackagingIntegrationClient, pi_id: str, file: str,
         output_format: str):
    """
    Update a packaging integration.\n
    You should specify a path to file with a packaging integration.
    The file must contain only one packaging integration.
    For now, CLI supports yaml and JSON file formats.
    If you want to update multiples packaging integrations than you should use "odahuflowctl res apply" instead.
    If you provide the packaging integration id parameter than it will be overridden before sending to API server.\n
    Usage example:\n
        * odahuflowctl pack-integration update -f pi.yaml --id examples-git
    \f
    :param client: Packaging integration HTTP client
    :param pi_id: Packaging integration ID
    :param file: Path to the file with only one packaging integration
    :param output_format: Output format
    """
    pi = parse_resources_file_with_one_item(file).resource
    if not isinstance(pi, PackagingIntegration):
        raise ValueError(
            f'Packaging integration expected, but {type(pi)} provided')

    if pi_id:
        pi.id = pi_id

    click.echo(format_output([client.edit(pi)], output_format))
def delete(client: ToolchainIntegrationClient, ti_id: str, file: str,
           ignore_not_found: bool):
    """
    Delete a toolchain integration.\n
    For this command, you must provide a toolchain integration ID or path to file with one toolchain integration.
    The file must contain only one toolchain integration.
    If you want to delete multiples toolchain integrations than you should use "odahuflowctl res delete" instead.
    For now, CLI supports yaml and JSON file formats.
    The command will be failed if you provide both arguments.\n
    Usage example:\n
        * odahuflowctl tn-integration delete --id examples-git\n
        * odahuflowctl tn-integration delete -f ti.yaml
    \f
    :param client: Toolchain integration HTTP client
    :param ti_id: Toolchain integration ID
    :param file: Path to the file with only one toolchain integration
    :param ignore_not_found: ignore if toolchain integration is not found
    """
    check_id_or_file_params_present(ti_id, file)

    if file:
        ti = parse_resources_file_with_one_item(file).resource
        if not isinstance(ti, ToolchainIntegration):
            raise ValueError(
                f'Toolchain Integration expected, but {type(ti)} provided')

        ti_id = ti.id

    try:
        click.echo(client.delete(ti_id))
    except WrongHttpStatusCode as e:
        if e.status_code != http.HTTPStatus.NOT_FOUND or not ignore_not_found:
            raise e

        click.echo(IGNORE_NOT_FOUND_ERROR_MESSAGE.format(ti_id))
예제 #6
0
def edit(client: ModelDeploymentClient, md_id: str, file: str, wait: bool, timeout: int, image: str):
    """
    \b
    Update a deployment.
    You should specify a path to file with a deployment. The file must contain only one deployment.
    For now, CLI supports YAML and JSON file formats.
    If you want to update multiple deployments, you should use "odahuflowctl bulk apply" instead.
    If you provide the deployment id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl dep update -f dep.yaml --id examples-git
    \f
    :param client: Model deployment HTTP client
    :param md_id: Model deployment ID
    :param file: Path to the file with only one deployment
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until edit will be finished
    :param image: Override Docker image from file
    """
    md = parse_resources_file_with_one_item(file).resource
    if not isinstance(md, ModelDeployment):
        raise ValueError(f'Model deployment expected, but {type(md)} provided')

    if md_id:
        md.id = md_id

    if image:
        md.spec.image = image

    click.echo(client.edit(md))

    wait_deployment_finish(timeout, wait, md.id, client)
예제 #7
0
def edit(client: ConnectionClient, conn_id: str, file: str,
         output_format: str):
    """
    \b
    Update a connection.
    You should specify a path to file with a connection. The file must contain only one connection.
    For now, CLI supports YAML and JSON file formats.
    If you want to update multiple connections, you should use "odahuflowctl bulk apply" instead.
    If you provide the connection id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl conn update -f conn.yaml --id examples-git
    \f
    :param client: Connection HTTP client
    :param conn_id: Connection ID
    :param file: Path to the file with only one connection
    :param output_format: Output format
    """
    conn = parse_resources_file_with_one_item(file).resource
    if not isinstance(conn, Connection):
        raise ValueError(f'Connection expected, but {type(conn)} provided')

    if conn_id:
        conn.id = conn_id

    click.echo(format_output([client.edit(conn)], output_format))
def create(client: ToolchainIntegrationClient, ti_id: str, file: str,
           output_format: str):
    """
    Create a toolchain integration.\n
    You should specify a path to file with a toolchain integration.
    The file must contain only one toolchain integration.
    For now, CLI supports yaml and JSON file formats.
    If you want to create multiples toolchain integrations than you should use "odahuflowctl res apply" instead.
    If you provide the toolchain integration id parameter than it will be overridden before sending to API server.\n
    Usage example:\n
        * odahuflowctl tn-integration create -f ti.yaml --id examples-git
    \f
    :param client: Toolchain integration HTTP client
    :param ti_id: Toolchain integration ID
    :param file: Path to the file with only one toolchain integration
    :param output_format: Output format
    """
    ti = parse_resources_file_with_one_item(file).resource
    if not isinstance(ti, ToolchainIntegration):
        raise ValueError(
            f'Toolchain integration expected, but {type(ti)} provided')

    if ti_id:
        ti.id = ti_id

    click.echo(format_output([client.create(ti)], output_format))
예제 #9
0
def edit(client: ModelTrainingClient, train_id: str, file: str, wait: bool,
         timeout: int):
    """
    \b
    Rerun a training.
    You should specify a path to file with a training. The file must contain only one training.
    For now, CLI supports YAML and JSON file formats.
    If you want to update multiple trainings, you should use "odahuflowctl bulk apply" instead.
    If you provide the training id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl train update -f train.yaml --id examples-git
    \f
    :param client: Model training HTTP client
    :param train_id: Model training ID
    :param file: Path to the file with only one training
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until scale will be finished
    """
    train = parse_resources_file_with_one_item(file).resource
    if not isinstance(train, ModelTraining):
        raise ValueError(
            f'Model training expected, but {type(train)} provided')

    if train_id:
        train.id = train_id

    train = client.edit(train)
    click.echo(f"Rerun training: {train}")

    wait_training_finish(timeout, wait, train.id, client)
예제 #10
0
    def packaging_post(payload_file, artifact_name=None):
        api_object = parse_resources_file_with_one_item(payload_file).resource

        if artifact_name:
            api_object.spec.artifact_name = artifact_name

        return ModelPackagingClient().create(api_object)
예제 #11
0
def create(client: ModelRouteClient, mr_id: str, file: str, wait: bool,
           timeout: int):
    """
    Create a model route.\n
    You should specify a path to file with a model route. The file must contain only one model route.
    For now, CLI supports yaml and JSON file formats.
    If you want to create multiples routes then you should use "odahuflowctl bulk apply" instead.
    If you provide the model route id parameter than it will be overridden before sending to API server.\n
    Usage example:\n
        * odahuflowctl route create -f route.yaml --id examples-git
    \f
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until operation will be finished
    :param client: ModelRoute HTTP client
    :param mr_id: ModelRoute ID
    :param file: Path to the file with only one model route
    """
    route_resource = parse_resources_file_with_one_item(file).resource
    if not isinstance(route_resource, ModelRoute):
        raise ValueError(
            f'ModelRoute expected, but {type(route_resource)} provided')

    if mr_id:
        route_resource.id = mr_id

    click.echo(client.create(route_resource))

    wait_operation_finish(timeout, wait, mr_id, client)
예제 #12
0
def logs(client: ModelPackagingClient, pack_id: str, file: str, follow: bool):
    """
    \b
    Stream packaging logs.
    For this command, you must provide a packaging ID or path to file with one packaging.
    The file must contain only one packaging.
    The command will fail if you provide both arguments.
    \b
    Usage example:
        * odahuflowctl pack delete --id examples-git
        * odahuflowctl pack delete -f pack.yaml
    \f
    :param follow: Follow logs stream
    :param client: Model packaging HTTP client
    :param pack_id: Model packaging ID
    :param file: Path to the file with only one packaging
    """
    check_id_or_file_params_present(pack_id, file)

    if file:
        pack = parse_resources_file_with_one_item(file).resource
        if not isinstance(pack, ModelPackaging):
            raise ValueError(
                f'Model packaging expected, but {type(pack)} provided')

        pack_id = pack.id

    for msg in client.log(pack_id, follow):
        print_logs(msg)
예제 #13
0
def edit(client: ModelPackagingClient, pack_id: str, file: str, wait: bool,
         timeout: int, artifact_name: str):
    """
    \b
    Update a packaging.
    You should specify a path to file with a packaging. The file must contain only one packaging.
    For now, CLI supports YAML and JSON file formats.
    If you want to update multiple packagings, you should use "odahuflowctl bulk apply" instead.
    If you provide the packaging id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl pack update -f pack.yaml --id examples-git
    \f
    :param client: Model packaging HTTP client
    :param pack_id: Model packaging ID
    :param file: Path to the file with only one packaging
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until scale will be finished
    :param artifact_name: Override artifact name from file
    """
    pack = parse_resources_file_with_one_item(file).resource
    if not isinstance(pack, ModelPackaging):
        raise ValueError(
            f'Model packaging expected, but {type(pack)} provided')

    if pack_id:
        pack.id = pack_id

    if artifact_name:
        pack.spec.artifact_name = artifact_name

    mp = client.edit(pack)
    click.echo(f"Rerun packing: {mp}")

    wait_packaging_finish(timeout, wait, pack.id, client)
예제 #14
0
def create(client: ModelPackagingClient, pack_id: str, file: str, wait: bool,
           timeout: int, artifact_name: str, ignore_if_exists: bool):
    """
    \b
    Create a packaging.
    You should specify a path to file with a packaging. The file must contain only one packaging.
    For now, CLI supports YAML and JSON file formats.
    If you want to create multiple packagings, you should use "odahuflowctl bulk apply" instead.
    If you provide the packaging id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl pack create -f pack.yaml --id examples-git
    \f
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until scale will be finished
    :param client: Model packaging HTTP client
    :param pack_id: Model packaging ID
    :param file: Path to the file with only one packaging
    :param artifact_name: Override artifact name from file
    :param ignore_if_exists: Return success status code if entity is already exists
    """
    pack = parse_resources_file_with_one_item(file).resource
    if not isinstance(pack, ModelPackaging):
        raise ValueError(
            f'Model packaging expected, but {type(pack)} provided')

    if pack_id:
        pack.id = pack_id

    if artifact_name:
        pack.spec.artifact_name = artifact_name

    try:
        mp = client.create(pack)
    except EntityAlreadyExists as e:
        if ignore_if_exists:
            LOGGER.debug(
                f'--ignore-if-exists was passed: {e} will be suppressed')
            click.echo('Packaging already exists')
            return
        raise

    click.echo(f"Start packing: {mp}")

    wait_packaging_finish(timeout, wait, pack.id, client)
예제 #15
0
def create(client: ModelDeploymentClient, md_id: str, file: str, wait: bool,
           timeout: int, image: str, ignore_if_exists: bool):
    """
    \b
    Create a deployment.
    You should specify a path to file with a deployment. The file must contain only one deployment.
    For now, CLI supports YAML and JSON file formats.
    If you want to create multiple deployments, you should use "odahuflowctl bulk apply" instead.
    If you provide the deployment id parameter, it will override before sending to API server.
    \b
    Usage example:
        * odahuflowctl dep create -f dep.yaml --id examples-git
    \f
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until deployment will be finished
    :param client: Model deployment HTTP client
    :param md_id: Model deployment ID
    :param file: Path to the file with only one deployment
    :param image: Override Docker image from file
    :param ignore_if_exists: Return success status code if entity is already exists
    """
    md = parse_resources_file_with_one_item(file).resource
    if not isinstance(md, ModelDeployment):
        raise ValueError(f'Model deployment expected, but {type(md)} provided')

    if md_id:
        md.id = md_id

    if image:
        md.spec.image = image

    try:
        res = client.create(md)
    except EntityAlreadyExists as e:
        if ignore_if_exists:
            LOGGER.debug(
                f'--ignore-if-exists was passed: {e} will be suppressed')
            click.echo('Deployment already exists')
            return
        raise

    click.echo(res)

    wait_deployment_finish(timeout, wait, md.id, client)
예제 #16
0
def delete(client: ModelDeploymentClient, md_id: str, file: str,
           ignore_not_found: bool, wait: bool, timeout: int):
    """
    \b
    Delete a deployment.
    For this command, you must provide a deployment ID or path to file with one deployment.
    The file must contain only one deployment.
    If you want to delete multiple deployments, you should use "odahuflowctl bulk delete" instead.
    For now, CLI supports YAML and JSON file formats.
    The command will fail if you provide both arguments.
    \b
    Usage example:
        * odahuflowctl dep delete --id examples-git
        * odahuflowctl dep delete -f dep.yaml
    \f
    :param timeout: timeout in seconds. for wait (if no-wait is off)
    :param wait: no wait until deletion will be finished
    :param client: Model deployment HTTP client
    :param md_id: Model deployment ID
    :param file: Path to the file with only one deployment
    :param ignore_not_found: ignore if Model Deployment is not found
    """
    check_id_or_file_params_present(md_id, file)

    if file:
        md = parse_resources_file_with_one_item(file).resource
        if not isinstance(md, ModelDeployment):
            raise ValueError(
                f'Model deployment expected, but {type(md)} provided')

        md_id = md.id

    try:
        message = client.delete(md_id)

        wait_delete_operation_finish(timeout, wait, md_id, client)
        click.echo(message)
    except WrongHttpStatusCode as e:
        if e.status_code != 404 or not ignore_not_found:
            raise e

        click.echo(
            IGNORE_NOT_FOUND_ERROR_MESSAGE.format(
                kind=ModelDeployment.__name__, id=md_id))
예제 #17
0
def delete(client: ModelTrainingClient, train_id: str, file: str,
           ignore_not_found: bool):
    """
    \b
    Delete a training.
    For this command, you must provide a training ID or path to file with one training.
    The file must contain only one training.
    For now, CLI supports YAML and JSON file formats.
    If you want to delete multiple trainings, you should use "odahuflowctl bulk delete" instead.
    The command will fail if you provide both arguments.
    \b
    Usage example:
        * odahuflowctl train delete --id examples-git
        * odahuflowctl train delete -f train.yaml
    \f
    :param client: Model training HTTP client
    :param train_id: Model training ID
    :param file: Path to the file with only one training
    :param ignore_not_found: ignore if Model Training is not found
    """
    check_id_or_file_params_present(train_id, file)

    if file:
        train = parse_resources_file_with_one_item(file).resource
        if not isinstance(train, ModelTraining):
            raise ValueError(
                f'Model training expected, but {type(train)} provided')

        train_id = train.id

    try:
        message = client.delete(train_id)
        click.echo(message)
    except WrongHttpStatusCode as e:
        if e.status_code != 404 or not ignore_not_found:
            raise e

        click.echo(
            IGNORE_NOT_FOUND_ERROR_MESSAGE.format(kind=ModelTraining.__name__,
                                                  id=train_id))
예제 #18
0
def delete(client: ModelPackagingClient, pack_id: str, file: str,
           ignore_not_found: bool):
    """
    \b
    Delete a packaging.
    For this command, you must provide a packaging ID or path to file with one packaging.
    The file must contain only one packaging.
    If you want to delete multiple packagings, you should use "odahuflowctl bulk delete" instead.
    For now, CLI supports YAML and JSON file formats.
    The command will fail if you provide both arguments.
    \b
    Usage example:
        * odahuflowctl pack delete --id examples-git
        * odahuflowctl pack delete -f pack.yaml
    \f
    :param client: Model packaging HTTP client
    :param pack_id: Model packaging ID
    :param file: Path to the file with only one packaging
    :param ignore_not_found: ignore if Model Packaging is not found
    """
    check_id_or_file_params_present(pack_id, file)

    if file:
        pack = parse_resources_file_with_one_item(file).resource
        if not isinstance(pack, ModelPackaging):
            raise ValueError(
                f'Model packaging expected, but {type(pack)} provided')

        pack_id = pack.id

    try:
        message = client.delete(pack_id)
        click.echo(message)
    except WrongHttpStatusCode as e:
        if e.status_code != 404 or not ignore_not_found:
            raise e

        click.echo(f'Model packaging {pack_id} was not found. Ignore')
예제 #19
0
def delete(client: ConnectionClient, conn_id: str, file: str,
           ignore_not_found: bool):
    """
    \b
    Delete a connection.
    For this command, you must provide a connection ID or path to file with one connection.
    The file must contain only one connection.
    If you want to delete multiple connections, you should use "odahuflowctl bulk delete" instead.
    For now, CLI supports YAML and JSON file formats.
    The command will fail if you provide both arguments.
    \b
    Usage example:
        * odahuflowctl conn delete --id examples-git
        * odahuflowctl conn delete -f conn.yaml
        * odahuflowctl conn delete --id examples-git --ignore-not-found
    \f
    :param client: Connection HTTP client
    :param conn_id: Connection ID
    :param file: Path to the file with only one connection
    :param ignore_not_found: ignore if connection is not found
    """
    check_id_or_file_params_present(conn_id, file)

    if file:
        conn = parse_resources_file_with_one_item(file).resource
        if not isinstance(conn, Connection):
            raise ValueError(f'Connection expected, but {type(conn)} provided')

        conn_id = conn.id

    try:
        click.echo(client.delete(conn_id))
    except WrongHttpStatusCode as e:
        if e.status_code != http.HTTPStatus.NOT_FOUND or not ignore_not_found:
            raise e

        click.echo(IGNORE_NOT_FOUND_ERROR_MESSAGE.format(conn_id))
예제 #20
0
 def training_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return ModelTrainingClient().create(api_object)
예제 #21
0
 def route_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return ModelRouteClient().create(api_object)
예제 #22
0
 def packager_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return PackagingIntegrationClient().create(api_object)
예제 #23
0
 def toolchain_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return ToolchainIntegrationClient().create(api_object)
예제 #24
0
 def connection_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return ConnectionClient().create(api_object)