def prune(self, bento_name=None, labels=None): """ Delete all BentoServices that matches the specified criteria Args: bento_name: optional labels: optional Example: >>> yatai_client = get_yatai_client() >>> # Delete all bento services >>> yatai_client.repository.prune() >>> # Delete bento services that matches with the label `ci=failed` >>> yatai_client.repository.prune(labels='ci=failed') """ track('py-api-prune') list_bentos_result = self.list(bento_name=bento_name, labels=labels,) if list_bentos_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( list_bentos_result.status ) raise BentoMLException(f'{error_code}:{error_message}') for bento in list_bentos_result.bentos: bento_tag = f'{bento.name}:{bento.version}' try: self.delete(bento_tag) except BentoMLException as e: logger.error(f'Failed to delete Bento {bento_tag}: {e}')
def delete(self, bento): """ Delete bento Args: bento: a BentoService identifier in the format of NAME:VERSION Example: >>> >>> yatai_client = get_yatai_client() >>> yatai_client.repository.delete('my_service:version') """ track('py-api-delete') if ':' not in bento: raise BentoMLException( 'BentoService name or version is missing. Please provide in the ' 'format of name:version' ) name, version = bento.split(':') result = self.yatai_service.DangerouslyDeleteBento( DangerouslyDeleteBentoRequest(bento_name=name, bento_version=version) ) if result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( result.status ) raise BentoMLException( f'Failed to delete Bento {bento} {error_code}:{error_message}' )
def deploy( name, namespace, bento, labels, region, api_name, memory_size, timeout, output, wait, ): track_cli('deploy-create', PLATFORM_NAME) yatai_client = YataiClient() bento_name, bento_version = bento.split(':') try: with Spinner(f'Deploying "{bento}" to AWS Lambda '): result = yatai_client.deployment.create_lambda_deployment( name=name, namespace=namespace, bento_name=bento_name, bento_version=bento_version, api_name=api_name, region=region, memory_size=memory_size, timeout=timeout, labels=labels, wait=wait, ) if result.status.status_code != status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( result.status) track_cli( 'deploy-create-failure', PLATFORM_NAME, { 'error_code': error_code, 'error_message': error_message }, ) _echo( f'Failed to create AWS Lambda deployment {name} ' f'{error_code}:{error_message}', CLI_COLOR_ERROR, ) return track_cli('deploy-create-success', PLATFORM_NAME) _echo(f'Successfully created AWS Lambda deployment {name}', CLI_COLOR_SUCCESS) _print_deployment_info(result.deployment, output) except BentoMLException as e: track_cli('deploy-create-failure', PLATFORM_NAME, {'error_message': str(e)}) _echo( f'Failed to create AWS Lambda deployment {name} {str(e)}', CLI_COLOR_ERROR, )