コード例 #1
0
ファイル: action_db.py プロジェクト: st2sandbox/st2
def get_runnertype_by_name(runnertype_name):
    """
    Get an runnertype by name.
    On error, raise ST2ObjectNotFoundError.
    """
    try:
        runnertypes = RunnerType.query(name=runnertype_name)
    except (ValueError, ValidationError) as e:
        LOG.error(
            'Database lookup for name="%s" resulted in exception: %s',
            runnertype_name,
            e,
        )
        raise StackStormDBObjectNotFoundError(
            'Unable to find runnertype with name="%s"' % runnertype_name
        )

    if not runnertypes:
        raise StackStormDBObjectNotFoundError(
            'Unable to find RunnerType with name="%s"' % runnertype_name
        )

    if len(runnertypes) > 1:
        LOG.warning(
            "More than one RunnerType returned from DB lookup by name. "
            "Result list is: %s",
            runnertypes,
        )

    return runnertypes[0]
コード例 #2
0
ファイル: action_views.py プロジェクト: rush-skills/st2
    def get_all(
        self,
        exclude_attributes=None,
        include_attributes=None,
        sort=None,
        offset=0,
        limit=None,
        requester_user=None,
        **raw_filters,
    ):
        """
        List all actions.

        Handles requests:
            GET /actions/views/overview
        """
        resp = super(OverviewController, self)._get_all(
            exclude_fields=exclude_attributes,
            include_fields=include_attributes,
            sort=sort,
            offset=offset,
            limit=limit,
            raw_filters=raw_filters,
            requester_user=requester_user,
        )
        runner_type_names = set([])
        action_ids = []

        result = []
        for item in resp.json:
            action_api = ActionAPI(**item)
            result.append(action_api)

            runner_type_names.add(action_api.runner_type)
            action_ids.append(str(action_api.id))

        # Add combined runner and action parameters to the compound result object
        # NOTE: This approach results in 2 additional queries while previous one resulted in
        # N * 2 additional queries

        # 1. Retrieve all the respective runner objects - we only need parameters
        runner_type_dbs = RunnerType.query(
            name__in=runner_type_names,
            only_fields=["name", "runner_parameters"])
        runner_type_dbs = dict([(runner_db.name, runner_db)
                                for runner_db in runner_type_dbs])

        # 2. Retrieve all the respective action objects - we only need parameters
        action_dbs = dict([(action_db.id, action_db) for action_db in result])

        for action_api in result:
            action_db = action_dbs.get(action_api.id, None)
            runner_db = runner_type_dbs.get(action_api.runner_type, None)
            all_params = action_param_utils.get_params_view(
                action_db=action_db, runner_db=runner_db, merged_only=True)
            action_api.parameters = all_params

        resp.json = result
        return resp
コード例 #3
0
ファイル: action_views.py プロジェクト: StackStorm/st2
    def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, offset=0,
                limit=None, requester_user=None, **raw_filters):
        """
            List all actions.

            Handles requests:
                GET /actions/views/overview
        """
        resp = super(OverviewController, self)._get_all(exclude_fields=exclude_attributes,
                                                        include_fields=include_attributes,
                                                        sort=sort,
                                                        offset=offset,
                                                        limit=limit,
                                                        raw_filters=raw_filters,
                                                        requester_user=requester_user)
        runner_type_names = set([])
        action_ids = []

        result = []
        for item in resp.json:
            action_api = ActionAPI(**item)
            result.append(action_api)

            runner_type_names.add(action_api.runner_type)
            action_ids.append(str(action_api.id))

        # Add combined runner and action parameters to the compound result object
        # NOTE: This approach results in 2 additional queries while previous one resulted in
        # N * 2 additional queries

        # 1. Retrieve all the respective runner objects - we only need parameters
        runner_type_dbs = RunnerType.query(name__in=runner_type_names,
                                           only_fields=['name', 'runner_parameters'])
        runner_type_dbs = dict([(runner_db.name, runner_db) for runner_db in runner_type_dbs])

        # 2. Retrieve all the respective action objects - we only need parameters
        action_dbs = dict([(action_db.id, action_db) for action_db in result])

        for action_api in result:
            action_db = action_dbs.get(action_api.id, None)
            runner_db = runner_type_dbs.get(action_api.runner_type, None)
            all_params = action_param_utils.get_params_view(action_db=action_db,
                                                            runner_db=runner_db,
                                                            merged_only=True)
            action_api.parameters = all_params

        resp.json = result
        return resp
コード例 #4
0
ファイル: action_db.py プロジェクト: ipv1337/st2
def get_runnertype_by_name(runnertype_name):
    """
        Get an runnertype by name.
        On error, raise ST2ObjectNotFoundError.
    """
    try:
        runnertypes = RunnerType.query(name=runnertype_name)
    except (ValueError, ValidationError) as e:
        LOG.error('Database lookup for name="%s" resulted in exception: %s', runnertype_name, e)
        raise StackStormDBObjectNotFoundError('Unable to find runnertype with name="%s"' % runnertype_name)

    if not runnertypes:
        raise StackStormDBObjectNotFoundError('Unable to find RunnerType with name="%s"' % runnertype_name)

    if len(runnertypes) > 1:
        LOG.warning("More than one RunnerType returned from DB lookup by name. " "Result list is: %s", runnertypes)

    return runnertypes[0]