def list( self, bento_name: str = None, offset: int = None, limit: int = None, order_by: str = None, ascending_order: bool = None, labels: str = None, ) -> List["Bento"]: """ List BentoServices that satisfy the specified criteria. Args: bento_name (`str`): BentoService name offset (`int`): offset of results limit (`int`): maximum number of returned results labels (`str`): sorted by given labels order_by (`str`): orders retrieved BentoService by :obj:`created_at` or :obj:`name` ascending_order (`bool`): direction of results order Returns: lists of :class:`~bentoml.BentoService` metadata. Example:: from bentoml.yatai.client import get_yatai_client yatai_client = get_yatai_client() bentos_info_list = yatai_client.repository.list(labels='key=value,key2=value') """ # noqa: E501 # TODO: ignore type checking for this function. This is # due to all given arguments in `ListBentoRequest` are # not optional types. One solution is to make all # `ListBentoRequest` args in `list` positional. This could # introduce different behaviour at different places in the # codebase. Low triage list_bento_request = ListBentoRequest( bento_name=bento_name, # type: ignore offset=offset, # type: ignore limit=limit, # type: ignore order_by=order_by, # type: ignore ascending_order=ascending_order, # type: ignore ) if labels is not None: generate_gprc_labels_selector(list_bento_request.label_selectors, labels) result = self.yatai_service.ListBento(list_bento_request) 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'{error_code}:{error_message}') return result.bentos
def list( self, bento_name=None, offset=None, limit=None, labels=None, order_by=None, ascending_order=None, ): """ List BentoServices that satisfy the specified criteria. Args: bento_name: optional. BentoService name limit: optional. maximum number of returned results labels: optional. offset: optional. offset of results order_by: optional. order by results ascending_order: optional. direction of results order Returns: [bentoml.yatai.proto.repository_pb2.Bento] Example: >>> yatai_client = get_yatai_client() >>> bentos_info_list = yatai_client.repository.list( >>> labels='key=value,key2=value' >>> ) """ track('py-api-list') list_bento_request = ListBentoRequest( bento_name=bento_name, offset=offset, limit=limit, order_by=order_by, ascending_order=ascending_order, ) if labels is not None: generate_gprc_labels_selector(list_bento_request.label_selectors, labels) result = self.yatai_service.ListBento(list_bento_request) 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'{error_code}:{error_message}') return result.bentos
def list( self, limit=None, offset=None, labels=None, namespace=None, is_all_namespaces=False, operator=None, order_by=None, ascending_order=None, ): if is_all_namespaces: if namespace is not None: logger.warning( 'Ignoring `namespace=%s` due to the --all-namespace flag presented', namespace, ) namespace = ALL_NAMESPACE_TAG if isinstance(operator, str): if operator == 'sagemaker': operator = DeploymentSpec.AWS_SAGEMAKER elif operator == 'lambda': operator = DeploymentSpec.AWS_LAMBDA elif operator == DeploymentSpec.AZURE_FUNCTIONS: operator = 'azure-functions' elif operator == "ec2": operator = DeploymentSpec.AWS_EC2 else: raise BentoMLException(f'Unrecognized operator {operator}') list_deployment_request = ListDeploymentsRequest( limit=limit, offset=offset, namespace=namespace, operator=operator, order_by=order_by, ascending_order=ascending_order, ) if labels is not None: generate_gprc_labels_selector( list_deployment_request.label_selectors, labels ) return self.yatai_service.ListDeployments(list_deployment_request)
def list( self, bento_name=None, offset=None, limit=None, labels=None, order_by=None, ascending_order=None, ): list_bento_request = ListBentoRequest( bento_name=bento_name, offset=offset, limit=limit, order_by=order_by, ascending_order=ascending_order, ) if labels is not None: generate_gprc_labels_selector(list_bento_request.label_selectors, labels) return self.yatai_service.ListBento(list_bento_request)
def test_generate_grpc_labels_selector(): success_single_query = 'Test' success_single_selector = LabelSelectors() generate_gprc_labels_selector(success_single_selector, success_single_query) assert len(success_single_selector.match_expressions) == 1, '' assert success_single_selector.match_expressions[0].key == 'Test' assert (success_single_selector.match_expressions[0].operator == LabelSelectors.LabelSelectorExpression.OPERATOR_TYPE.Exists), '' success_multiple_query = 'Key1,key2 in (value1, value2), key3 Exists' success_multiple_selector = LabelSelectors() generate_gprc_labels_selector(success_multiple_selector, success_multiple_query) assert len(success_multiple_selector.match_expressions) == 3, '' assert success_multiple_selector.match_expressions[1].key == 'key2', '' assert success_multiple_selector.match_expressions[1].values == [ 'value1', 'value2', ], '' success_single_label_query = 'foo=bar' success_single_label_selector = LabelSelectors() generate_gprc_labels_selector(success_single_label_selector, success_single_label_query) assert 'foo' in success_single_label_selector.match_labels.keys(), '' assert 'bar' == success_single_label_selector.match_labels['foo'], '' assert len(success_single_label_selector.match_labels.keys()) == 1, '' success_multiple_labels_query = 'foo=bar,test=pass, foo=replaced' success_multiple_labels_selector = LabelSelectors() generate_gprc_labels_selector(success_multiple_labels_selector, success_multiple_labels_query) assert len(success_multiple_labels_selector.match_labels.keys()) == 2, '' assert success_multiple_labels_selector.match_labels[ 'foo'] == 'replaced', '' success_mixed_query = ( 'foo=bar, foo=replaced,test=passed,key1 in (value1, value2), ' 'key2 Exists, key3, user!=admin') success_mixed_selector = LabelSelectors() generate_gprc_labels_selector(success_mixed_selector, success_mixed_query) assert len(success_mixed_selector.match_expressions) == 4, '' assert success_mixed_selector.match_labels['foo'] == 'replaced', '' assert 'user' not in success_mixed_selector.match_labels.keys(), '' assert success_mixed_selector.match_expressions[3].key == 'user', '' assert success_mixed_selector.match_expressions[3].values == ['admin'], '' assert not success_mixed_selector.match_expressions[1].values, '' with pytest.raises(BentoMLException) as e: generate_gprc_labels_selector(LabelSelectors(), 'key=value1=value2') assert str(e.value).startswith("Too many '=' operator in") with pytest.raises(BentoMLException) as e: generate_gprc_labels_selector(LabelSelectors(), 'In') assert str(e.value).startswith( "Label query operator In can't be the only element") with pytest.raises(BentoMLException) as e: generate_gprc_labels_selector(LabelSelectors(), 'key in value1 value2') assert str(e.value).startswith('Too many elements in the label query') with pytest.raises(AssertionError) as e: generate_gprc_labels_selector(LabelSelectors(), 'Key IncorrectOperator') assert str(e.value).startswith('Operator "IncorrectOperator" is invalid') with pytest.raises(AssertionError) as e: generate_gprc_labels_selector(LabelSelectors(), 'Key ins (value)') assert str(e.value).startswith('Operator "ins" is invalid') with pytest.raises(BentoMLException) as e: generate_gprc_labels_selector(LabelSelectors(), 'key In ()') assert str(e.value).startswith("Query values can't be empty")