def _search(cls, search_resource, search_item_factory, boto_next_token_name="NextToken", sagemaker_boto_client=None, **kwargs): sagemaker_boto_client = sagemaker_boto_client or _utils.sagemaker_client( ) next_token = None try: while True: search_request_kwargs = _boto_functions.to_boto( kwargs, cls._custom_boto_names, cls._custom_boto_types) search_request_kwargs["Resource"] = search_resource if next_token: search_request_kwargs[boto_next_token_name] = next_token search_method = getattr(sagemaker_boto_client, "search") search_method_response = search_method(**search_request_kwargs) search_items = search_method_response.get("Results", []) next_token = search_method_response.get(boto_next_token_name) for item in search_items: if cls.__name__ in item: yield search_item_factory(item[cls.__name__]) if not next_token: break except StopIteration: return
def _list(cls, boto_list_method, list_item_factory, boto_list_items_name, boto_next_token_name="NextToken", sagemaker_boto_client=None, **kwargs): sagemaker_boto_client = sagemaker_boto_client or _utils.sagemaker_client( ) next_token = None try: while True: list_request_kwargs = _boto_functions.to_boto( kwargs, cls._custom_boto_names, cls._custom_boto_types) if next_token: list_request_kwargs[boto_next_token_name] = next_token list_method = getattr(sagemaker_boto_client, boto_list_method) list_method_response = list_method(**list_request_kwargs) list_items = list_method_response.get(boto_list_items_name, []) next_token = list_method_response.get(boto_next_token_name) for item in list_items: yield list_item_factory(item) if not next_token: break except StopIteration: return
def to_boto(cls, obj): """Convert an object to a boto representation.""" if not isinstance(obj, dict): var_dict = vars(obj) else: var_dict = obj return _boto_functions.to_boto(var_dict, cls._custom_boto_names, cls._custom_boto_types)