本文整理汇总了Python中st2common.persistence.runner.RunnerType.query方法的典型用法代码示例。如果您正苦于以下问题:Python RunnerType.query方法的具体用法?Python RunnerType.query怎么用?Python RunnerType.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.runner.RunnerType
的用法示例。
在下文中一共展示了RunnerType.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_all
# 需要导入模块: from st2common.persistence.runner import RunnerType [as 别名]
# 或者: from st2common.persistence.runner.RunnerType import query [as 别名]
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
示例2: get_runnertype_by_name
# 需要导入模块: from st2common.persistence.runner import RunnerType [as 别名]
# 或者: from st2common.persistence.runner.RunnerType import query [as 别名]
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]