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))
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))
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))
def get(client: ToolchainIntegrationClient, ti_id: str, output_format: str): """ Get toolchain integrations.\n The command without id argument retrieve all toolchain integrations.\n Get all toolchain integrations in json format:\n odahuflowctl tn-integration get --output-format json\n Get toolchain integration with "git-repo" id:\n odahuflowctl tn-integration get --id git-repo\n Using jsonpath:\n odahuflowctl tn-integration get -o 'jsonpath=[*].spec.reference' \f :param client: Toolchain integration HTTP client :param ti_id: Toolchain integration ID :param output_format: Output format :return: """ tis = [client.get(ti_id)] if ti_id else client.get_all() format_output(tis, output_format)
def run(client: ModelTrainingClient, train_id: str, manifest_file: List[str], manifest_dir: List[str], output_dir: str): """ \b Start a training process locally. \b Usage example: * odahuflowctl local train run --id examples-git \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)) mt: Optional[ModelTraining] = None # find a training toolchains: Dict[str, ToolchainIntegration] = {} for entity in map(lambda x: x.resource, entities): if isinstance(entity, ToolchainIntegration): toolchains[entity.id] = entity elif isinstance(entity, ModelTraining) and entity.id == train_id: mt = entity if not mt: click.echo( f'{train_id} training not found. Trying to retrieve it from API server' ) mt = client.get(train_id) toolchain = toolchains.get(mt.spec.toolchain) if not toolchain: click.echo( f'{toolchain} toolchain not found. Trying to retrieve it from API server' ) toolchain = ToolchainIntegrationClient.construct_from_other( client).get(mt.spec.toolchain) trainer = K8sTrainer( model_training=mt, toolchain_integration=toolchain, ) start_train(trainer, output_dir)
def toolchain_integration(ctx: click.core.Context, url: str, token: str): """ Allow you to perform actions on toolchain integration.\n Alias for the command is ti. """ ctx.obj = ToolchainIntegrationClient(url, token)
def toolchain_delete(ti_id: str): return ToolchainIntegrationClient().delete(ti_id)
def toolchain_post(payload_file): api_object = parse_resources_file_with_one_item(payload_file).resource return ToolchainIntegrationClient().create(api_object)
def toolchain_get_id(ti_id: str): return ToolchainIntegrationClient().get(ti_id)
def toolchain_get(): return ToolchainIntegrationClient().get_all()
connection.connection, 'Connection', ) TRAINING = EntityTestData( ModelTrainingClient(), ModelTraining( id=ENTITY_ID, spec=ModelTrainingSpec(work_dir="/1/2/3", model=ModelIdentity(name="name", version="version")), status=ModelTrainingStatus(state=SUCCEEDED_STATE)), training.training, 'ModelTraining') TOOLCHAIN = EntityTestData( ToolchainIntegrationClient(), ToolchainIntegration( id=ENTITY_ID, spec=ToolchainIntegrationSpec( default_image="mock-image", entrypoint="default-entrypoint", ), ), toolchain_integration.toolchain_integration, 'ToolchainIntegration', ) PACKAGING = EntityTestData( ModelPackagingClient(), ModelPackaging(id=ENTITY_ID, spec=ModelPackagingSpec(artifact_name='test-artifact-name',