def create(self, deployment_info, wait): from bentoml.yatai.validator import validate_deployment_pb if isinstance(deployment_info, dict): deployment_pb = deployment_dict_to_pb(deployment_info) elif isinstance(deployment_info, str): deployment_pb = deployment_yaml_string_to_pb(deployment_info) elif isinstance(deployment_info, Deployment): deployment_pb = deployment_info else: raise YataiDeploymentException( 'Unexpected argument type, expect deployment info to be str in yaml ' 'format or a dict or a deployment protobuf obj, instead got: {}'.format( str(type(deployment_info)) ) ) validation_errors = validate_deployment_pb(deployment_pb) if validation_errors: raise YataiDeploymentException( f'Failed to validate deployment {deployment_pb.name}: ' f'{validation_errors}' ) # Make sure there is no active deployment with the same deployment name get_deployment_pb = self.yatai_service.GetDeployment( GetDeploymentRequest( deployment_name=deployment_pb.name, namespace=deployment_pb.namespace ) ) if get_deployment_pb.status.status_code != status_pb2.Status.NOT_FOUND: raise BentoMLException( f'Deployment "{deployment_pb.name}" already existed, use Update or ' f'Apply for updating existing deployment, delete the deployment, ' f'or use a different deployment name' ) apply_result = self.yatai_service.ApplyDeployment( ApplyDeploymentRequest(deployment=deployment_pb) ) if apply_result.status.status_code != status_pb2.Status.OK: error_code, error_message = status_pb_to_error_code_and_message( apply_result.status ) raise YataiDeploymentException(f'{error_code}:{error_message}') if wait: self._wait_deployment_action_complete( deployment_pb.name, deployment_pb.namespace ) return self.get(namespace=deployment_pb.namespace, name=deployment_pb.name)
def get(self, namespace, name): return self.yatai_service.GetDeployment( GetDeploymentRequest(deployment_name=name, namespace=namespace))