def update(name, namespace, bento, memory_size, timeout, output, wait): yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(':') else: bento_name = None bento_version = None with Spinner('Updating Lambda deployment '): result = yatai_client.deployment.update_lambda_deployment( bento_name=bento_name, bento_version=bento_version, deployment_name=name, namespace=namespace, memory_size=memory_size, timeout=timeout, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully updated AWS Lambda deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def update(name, namespace, bento, min_instances, max_burst, premium_plan_sku, output, wait): yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(':') else: bento_name = None bento_version = None with Spinner(f'Updating Azure Functions deployment {name}'): result = yatai_client.deployment.update_azure_functions_deployment( namespace=namespace, deployment_name=name, bento_name=bento_name, bento_version=bento_version, min_instances=min_instances, max_burst=max_burst, premium_plan_sku=premium_plan_sku, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully updated Azure Functions deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def get(bento, limit, ascending_order, print_location, labels, output): if ':' in bento: name, version = bento.split(':') else: name = bento version = None yatai_client = get_default_yatai_client() if name and version: output = output or 'json' get_bento_result = yatai_client.repository.get(name, version) if get_bento_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_bento_result.status) raise CLIException(f'{error_code}:{error_message}') if print_location: _echo(get_bento_result.bento.uri.uri) return _print_bento_info(get_bento_result.bento, output) elif name: output = output or 'table' list_bento_versions_result = yatai_client.repository.list( bento_name=name, limit=limit, labels=labels, ascending_order=ascending_order, ) if (list_bento_versions_result.status.status_code != yatai_proto.status_pb2.Status.OK): error_code, error_message = status_pb_to_error_code_and_message( list_bento_versions_result.status) raise CLIException(f'{error_code}:{error_message}') _print_bentos_info(list_bento_versions_result.bentos, output)
def delete(name, namespace, force): _echo( message='AWS EC2 deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-ec2-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() get_deployment_result = yatai_client.deployment.get( namespace=namespace, name=name) if get_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_deployment_result.status) raise CLIException(f"{error_code}:{error_message}") delete_deployment_result = yatai_client.deployment.delete( namespace=namespace, deployment_name=name, force_delete=force) if (delete_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK): error_code, error_message = status_pb_to_error_code_and_message( delete_deployment_result.status) raise CLIException(f"{error_code}:{error_message}") _echo(f"Successfiully deleted AWS EC2 deployment '{name}'", CLI_COLOR_SUCCESS)
def retrieve(bento, target_dir): if ':' not in bento: _echo(f'BentoService {bento} invalid - specify name:version') return name, version = bento.split(':') yatai_client = get_default_yatai_client() get_bento_result = yatai_client.repository.get(name, version) if get_bento_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_bento_result.status) raise CLIException( f'Failed to access BentoService {name}:{version} - ' f'{error_code}:{error_message}') if get_bento_result.bento.uri.s3_presigned_url: bento_service_bundle_path = get_bento_result.bento.uri.s3_presigned_url elif get_bento_result.bento.uri.gcs_presigned_url: bento_service_bundle_path = get_bento_result.bento.uri.gcs_presigned_url else: bento_service_bundle_path = get_bento_result.bento.uri.uri safe_retrieve(bento_service_bundle_path, target_dir) click.echo('Service %s artifact directory => %s' % (name, target_dir))
def update(name, namespace, bento, memory_size, timeout, output, wait): _echo( message= 'AWS Lambda deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-lambda-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(':') else: bento_name = None bento_version = None with Spinner('Updating Lambda deployment '): result = yatai_client.deployment.update_lambda_deployment( bento_name=bento_name, bento_version=bento_version, deployment_name=name, namespace=namespace, memory_size=memory_size, timeout=timeout, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully updated AWS Lambda deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def deploy( name, bento, namespace, region, min_size, desired_capacity, max_size, instance_type, ami_id, output, wait, ): yatai_client = get_default_yatai_client() bento_name, bento_version = bento.split(":") with Spinner(f"Deploying {bento} to AWS EC2"): result = yatai_client.deployment.create_ec2_deployment( name=name, namespace=namespace, bento_name=bento_name, bento_version=bento_version, region=region, min_size=min_size, desired_capacity=desired_capacity, max_size=max_size, instance_type=instance_type, ami_id=ami_id, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _print_deployment_info(result.deployment, output) _echo("Successfully created AWS EC2 deployment", CLI_COLOR_SUCCESS)
def delete(bentos, yes): """Delete saved BentoService. BENTO is the target BentoService to be deleted, referenced by its name and version in format of name:version. For example: "iris_classifier:v1.2.0" `bentoml delete` command also supports deleting multiple saved BentoService at once, by providing name version tag separated by ",", for example: `bentoml delete iris_classifier:v1.2.0,my_svc:v1,my_svc2:v3` """ yatai_client = get_default_yatai_client() for bento in bentos: name, version = bento.split(':') if not name and not version: raise CLIException( 'BentoService name or version is missing. Please provide in the ' 'format of name:version') if not yes and not click.confirm( f'Are you sure about delete {bento}? This will delete the BentoService ' f'saved bundle files permanently'): return result = yatai_client.repository.dangerously_delete_bento( name=name, 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 CLIException(f'{error_code}:{error_message}') _echo(f'BentoService {name}:{version} deleted')
def deploy( name, bento, namespace, labels, region, api_name, memory_size, timeout, output, wait, ): yatai_client = get_default_yatai_client() bento_name, bento_version = bento.split(':') 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 != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( result.status) raise CLIException(f'{error_code}:{error_message}') _echo(f'Successfully created AWS Lambda deployment {name}', CLI_COLOR_SUCCESS) _print_deployment_info(result.deployment, output)
def deploy( name, bento, namespace, labels, region, instance_type, instance_count, num_of_gunicorn_workers_per_instance, api_name, timeout, output, wait, data_capture_s3_prefix, data_capture_sample_percent, ): _echo( message= 'AWS Sagemaker deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-sagemaker-deploy ' 'going forward.', color='yellow', ) # use the DeploymentOperator name in proto to be consistent with amplitude bento_name, bento_version = bento.split(':') yatai_client = get_default_yatai_client() with Spinner('Deploying Sagemaker deployment '): result = yatai_client.deployment.create_sagemaker_deployment( name=name, namespace=namespace, labels=labels, bento_name=bento_name, bento_version=bento_version, instance_count=instance_count, instance_type=instance_type, num_of_gunicorn_workers_per_instance= num_of_gunicorn_workers_per_instance, # noqa E501 api_name=api_name, timeout=timeout, region=region, wait=wait, data_capture_s3_prefix=data_capture_s3_prefix, data_capture_sample_percent=data_capture_sample_percent, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully created AWS Sagemaker deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def list_deployment(namespace, limit, labels, order_by, asc, output): yatai_client = get_default_yatai_client() list_result = yatai_client.deployment.list_azure_functions_deployments( limit=limit, labels=labels, namespace=namespace, order_by=order_by, ascending_order=asc, ) if list_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( list_result.status) raise CLIException(f'{error_code}:{error_message}') _print_deployments_info(list_result.deployments, output)
def get(name, namespace, output): yatai_client = get_default_yatai_client() get_result = yatai_client.deployment.get(namespace, name) if get_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_result.status) raise CLIException(f'{error_code}:{error_message}') describe_result = yatai_client.deployment.describe(namespace, name) if describe_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( describe_result.status) raise CLIException(f'{error_code}:{error_message}') get_result.deployment.state.CopyFrom(describe_result.state) _print_deployment_info(get_result.deployment, output)
def create(deployment_yaml, output, wait): yatai_client = get_default_yatai_client() deployment_name = deployment_yaml.get('name') with Spinner('Creating deployment '): result = yatai_client.deployment.create(deployment_yaml, wait) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully created deployment {deployment_name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def delete(name, namespace, force): yatai_client = get_default_yatai_client() get_deployment_result = yatai_client.deployment.get(namespace, name) if get_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_deployment_result.status) raise CLIException(f'{error_code}:{error_message}') result = yatai_client.deployment.delete(name, namespace, force) 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 CLIException(f'{error_code}:{error_message}') _echo('Successfully deleted deployment "{}"'.format(name), CLI_COLOR_SUCCESS)
def list_bentos(limit, offset, labels, order_by, ascending_order, output): yatai_client = get_default_yatai_client() list_bentos_result = yatai_client.repository.list( limit=limit, offset=offset, labels=labels, order_by=order_by, ascending_order=ascending_order, ) 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 CLIException(f'{error_code}:{error_message}') _print_bentos_info(list_bentos_result.bentos, output)
def update( name, bento, namespace, min_size, desired_capacity, max_size, instance_type, ami_id, output, wait, ): _echo( message='AWS EC2 deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-ec2-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(":") else: bento_name = None bento_version = None with Spinner("Updating EC2 deployment"): update_result = yatai_client.deployment.update_ec2_deployment( deployment_name=name, bento_name=bento_name, bento_version=bento_version, namespace=namespace, min_size=min_size, desired_capacity=desired_capacity, max_size=max_size, instance_type=instance_type, ami_id=ami_id, wait=wait, ) if update_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( update_result.status) raise CLIException(f"{error_code}:{error_message}") _print_deployment_info(update_result.deployment, output) _echo(f"Successfiully updated AWS EC2 deployment '{name}'", CLI_COLOR_SUCCESS)
def deploy( name, bento, namespace, labels, region, instance_type, instance_count, num_of_gunicorn_workers_per_instance, api_name, timeout, output, wait, data_capture_s3_prefix, data_capture_sample_percent, ): # use the DeploymentOperator name in proto to be consistent with amplitude bento_name, bento_version = bento.split(':') yatai_client = get_default_yatai_client() with Spinner('Deploying Sagemaker deployment '): result = yatai_client.deployment.create_sagemaker_deployment( name=name, namespace=namespace, labels=labels, bento_name=bento_name, bento_version=bento_version, instance_count=instance_count, instance_type=instance_type, num_of_gunicorn_workers_per_instance= num_of_gunicorn_workers_per_instance, # noqa E501 api_name=api_name, timeout=timeout, region=region, wait=wait, data_capture_s3_prefix=data_capture_s3_prefix, data_capture_sample_percent=data_capture_sample_percent, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully created AWS Sagemaker deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def deploy( namespace, name, bento, location, min_instances, max_burst, premium_plan_sku, labels, function_auth_level, output, wait, ): _echo( message= 'Azure Functions deployment functionalities are being migrated to ' 'a separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/azure-functions-deploy ' 'going forward.', color='yellow', ) bento_name, bento_version = bento.split(':') yatai_client = get_default_yatai_client() with Spinner(f'Deploying {bento} to Azure Functions'): result = yatai_client.deployment.create_azure_functions_deployment( name=name, namespace=namespace, labels=labels, bento_name=bento_name, bento_version=bento_version, location=location, min_instances=min_instances, max_burst=max_burst, premium_plan_sku=premium_plan_sku, function_auth_level=function_auth_level, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully created Azure Functions deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def update( name, namespace, bento, api_name, instance_type, instance_count, num_of_gunicorn_workers_per_instance, timeout, output, wait, data_capture_s3_prefix, data_capture_sample_percent, ): yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(':') else: bento_name = None bento_version = None with Spinner('Updating Sagemaker deployment '): result = yatai_client.deployment.update_sagemaker_deployment( namespace=namespace, deployment_name=name, bento_name=bento_name, bento_version=bento_version, instance_count=instance_count, instance_type=instance_type, num_of_gunicorn_workers_per_instance= num_of_gunicorn_workers_per_instance, # noqa E501 timeout=timeout, api_name=api_name, wait=wait, data_capture_s3_prefix=data_capture_s3_prefix, data_capture_sample_percent=data_capture_sample_percent, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully updated AWS Sagemaker deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def delete(name, namespace, force): yatai_client = get_default_yatai_client() get_deployment_result = yatai_client.deployment.get( namespace=namespace, name=name) if get_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_deployment_result.status) raise CLIException(f"{error_code}:{error_message}") delete_deployment_result = yatai_client.deployment.delete( namespace=namespace, deployment_name=name, force_delete=force) if (delete_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK): error_code, error_message = status_pb_to_error_code_and_message( delete_deployment_result.status) raise CLIException(f"{error_code}:{error_message}") _echo(f"Successfiully deleted AWS EC2 deployment '{name}'", CLI_COLOR_SUCCESS)
def deploy( name, bento, namespace, region, min_size, desired_capacity, max_size, instance_type, ami_id, output, wait, ): _echo( message='AWS EC2 deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-ec2-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() bento_name, bento_version = bento.split(":") with Spinner(f"Deploying {bento} to AWS EC2"): result = yatai_client.deployment.create_ec2_deployment( name=name, namespace=namespace, bento_name=bento_name, bento_version=bento_version, region=region, min_size=min_size, desired_capacity=desired_capacity, max_size=max_size, instance_type=instance_type, ami_id=ami_id, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _print_deployment_info(result.deployment, output) _echo("Successfully created AWS EC2 deployment", CLI_COLOR_SUCCESS)
def update( name, bento, namespace, min_size, desired_capacity, max_size, instance_type, ami_id, output, wait, ): yatai_client = get_default_yatai_client() if bento: bento_name, bento_version = bento.split(":") else: bento_name = None bento_version = None with Spinner("Updating EC2 deployment"): update_result = yatai_client.deployment.update_ec2_deployment( deployment_name=name, bento_name=bento_name, bento_version=bento_version, namespace=namespace, min_size=min_size, desired_capacity=desired_capacity, max_size=max_size, instance_type=instance_type, ami_id=ami_id, wait=wait, ) if update_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( update_result.status) raise CLIException(f"{error_code}:{error_message}") _print_deployment_info(update_result.deployment, output) _echo(f"Successfiully updated AWS EC2 deployment '{name}'", CLI_COLOR_SUCCESS)
def get(name, namespace, output): _echo( message= 'AWS Lambda deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-lambda-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() describe_result = yatai_client.deployment.describe(namespace, name) if describe_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( describe_result.status) raise CLIException(f'{error_code}:{error_message}') get_result = yatai_client.deployment.get(namespace, name) if get_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_result.status) raise CLIException(f'{error_code}:{error_message}') _print_deployment_info(get_result.deployment, output)
def list_deployment(namespace, limit, labels, order_by, asc, output): _echo( message= 'AWS Sagemaker deployment functionalities are being migrated to a ' 'separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/aws-sagemaker-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() list_result = yatai_client.deployment.list_sagemaker_deployments( limit=limit, labels=labels, namespace=namespace, order_by=order_by, ascending_order=asc, ) if list_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( list_result.status) raise CLIException(f'{error_code}:{error_message}') _print_deployments_info(list_result.deployments, output)
def deploy( namespace, name, bento, location, min_instances, max_burst, premium_plan_sku, labels, function_auth_level, output, wait, ): bento_name, bento_version = bento.split(':') yatai_client = get_default_yatai_client() with Spinner(f'Deploying {bento} to Azure Functions'): result = yatai_client.deployment.create_azure_functions_deployment( name=name, namespace=namespace, labels=labels, bento_name=bento_name, bento_version=bento_version, location=location, min_instances=min_instances, max_burst=max_burst, premium_plan_sku=premium_plan_sku, function_auth_level=function_auth_level, wait=wait, ) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully created Azure Functions deployment {name}', CLI_COLOR_SUCCESS, ) _print_deployment_info(result.deployment, output)
def delete(name, namespace, force): _echo( message= 'Azure Functions deployment functionalities are being migrated to ' 'a separate tool and related CLI commands will be deprecated in BentoML ' 'itself, please use https://github.com/bentoml/azure-functions-deploy ' 'going forward.', color='yellow', ) yatai_client = get_default_yatai_client() get_deployment_result = yatai_client.deployment.get(namespace, name) if get_deployment_result.status.status_code != yatai_proto.status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( get_deployment_result.status) raise CLIException(f'{error_code}:{error_message}') result = yatai_client.deployment.delete(name, namespace, force) 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 CLIException(f'{error_code}:{error_message}') _echo( f'Successfully deleted Azure Functions deployment "{name}"', CLI_COLOR_SUCCESS, )