コード例 #1
0
ファイル: user.py プロジェクト: zhcf/nauta
    def list(cls,
             namespace: str = None,
             custom_objects_api: CustomObjectsApi = None):
        """
        Return list of users.
        :namespace:
        :return: List of User objects
        """
        logger.debug('Listing users.')
        k8s_custom_object_api = custom_objects_api if custom_objects_api else PlatformResourceApiClient.get(
        )

        raw_users = k8s_custom_object_api.list_cluster_custom_object(
            group=cls.api_group_name,
            plural=cls.crd_plural_name,
            version=cls.crd_version)

        users = [
            User.from_k8s_response_dict(user_dict)
            for user_dict in raw_users['items']
        ]

        # Get experiment runs for each user
        # TODO: CHANGE IMPLEMENTATION TO USE AGGREGATED USER DATA AFTER CAN-366
        runs = Run.list(custom_objects_api=k8s_custom_object_api)
        user_map = {user.name: user for user in users}

        for run in runs:
            if user_map.get(run.namespace):
                user_map[run.namespace].experiment_runs.append(run)
            else:
                logger.error(
                    f"Run exists for nonexisting user {run.namespace}")

        return users
コード例 #2
0
ファイル: run.py プロジェクト: yuanbw/nauta
    def list(cls,
             namespace: str = None,
             custom_objects_api: CustomObjectsApi = None,
             **kwargs):
        """
        Return list of experiment runs.
        :param namespace: If provided, only runs from this namespace will be returned
        :param state_list: If provided, only runs with given states will be returned
        :param name_filter: If provided, only runs matching name_filter regular expression will be returned
        :param exp_name_filter: If provided, list of runs is filtered by experiment names from given list
        :param excl_state: If provided, only runs with a state other than given will be returned
        :param run_kinds_filter: If provided, only runs with a kind that matches to any of the run kinds from given
            filtering list will be returned
        :return: List of Run objects
        In case of problems during getting a list of runs - throws an error
        """
        state_list = kwargs.pop('state_list', None)
        name_filter = kwargs.pop('name_filter', None)
        exp_name_filter = kwargs.pop('exp_name_filter', None)
        excl_state = kwargs.pop('excl_state', None)
        run_kinds_filter = kwargs.pop('run_kinds_filter', None)

        k8s_custom_object_api = custom_objects_api if custom_objects_api else PlatformResourceApiClient.get(
        )
        if namespace:
            raw_runs = k8s_custom_object_api.list_namespaced_custom_object(
                group=Run.api_group_name,
                namespace=namespace,
                plural=Run.crd_plural_name,
                version=Run.crd_version)
        else:
            raw_runs = k8s_custom_object_api.list_cluster_custom_object(
                group=Run.api_group_name,
                plural=Run.crd_plural_name,
                version=Run.crd_version)

        try:
            name_regex = re.compile(name_filter) if name_filter else None
        except sre_constants.error as e:
            error_msg = Texts.REGEX_COMPILATION_FAIL_MSG.format(
                name_filter=name_filter)
            logger.exception(error_msg)
            raise InvalidRegularExpressionError(error_msg) from e

        run_filters = [
            partial(filter_by_name_regex,
                    name_regex=name_regex,
                    spec_location=False),
            partial(filter_run_by_state, state_list=state_list),
            partial(filter_run_by_excl_state, state=excl_state),
            partial(filter_by_experiment_name, exp_name=exp_name_filter),
            partial(filter_by_run_kinds, run_kinds=run_kinds_filter)
        ]

        runs = [
            Run.from_k8s_response_dict(run_dict)
            for run_dict in raw_runs['items'] if all(
                f(run_dict) for f in run_filters)
        ]
        return runs
コード例 #3
0
ファイル: experiment.py プロジェクト: zhcf/nauta
 def list_raw_experiments(
         cls,
         namespace: str = None,
         label_selector: str = "",
         custom_objects_api: CustomObjectsApi = None) -> dict:
     """
     Return raw list of experiments.
     :param namespace: If provided, only experiments from this namespace will be returned
     :param str label_selector: A selector to restrict the list of returned objects by their labels.
      Defaults to everything.
     """
     k8s_custom_object_api = custom_objects_api if custom_objects_api else PlatformResourceApiClient.get(
     )
     if namespace:
         raw_experiments = k8s_custom_object_api.list_namespaced_custom_object(
             group=Experiment.api_group_name,
             namespace=namespace,
             plural=Experiment.crd_plural_name,
             version=Experiment.crd_version,
             label_selector=label_selector)
     else:
         raw_experiments = k8s_custom_object_api.list_cluster_custom_object(
             group=Experiment.api_group_name,
             plural=Experiment.crd_plural_name,
             version=Experiment.crd_version,
             label_selector=label_selector)
     return raw_experiments
コード例 #4
0
    def list(cls,
             namespace: str = None,
             custom_objects_api: CustomObjectsApi = None,
             **kwargs):
        """
        Return list of experiment runs.
        :param namespace: If provided, only workflows from this namespace will be returned
        :param label_selector: If provided, only workflows matching label_selector expression will be returned
        :return: List of AgroWorkflow objects
        In case of problems during getting a list of workflows - throws an error
        """
        label_selector = kwargs.pop('label_selector', '')
        name_filter = kwargs.pop('name_filter', None)

        k8s_custom_object_api = custom_objects_api if custom_objects_api else PlatformResourceApiClient.get(
        )
        if namespace:
            raw_runs = k8s_custom_object_api.list_namespaced_custom_object(
                group=ArgoWorkflow.api_group_name,
                namespace=namespace,
                plural=ArgoWorkflow.crd_plural_name,
                version=ArgoWorkflow.crd_version,
                label_selector=label_selector)
        else:
            raw_runs = k8s_custom_object_api.list_cluster_custom_object(
                group=ArgoWorkflow.api_group_name,
                plural=ArgoWorkflow.crd_plural_name,
                version=ArgoWorkflow.crd_version,
                label_selector=label_selector)

        if name_filter:
            try:
                name_regex = re.compile(name_filter) if name_filter else None
            except sre_constants.error as e:
                error_msg = Texts.REGEX_COMPILATION_FAIL_MSG.format(
                    name_filter=name_filter)
                logger.exception(error_msg)
                raise InvalidRegularExpressionError(error_msg) from e

            run_filters = [
                partial(filter_by_name_regex,
                        name_regex=name_regex,
                        spec_location=False)
            ]

            runs = [
                ArgoWorkflow.from_k8s_response_dict(run_dict)
                for run_dict in raw_runs['items'] if all(
                    f(run_dict) for f in run_filters)
            ]
        else:
            runs = [
                ArgoWorkflow.from_k8s_response_dict(run_dict)
                for run_dict in raw_runs['items']
            ]
        return runs