本文整理汇总了Python中st2common.models.api.action.RunnerTypeAPI.from_model方法的典型用法代码示例。如果您正苦于以下问题:Python RunnerTypeAPI.from_model方法的具体用法?Python RunnerTypeAPI.from_model怎么用?Python RunnerTypeAPI.from_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.action.RunnerTypeAPI
的用法示例。
在下文中一共展示了RunnerTypeAPI.from_model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_execution
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_basic_execution(self):
liveaction = LiveActionDB(action='executions.local', parameters={'cmd': 'uname -a'})
liveaction, _ = action_service.request(liveaction)
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(
liveaction__id=str(liveaction.id),
raise_exception=True
)
self.assertDictEqual(execution.trigger, {})
self.assertDictEqual(execution.trigger_type, {})
self.assertDictEqual(execution.trigger_instance, {})
self.assertDictEqual(execution.rule, {})
action = action_utils.get_action_by_ref('executions.local')
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
示例2: test_chained_executions
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_chained_executions(self):
with mock.patch("st2common.runners.register_runner", mock.MagicMock(return_value=action_chain_runner)):
liveaction = LiveActionDB(action="executions.chain")
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(liveaction__id=str(liveaction.id), raise_exception=True)
action = action_utils.get_action_by_ref("executions.chain")
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type["name"])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction["callback"], liveaction.callback)
self.assertEqual(execution.liveaction["action"], liveaction.action)
self.assertGreater(len(execution.children), 0)
for child in execution.children:
record = ActionExecution.get(id=child, raise_exception=True)
self.assertEqual(record.parent, str(execution.id))
self.assertEqual(record.action["name"], "local")
self.assertEqual(record.runner["name"], "run-local")
示例3: test_chained_executions
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_chained_executions(self):
liveaction = LiveActionDB(action='core.chain')
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(liveaction__id=str(liveaction.id),
raise_exception=True)
action = action_utils.get_action_by_ref('core.chain')
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
self.assertGreater(len(execution.children), 0)
for child in execution.children:
record = ActionExecution.get(id=child, raise_exception=True)
self.assertEqual(record.parent, str(execution.id))
self.assertEqual(record.action['name'], 'local')
self.assertEqual(record.runner['name'], 'run-local')
示例4: put
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def put(self, runner_type_api, name_or_id, requester_user):
# Note: We only allow "enabled" attribute of the runner to be changed
runner_type_db = self._get_by_name_or_id(name_or_id=name_or_id)
permission_type = PermissionType.RUNNER_MODIFY
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=runner_type_db,
permission_type=permission_type)
old_runner_type_db = runner_type_db
LOG.debug('PUT /runnertypes/ lookup with id=%s found object: %s', name_or_id,
runner_type_db)
try:
if runner_type_api.id and runner_type_api.id != name_or_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
runner_type_api.id, name_or_id)
runner_type_db.enabled = runner_type_api.enabled
runner_type_db = RunnerType.add_or_update(runner_type_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for runner type data=%s', runner_type_api)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_runner_type_db': old_runner_type_db, 'new_runner_type_db': runner_type_db}
LOG.audit('Runner Type updated. RunnerType.id=%s.' % (runner_type_db.id), extra=extra)
runner_type_api = RunnerTypeAPI.from_model(runner_type_db)
return runner_type_api
示例5: test_execution_creation_action_triggered_by_rule
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_execution_creation_action_triggered_by_rule(self):
# Wait for the action execution to complete and then confirm outcome.
trigger_type = self.MODELS['triggertypes']['triggertype2.yaml']
trigger = self.MODELS['triggers']['trigger2.yaml']
trigger_instance = self.MODELS['triggerinstances']['trigger_instance_1.yaml']
test_liveaction = self.FIXTURES['liveactions']['liveaction3.yaml']
rule = self.MODELS['rules']['rule3.yaml']
# Setup LiveAction to point to right rule and trigger_instance.
# XXX: We need support for dynamic fixtures.
test_liveaction['context']['rule']['id'] = str(rule.id)
test_liveaction['context']['trigger_instance']['id'] = str(trigger_instance.id)
test_liveaction_api = LiveActionAPI(**test_liveaction)
test_liveaction = LiveAction.add_or_update(LiveActionAPI.to_model(test_liveaction_api))
liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
self.assertIsNotNone(liveaction)
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_REQUESTED)
executions_util.create_execution_object(liveaction)
execution = self._get_action_execution(liveaction__id=str(liveaction.id),
raise_exception=True)
self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
self.assertDictEqual(execution.trigger_instance,
vars(TriggerInstanceAPI.from_model(trigger_instance)))
self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
action = action_utils.get_action_by_ref(liveaction.action)
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEquals(execution.liveaction['id'], str(liveaction.id))
示例6: get_one
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def get_one(self, id):
"""
List RunnerType objects by id.
Handle:
GET /runnertypes/1
"""
runnertype_db = RunnerTypesController.__get_by_id(id)
runnertype_api = RunnerTypeAPI.from_model(runnertype_db)
return runnertype_api
示例7: create_execution_object
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def create_execution_object(liveaction, action_db=None, runnertype_db=None, publish=True):
if not action_db:
action_db = action_utils.get_action_by_ref(liveaction.action)
if not runnertype_db:
runnertype_db = RunnerType.get_by_name(action_db.runner_type['name'])
attrs = {
'action': vars(ActionAPI.from_model(action_db)),
'parameters': liveaction['parameters'],
'runner': vars(RunnerTypeAPI.from_model(runnertype_db))
}
attrs.update(_decompose_liveaction(liveaction))
if 'rule' in liveaction.context:
rule = reference.get_model_from_ref(Rule, liveaction.context.get('rule', {}))
attrs['rule'] = vars(RuleAPI.from_model(rule))
if 'trigger_instance' in liveaction.context:
trigger_instance_id = liveaction.context.get('trigger_instance', {})
trigger_instance_id = trigger_instance_id.get('id', None)
trigger_instance = TriggerInstance.get_by_id(trigger_instance_id)
trigger = reference.get_model_by_resource_ref(db_api=Trigger,
ref=trigger_instance.trigger)
trigger_type = reference.get_model_by_resource_ref(db_api=TriggerType,
ref=trigger.type)
trigger_instance = reference.get_model_from_ref(
TriggerInstance, liveaction.context.get('trigger_instance', {}))
attrs['trigger_instance'] = vars(TriggerInstanceAPI.from_model(trigger_instance))
attrs['trigger'] = vars(TriggerAPI.from_model(trigger))
attrs['trigger_type'] = vars(TriggerTypeAPI.from_model(trigger_type))
parent = _get_parent_execution(liveaction)
if parent:
attrs['parent'] = str(parent.id)
attrs['log'] = [_create_execution_log_entry(liveaction['status'])]
# TODO: This object initialization takes 20-30or so ms
execution = ActionExecutionDB(**attrs)
# TODO: Do 100% research this is fully safe and unique in distributed setups
execution.id = ObjectId()
execution.web_url = _get_web_url_for_execution(str(execution.id))
# NOTE: User input data is already validate as part of the API request,
# other data is set by us. Skipping validation here makes operation 10%-30% faster
execution = ActionExecution.add_or_update(execution, publish=publish, validate=False)
if parent and str(execution.id) not in parent.children:
values = {}
values['push__children'] = str(execution.id)
ActionExecution.update(parent, **values)
return execution
示例8: get_all
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def get_all(self, **kw):
"""
List all RunnerType objects.
Handles requests:
GET /runnertypes/
"""
runnertype_dbs = RunnerType.get_all(**kw)
runnertype_apis = [RunnerTypeAPI.from_model(runnertype_db)
for runnertype_db in runnertype_dbs]
return runnertype_apis
示例9: get_one
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def get_one(self, id):
"""
List RunnerType objects by id.
Handle:
GET /runnertypes/1
"""
LOG.info('GET /runnertypes/ with id=%s', id)
runnertype_db = RunnerTypesController.__get_by_id(id)
runnertype_api = RunnerTypeAPI.from_model(runnertype_db)
LOG.debug('GET /runnertypes/ with id=%s, client_result=%s', id, runnertype_api)
return runnertype_api
示例10: get_all
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def get_all(self, **kw):
"""
List all RunnerType objects.
Handles requests:
GET /runnertypes/
"""
LOG.info('GET all /runnertypes/ with filters=%s', kw)
runnertype_dbs = RunnerType.get_all(**kw)
runnertype_apis = [RunnerTypeAPI.from_model(runnertype_db)
for runnertype_db in runnertype_dbs]
LOG.debug('GET all /runnertypes/ client_result=%s', runnertype_apis)
return runnertype_apis
示例11: create_execution_object
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def create_execution_object(liveaction, publish=True):
action_db = action_utils.get_action_by_ref(liveaction.action)
runner = RunnerType.get_by_name(action_db.runner_type['name'])
attrs = {
'action': vars(ActionAPI.from_model(action_db)),
'parameters': liveaction['parameters'],
'runner': vars(RunnerTypeAPI.from_model(runner))
}
attrs.update(_decompose_liveaction(liveaction))
if 'rule' in liveaction.context:
rule = reference.get_model_from_ref(Rule, liveaction.context.get('rule', {}))
attrs['rule'] = vars(RuleAPI.from_model(rule))
if 'trigger_instance' in liveaction.context:
trigger_instance_id = liveaction.context.get('trigger_instance', {})
trigger_instance_id = trigger_instance_id.get('id', None)
trigger_instance = TriggerInstance.get_by_id(trigger_instance_id)
trigger = reference.get_model_by_resource_ref(db_api=Trigger,
ref=trigger_instance.trigger)
trigger_type = reference.get_model_by_resource_ref(db_api=TriggerType,
ref=trigger.type)
trigger_instance = reference.get_model_from_ref(
TriggerInstance, liveaction.context.get('trigger_instance', {}))
attrs['trigger_instance'] = vars(TriggerInstanceAPI.from_model(trigger_instance))
attrs['trigger'] = vars(TriggerAPI.from_model(trigger))
attrs['trigger_type'] = vars(TriggerTypeAPI.from_model(trigger_type))
parent = _get_parent_execution(liveaction)
if parent:
attrs['parent'] = str(parent.id)
attrs['log'] = [_create_execution_log_entry(liveaction['status'])]
execution = ActionExecutionDB(**attrs)
execution = ActionExecution.add_or_update(execution, publish=False)
# Update the web_url field in execution. Unfortunately, we need
# the execution id for constructing the URL which we only get
# after the model is written to disk.
execution.web_url = _get_web_url_for_execution(str(execution.id))
execution = ActionExecution.add_or_update(execution, publish=publish)
if parent:
if str(execution.id) not in parent.children:
parent.children.append(str(execution.id))
ActionExecution.add_or_update(parent)
return execution
示例12: test_triggered_execution
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_triggered_execution(self):
docs = {
'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance'])}
# Trigger an action execution.
trigger_type = TriggerType.add_or_update(
TriggerTypeAPI.to_model(TriggerTypeAPI(**docs['trigger_type'])))
trigger = Trigger.add_or_update(TriggerAPI.to_model(TriggerAPI(**docs['trigger'])))
rule = RuleAPI.to_model(RuleAPI(**docs['rule']))
rule.trigger = reference.get_str_resource_ref_from_model(trigger)
rule = Rule.add_or_update(rule)
trigger_instance = TriggerInstance.add_or_update(
TriggerInstanceAPI.to_model(TriggerInstanceAPI(**docs['trigger_instance'])))
trace_service.add_or_update_given_trace_context(
trace_context={'trace_tag': 'test_triggered_execution_trace'},
trigger_instances=[str(trigger_instance.id)])
enforcer = RuleEnforcer(trigger_instance, rule)
enforcer.enforce()
# Wait for the action execution to complete and then confirm outcome.
liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
self.assertIsNotNone(liveaction)
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(
liveaction__id=str(liveaction.id),
raise_exception=True
)
self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
self.assertDictEqual(execution.trigger_instance,
vars(TriggerInstanceAPI.from_model(trigger_instance)))
self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
action = action_utils.get_action_by_ref(liveaction.action)
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
示例13: test_execution_creation_manual_action_run
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_execution_creation_manual_action_run(self):
liveaction = self.MODELS['liveactions']['liveaction1.yaml']
executions_util.create_execution_object(liveaction)
execution = self._get_action_execution(liveaction__id=str(liveaction.id),
raise_exception=True)
self.assertDictEqual(execution.trigger, {})
self.assertDictEqual(execution.trigger_type, {})
self.assertDictEqual(execution.trigger_instance, {})
self.assertDictEqual(execution.rule, {})
action = action_utils.get_action_by_ref('core.local')
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEquals(execution.liveaction['id'], str(liveaction.id))
示例14: record_action_execution
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def record_action_execution(self, body):
try:
history_id = bson.ObjectId()
execution = ActionExecution.get_by_id(str(body.id))
action_ref = ResourceReference.from_string_reference(ref=execution.action)
action_db, _ = action_utils.get_action_by_dict(
{'name': action_ref.name,
'pack': action_ref.pack})
runner = RunnerType.get_by_name(action_db.runner_type['name'])
attrs = {
'id': history_id,
'action': vars(ActionAPI.from_model(action_db)),
'runner': vars(RunnerTypeAPI.from_model(runner)),
'execution': vars(ActionExecutionAPI.from_model(execution))
}
if 'rule' in execution.context:
rule = reference.get_model_from_ref(Rule, execution.context.get('rule', {}))
attrs['rule'] = vars(RuleAPI.from_model(rule))
if 'trigger_instance' in execution.context:
trigger_instance_id = execution.context.get('trigger_instance', {})
trigger_instance_id = trigger_instance_id.get('id', None)
trigger_instance = TriggerInstance.get_by_id(trigger_instance_id)
trigger = reference.get_model_by_resource_ref(db_api=Trigger,
ref=trigger_instance.trigger)
trigger_type = reference.get_model_by_resource_ref(db_api=TriggerType,
ref=trigger.type)
trigger_instance = reference.get_model_from_ref(
TriggerInstance, execution.context.get('trigger_instance', {}))
attrs['trigger_instance'] = vars(TriggerInstanceAPI.from_model(trigger_instance))
attrs['trigger'] = vars(TriggerAPI.from_model(trigger))
attrs['trigger_type'] = vars(TriggerTypeAPI.from_model(trigger_type))
parent = ActionExecutionHistory.get(execution__id=execution.context.get('parent', ''))
if parent:
attrs['parent'] = str(parent.id)
if str(history_id) not in parent.children:
parent.children.append(str(history_id))
ActionExecutionHistory.add_or_update(parent)
history = ActionExecutionHistoryDB(**attrs)
history = ActionExecutionHistory.add_or_update(history)
except:
LOG.exception('An unexpected error occurred while creating the '
'action execution history.')
raise
示例15: test_basic_execution
# 需要导入模块: from st2common.models.api.action import RunnerTypeAPI [as 别名]
# 或者: from st2common.models.api.action.RunnerTypeAPI import from_model [as 别名]
def test_basic_execution(self):
action_ref = ResourceReference(name='local', pack='core')
execution = ActionExecutionDB(action=action_ref.ref, parameters={'cmd': 'uname -a'})
execution = action_service.schedule(execution)
execution = ActionExecution.get_by_id(str(execution.id))
self.assertEqual(execution.status, ACTIONEXEC_STATUS_SUCCEEDED)
history = ActionExecutionHistory.get(execution__id=str(execution.id), raise_exception=True)
self.assertDictEqual(history.trigger, {})
self.assertDictEqual(history.trigger_type, {})
self.assertDictEqual(history.trigger_instance, {})
self.assertDictEqual(history.rule, {})
action, _ = action_utils.get_action_by_dict(
{'name': action_ref.name, 'pack': action_ref.pack})
self.assertDictEqual(history.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(history.runner, vars(RunnerTypeAPI.from_model(runner)))
execution = ActionExecution.get_by_id(str(execution.id))
self.assertDictEqual(history.execution, vars(ActionExecutionAPI.from_model(execution)))