本文整理汇总了Python中st2common.models.api.action.ActionAPI.to_model方法的典型用法代码示例。如果您正苦于以下问题:Python ActionAPI.to_model方法的具体用法?Python ActionAPI.to_model怎么用?Python ActionAPI.to_model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.models.api.action.ActionAPI
的用法示例。
在下文中一共展示了ActionAPI.to_model方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestActionExecutionHistoryWorker, cls).setUpClass()
runners_registrar.register_runner_types()
action_local = ActionAPI(**copy.deepcopy(fixture.ARTIFACTS['actions']['local']))
Action.add_or_update(ActionAPI.to_model(action_local))
action_chain = ActionAPI(**copy.deepcopy(fixture.ARTIFACTS['actions']['chain']))
action_chain.entry_point = fixture.PATH + '/chain.yaml'
Action.add_or_update(ActionAPI.to_model(action_chain))
示例2: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestActionExecutionHistoryWorker, cls).setUpClass()
runners_registrar.register_runners()
action_local = ActionAPI(**copy.deepcopy(fixture.ARTIFACTS["actions"]["local"]))
Action.add_or_update(ActionAPI.to_model(action_local))
action_chain = ActionAPI(**copy.deepcopy(fixture.ARTIFACTS["actions"]["chain"]))
action_chain.entry_point = fixture.PATH + "/chain.yaml"
Action.add_or_update(ActionAPI.to_model(action_chain))
示例3: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestMistralRunner, cls).setUpClass()
runners_registrar.register_runner_types()
metadata = fixture.ARTIFACTS['metadata']
action_local = ActionAPI(**copy.deepcopy(metadata['actions']['local']))
Action.add_or_update(ActionAPI.to_model(action_local))
action_wkflow = ActionAPI(**copy.deepcopy(metadata['actions']['workflow-v2']))
Action.add_or_update(ActionAPI.to_model(action_wkflow))
示例4: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(DSLTransformTestCase, cls).setUpClass()
runners_registrar.register_runner_types()
action_local = ActionAPI(**copy.deepcopy(FIXTURES['actions']['local.yaml']))
Action.add_or_update(ActionAPI.to_model(action_local))
for action_name in ['action1', 'action2', 'action3']:
metadata = copy.deepcopy(FIXTURES['actions']['local.yaml'])
metadata['name'] = action_name
metadata['pack'] = 'demo'
action = ActionAPI(**metadata)
Action.add_or_update(ActionAPI.to_model(action))
示例5: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(ExecutionCancellationTestCase, cls).setUpClass()
for _, fixture in six.iteritems(FIXTURES['actions']):
instance = ActionAPI(**fixture)
Action.add_or_update(ActionAPI.to_model(instance))
runners_registrar.register_runners()
示例6: put
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def put(self, action_ref_or_id, action):
action_db = self._get_by_ref_or_id(ref_or_id=action_ref_or_id)
action_id = action_db.id
try:
validate_not_part_of_system_pack(action_db)
except ValueValidationException as e:
abort(http_client.BAD_REQUEST, str(e))
if not getattr(action, 'pack', None):
action.pack = action_db.pack
try:
action_validator.validate_action(action)
except ValueValidationException as e:
abort(http_client.BAD_REQUEST, str(e))
return
try:
action_db = ActionAPI.to_model(action)
action_db.id = action_id
action_db = Action.add_or_update(action_db)
except (ValidationError, ValueError) as e:
LOG.exception('Unable to update action data=%s', action)
abort(http_client.BAD_REQUEST, str(e))
return
action_api = ActionAPI.from_model(action_db)
LOG.debug('PUT /actions/ client_result=%s', action_api)
return action_api
示例7: post
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def post(self, action):
"""
Create a new action.
Handles requests:
POST /actions/
"""
if not hasattr(action, 'pack'):
setattr(action, 'pack', DEFAULT_PACK_NAME)
try:
action_validator.validate_action(action)
except ValueValidationException as e:
abort(http_client.BAD_REQUEST, str(e))
return
# ActionsController._validate_action_parameters(action, runnertype_db)
action_model = ActionAPI.to_model(action)
LOG.debug('/actions/ POST verified ActionAPI object=%s', action)
action_db = Action.add_or_update(action_model)
LOG.debug('/actions/ POST saved ActionDB object=%s', action_db)
extra = {'action_db': action_db}
LOG.audit('Action created. Action.id=%s' % (action_db.id), extra=extra)
action_api = ActionAPI.from_model(action_db)
return action_api
示例8: post
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def post(self, action):
"""
Create a new action.
Handles requests:
POST /actions/
"""
# Perform validation
validate_not_part_of_system_pack(action)
action_validator.validate_action(action)
# Write pack data files to disk (if any are provided)
data_files = getattr(action, 'data_files', [])
written_data_files = []
if data_files:
written_data_files = self._handle_data_files(pack_name=action.pack,
data_files=data_files)
action_model = ActionAPI.to_model(action)
LOG.debug('/actions/ POST verified ActionAPI object=%s', action)
action_db = Action.add_or_update(action_model)
LOG.debug('/actions/ POST saved ActionDB object=%s', action_db)
# Dispatch an internal trigger for each written data file. This way user
# automate comitting this files to git using StackStorm rule
if written_data_files:
self._dispatch_trigger_for_written_data_files(action_db=action_db,
written_data_files=written_data_files)
extra = {'acion_db': action_db}
LOG.audit('Action created. Action.id=%s' % (action_db.id), extra=extra)
action_api = ActionAPI.from_model(action_db)
return action_api
示例9: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestActionExecutionService, cls).setUpClass()
cls.runner = RunnerTypeAPI(**RUNNER)
cls.runnerdb = RunnerType.add_or_update(RunnerTypeAPI.to_model(cls.runner))
cls.action = ActionAPI(**ACTION)
cls.actiondb = Action.add_or_update(ActionAPI.to_model(cls.action))
cls.container = RunnerContainer()
示例10: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestMistralRunner, cls).setUpClass()
runners_registrar.register_runner_types()
for _, fixture in six.iteritems(FIXTURES['actions']):
instance = ActionAPI(**fixture)
Action.add_or_update(ActionAPI.to_model(instance))
示例11: _register_action
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def _register_action(self, pack, action):
content = self._meta_loader.load(action)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
action_api = ActionAPI(**content)
action_api.validate()
action_validator.validate_action(action_api)
model = ActionAPI.to_model(action_api)
action_ref = ResourceReference.to_string_reference(pack=pack, name=str(content['name']))
existing = action_utils.get_action_by_ref(action_ref)
if not existing:
LOG.debug('Action %s not found. Creating new one with: %s', action_ref, content)
else:
LOG.debug('Action %s found. Will be updated from: %s to: %s',
action_ref, existing, model)
model.id = existing.id
try:
model = Action.add_or_update(model)
extra = {'action_db': model}
LOG.audit('Action updated. Action %s from %s.', model, action, extra=extra)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise
示例12: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(TestStreamController, cls).setUpClass()
instance = RunnerTypeAPI(**RUNNER_TYPE_1)
RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))
instance = ActionAPI(**ACTION_1)
Action.add_or_update(ActionAPI.to_model(instance))
示例13: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(DSLTransformTestCase, cls).setUpClass()
for _, fixture in six.iteritems(FIXTURES['runners']):
instance = RunnerTypeAPI(**fixture)
RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))
for _, fixture in six.iteritems(FIXTURES['actions']):
instance = ActionAPI(**fixture)
Action.add_or_update(ActionAPI.to_model(instance))
示例14: setUpClass
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def setUpClass(cls):
super(MistralValidationControllerTest, cls).setUpClass()
for _, fixture in six.iteritems(FIXTURES['runners']):
instance = RunnerTypeAPI(**fixture)
RunnerType.add_or_update(RunnerTypeAPI.to_model(instance))
for _, fixture in six.iteritems(FIXTURES['actions']):
instance = ActionAPI(**fixture)
Action.add_or_update(ActionAPI.to_model(instance))
示例15: _register_action
# 需要导入模块: from st2common.models.api.action import ActionAPI [as 别名]
# 或者: from st2common.models.api.action.ActionAPI import to_model [as 别名]
def _register_action(self, pack, action):
content = self._meta_loader.load(action)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
action_api = ActionAPI(**content)
try:
action_api.validate()
except jsonschema.ValidationError as e:
# We throw a more user-friendly exception on invalid parameter name
msg = str(e)
is_invalid_parameter_name = 'does not match any of the regexes: ' in msg
if is_invalid_parameter_name:
match = re.search('\'(.+?)\' does not match any of the regexes', msg)
if match:
parameter_name = match.groups()[0]
else:
parameter_name = 'unknown'
new_msg = ('Parameter name "%s" is invalid. Valid characters for parameter name '
'are [a-zA-Z0-0_].' % (parameter_name))
new_msg += '\n\n' + msg
raise jsonschema.ValidationError(new_msg)
raise e
action_validator.validate_action(action_api)
model = ActionAPI.to_model(action_api)
action_ref = ResourceReference.to_string_reference(pack=pack, name=str(content['name']))
existing = action_utils.get_action_by_ref(action_ref)
if not existing:
LOG.debug('Action %s not found. Creating new one with: %s', action_ref, content)
else:
LOG.debug('Action %s found. Will be updated from: %s to: %s',
action_ref, existing, model)
model.id = existing.id
try:
model = Action.add_or_update(model)
extra = {'action_db': model}
LOG.audit('Action updated. Action %s from %s.', model, action, extra=extra)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise