示例#1
0
def build_client(resource: OdahuflowCloudResourceUpdatePair,
                 api_client: RemoteAPIClient) -> typing.Optional[object]:
    """
    Build client for particular resource (e.g. it builds ModelTrainingClient for ModelTraining resource)

    :param resource: target resource
    :param api_client: base API client to extract connection options from
    :return: remote client or None
    """
    if isinstance(resource.resource, ModelTraining):
        return ModelTrainingClient.construct_from_other(api_client)
    elif isinstance(resource.resource, ModelDeployment):
        return ModelDeploymentClient.construct_from_other(api_client)
    elif isinstance(resource.resource, Connection):
        return ConnectionClient.construct_from_other(api_client)
    elif isinstance(resource.resource, ToolchainIntegration):
        return ToolchainIntegrationClient.construct_from_other(api_client)
    elif isinstance(resource.resource, ModelRoute):
        return ModelRouteClient.construct_from_other(api_client)
    elif isinstance(resource.resource, ModelPackaging):
        return ModelPackagingClient.construct_from_other(api_client)
    elif isinstance(resource.resource, PackagingIntegration):
        return PackagingIntegrationClient.construct_from_other(api_client)
    else:
        raise InvalidResourceType('{!r} is invalid resource '.format(
            resource.resource))
示例#2
0
def run(client: ModelPackagingClient, pack_id: str, manifest_file: List[str], manifest_dir: List[str],
        artifact_path: str, artifact_name: str, is_target_disabled: bool):
    """
    \b
    Start a packaging process locally.
    \b
    Usage example:
        * odahuflowctl local pack run --id wine
    \f
    """
    entities: List[OdahuflowCloudResourceUpdatePair] = []
    for file_path in manifest_file:
        entities.extend(parse_resources_file(file_path).changes)

    for dir_path in manifest_dir:
        entities.extend(parse_resources_dir(dir_path))

    mp: Optional[ModelPackaging] = None

    packagers: Dict[str, PackagingIntegration] = {}
    for entity in map(lambda x: x.resource, entities):
        if isinstance(entity, PackagingIntegration):
            packagers[entity.id] = entity
        elif isinstance(entity, ModelPackaging) and entity.id == pack_id:
            mp = entity

    if not mp:
        click.echo(
            f'The {pack_id} packaging not found in the manifest files.'
            f' Trying to retrieve it from API server'
        )
        mp = client.get(pack_id)

    integration_name = mp.spec.integration_name
    packager = packagers.get(integration_name)
    if not packager:
        click.echo(
            f'The {integration_name} packager not found in the manifest files.'
            f' Trying to retrieve it from API server'
        )
        packager = PackagingIntegrationClient.construct_from_other(client).get(integration_name)

    if artifact_name:
        mp.spec.artifact_name = artifact_name
        LOGGER.debug('Override the artifact name')

    if is_target_disabled:
        mp.spec.targets = []

    k8s_packager = K8sPackager(
        model_packaging=mp,
        packaging_integration=packager,
        targets=[],
    )

    result = start_package(k8s_packager, artifact_path)

    click.echo('Packager results:')
    for key, value in result.items():
        click.echo(f'* {key} - {value}')
示例#3
0
def delete(client: PackagingIntegrationClient, pi_id: str, file: str, ignore_not_found: bool):
    """
    Delete a packaging integration.\n
    For this command, you must provide a packaging integration ID or path to file with one packaging integration.
    The file must contain only one packaging integration.
    If you want to delete multiples packaging integrations then you should use "odahuflowctl bulk 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 pack-integration delete --id examples-git\n
        * odahuflowctl pack-integration delete -f pi.yaml
    \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 ignore_not_found: ignore if toolchain integration is not found
    """
    check_id_or_file_params_present(pi_id, file)

    if file:
        pi = parse_resources_file_with_one_item(file).resource
        if not isinstance(pi, PackagingIntegration):
            raise ValueError(f'Packaging Integration expected, but {type(pi)} provided')

        pi_id = pi.id

    try:
        click.echo(client.delete(pi_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(kind=PackagingIntegration.__name__, id=pi_id))
def create(client: PackagingIntegrationClient, pi_id: str, file: str,
           output_format: str):
    """
    Create 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 create 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 create -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.create(pi)], output_format))
示例#5
0
def get(client: PackagingIntegrationClient, pi_id: str, output_format: str):
    """
    Get packaging integrations.\n
    The command without id argument retrieve all packaging integrations.\n
    Get all packaging integrations in json format:\n
        odahuflowctl pack-integration get --output-format json\n
    Get packaging integration with "git-repo" id:\n
        odahuflowctl pack-integration get --id git-repo\n
    Using jsonpath:\n
        odahuflowctl pack-integration get -o 'jsonpath=[*].spec.reference'
    \f
    :param client: Packaging integration HTTP client
    :param pi_id: Packaging integration ID
    :param output_format: Output format
    :return:
    """
    pis = [client.get(pi_id)] if pi_id else client.get_all()

    format_output(pis, output_format)
示例#6
0
 def packager_delete(pi_id: str):
     return PackagingIntegrationClient().delete(pi_id)
示例#7
0
 def packager_post(payload_file):
     api_object = parse_resources_file_with_one_item(payload_file).resource
     return PackagingIntegrationClient().create(api_object)
示例#8
0
 def packager_get_id(pi_id: str):
     return PackagingIntegrationClient().get(pi_id)
示例#9
0
 def packager_get():
     return PackagingIntegrationClient().get_all()
示例#10
0
def packaging_integration(ctx: click.core.Context, url: str, token: str):
    """
    Allow you to perform actions on packaging integration.\n
    Alias for the command is pi.
    """
    ctx.obj = PackagingIntegrationClient(url, token)
示例#11
0
    toolchain_integration.toolchain_integration,
    'ToolchainIntegration',
)

PACKAGING = EntityTestData(
    ModelPackagingClient(),
    ModelPackaging(id=ENTITY_ID,
                   spec=ModelPackagingSpec(artifact_name='test-artifact-name',
                                           integration_name='test'),
                   status=ModelPackagingStatus(state=SUCCEEDED_STATE, )),
    packaging.packaging,
    'ModelPackaging',
)

PACKAGING_INTEGRATION = EntityTestData(
    PackagingIntegrationClient(),
    PackagingIntegration(
        id=ENTITY_ID,
        spec=PackagingIntegrationSpec(default_image="odahu:image",
                                      entrypoint="some_entrypoint"),
    ),
    packaging_integration.packaging_integration,
    'PackagingIntegration',
)

DEPLOYMENT = EntityTestData(
    ModelDeploymentClient(),
    ModelDeployment(id=ENTITY_ID,
                    spec=ModelDeploymentSpec(image="odahu:image",
                                             min_replicas=0),
                    status=ModelDeploymentStatus(