本文整理汇总了Python中st2common.persistence.actionalias.ActionAlias.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python ActionAlias.get_by_name方法的具体用法?Python ActionAlias.get_by_name怎么用?Python ActionAlias.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.actionalias.ActionAlias
的用法示例。
在下文中一共展示了ActionAlias.get_by_name方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_action_alias
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def _register_action_alias(self, pack, action_alias):
content = self._meta_loader.load(action_alias)
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_alias_api = ActionAliasAPI(**content)
action_alias_api.validate()
action_alias_db = ActionAliasAPI.to_model(action_alias_api)
try:
action_alias_db.id = ActionAlias.get_by_name(action_alias_api.name).id
except ValueError:
LOG.info('ActionAlias %s not found. Creating new one.', action_alias)
try:
action_alias_db = ActionAlias.add_or_update(action_alias_db)
extra = {'action_alias_db': action_alias_db}
LOG.audit('Action alias updated. Action alias %s from %s.', action_alias_db,
action_alias, extra=extra)
except Exception:
LOG.exception('Failed to create action alias %s.', action_alias_api.name)
raise
示例2: post
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def post(self, payload):
action_alias_name = payload.name if payload else None
if not action_alias_name:
pecan.abort(http_client.BAD_REQUEST, 'Alias execution "name" is required')
format = payload.format or ''
command = payload.command or ''
try:
action_alias_db = ActionAlias.get_by_name(action_alias_name)
except ValueError:
action_alias_db = None
if not action_alias_db:
msg = 'Unable to identify action alias with name "%s".' % (action_alias_name)
pecan.abort(http_client.NOT_FOUND, msg)
return
if not action_alias_db.enabled:
msg = 'Action alias with name "%s" is disabled.' % (action_alias_name)
pecan.abort(http_client.BAD_REQUEST, msg)
return
execution_parameters = self._extract_parameters(action_alias_db=action_alias_db,
format=format,
param_stream=command)
notify = self._get_notify_field(payload)
execution = self._schedule_execution(action_alias_db=action_alias_db,
params=execution_parameters,
notify=notify)
return str(execution.id)
示例3: post
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def post(self, payload):
action_alias_name = payload.name if payload else None
if not action_alias_name:
pecan.abort(http_client.BAD_REQUEST, 'Alias execution "name" is required')
format_str = payload.format or ''
command = payload.command or ''
try:
action_alias_db = ActionAlias.get_by_name(action_alias_name)
except ValueError:
action_alias_db = None
if not action_alias_db:
msg = 'Unable to identify action alias with name "%s".' % (action_alias_name)
pecan.abort(http_client.NOT_FOUND, msg)
return
if not action_alias_db.enabled:
msg = 'Action alias with name "%s" is disabled.' % (action_alias_name)
pecan.abort(http_client.BAD_REQUEST, msg)
return
execution_parameters = extract_parameters_for_action_alias_db(
action_alias_db=action_alias_db,
format_str=format_str,
param_stream=command)
notify = self._get_notify_field(payload)
context = {
'action_alias_ref': reference.get_ref_from_model(action_alias_db),
'api_user': payload.user,
'user': get_requester(),
'source_channel': payload.source_channel
}
execution = self._schedule_execution(action_alias_db=action_alias_db,
params=execution_parameters,
notify=notify,
context=context)
result = {
'execution': execution,
'actionalias': ActionAliasAPI.from_model(action_alias_db)
}
if action_alias_db.ack:
if 'format' in action_alias_db.ack:
result.update({
'message': render({'alias': action_alias_db.ack['format']}, result)['alias']
})
if 'extra' in action_alias_db.ack:
result.update({
'extra': render(action_alias_db.ack['extra'], result)
})
return result
示例4: _register_action_alias
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def _register_action_alias(self, pack, action_alias):
action_alias_db = self._get_action_alias_db(pack=pack, action_alias=action_alias)
try:
action_alias_db.id = ActionAlias.get_by_name(action_alias_db.name).id
except StackStormDBObjectNotFoundError:
LOG.debug("ActionAlias %s not found. Creating new one.", action_alias)
try:
action_alias_db = ActionAlias.add_or_update(action_alias_db)
extra = {"action_alias_db": action_alias_db}
LOG.audit("Action alias updated. Action alias %s from %s.", action_alias_db, action_alias, extra=extra)
except Exception:
LOG.exception("Failed to create action alias %s.", action_alias_db.name)
raise
示例5: _register_action_alias
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def _register_action_alias(self, pack, action_alias):
action_alias_db = self._get_action_alias_db(pack=pack, action_alias=action_alias)
try:
action_alias_db.id = ActionAlias.get_by_name(action_alias_db.name).id
except ValueError:
LOG.debug('ActionAlias %s not found. Creating new one.', action_alias)
try:
action_alias_db = ActionAlias.add_or_update(action_alias_db)
extra = {'action_alias_db': action_alias_db}
LOG.audit('Action alias updated. Action alias %s from %s.', action_alias_db,
action_alias, extra=extra)
except Exception:
LOG.exception('Failed to create action alias %s.', action_alias_db.name)
raise
示例6: post
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def post(self, payload):
action_alias_name = payload.name if payload else None
if not action_alias_name:
pecan.abort(http_client.BAD_REQUEST, 'Alias execution "name" is required')
format_str = payload.format or ''
command = payload.command or ''
try:
action_alias_db = ActionAlias.get_by_name(action_alias_name)
except ValueError:
action_alias_db = None
if not action_alias_db:
msg = 'Unable to identify action alias with name "%s".' % (action_alias_name)
pecan.abort(http_client.NOT_FOUND, msg)
return
if not action_alias_db.enabled:
msg = 'Action alias with name "%s" is disabled.' % (action_alias_name)
pecan.abort(http_client.BAD_REQUEST, msg)
return
execution_parameters = self._extract_parameters(action_alias_db=action_alias_db,
format_str=format_str,
param_stream=command)
notify = self._get_notify_field(payload)
context = {
'action_alias_ref': reference.get_ref_from_model(action_alias_db),
'api_user': payload.user,
'user': get_system_username(),
'source_channel': payload.source_channel
}
execution = self._schedule_execution(action_alias_db=action_alias_db,
params=execution_parameters,
notify=notify,
context=context)
return str(execution.id)
示例7: _register_action_alias
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def _register_action_alias(self, pack, action_alias):
action_alias_db = self._get_action_alias_db(pack=pack,
action_alias=action_alias)
try:
action_alias_db.id = ActionAlias.get_by_name(action_alias_db.name).id
except StackStormDBObjectNotFoundError:
LOG.debug('ActionAlias %s not found. Creating new one.', action_alias)
action_ref = action_alias_db.action_ref
action_db = Action.get_by_ref(action_ref)
if not action_db:
LOG.warning('Action %s not found in DB. Did you forget to register the action?',
action_ref)
try:
action_alias_db = ActionAlias.add_or_update(action_alias_db)
extra = {'action_alias_db': action_alias_db}
LOG.audit('Action alias updated. Action alias %s from %s.', action_alias_db,
action_alias, extra=extra)
except Exception:
LOG.exception('Failed to create action alias %s.', action_alias_db.name)
raise
示例8: _post
# 需要导入模块: from st2common.persistence.actionalias import ActionAlias [as 别名]
# 或者: from st2common.persistence.actionalias.ActionAlias import get_by_name [as 别名]
def _post(self, payload, requester_user, show_secrets=False, match_multiple=False):
action_alias_name = payload.name if payload else None
if not action_alias_name:
abort(http_client.BAD_REQUEST, 'Alias execution "name" is required')
return
if not requester_user:
requester_user = UserDB(cfg.CONF.system_user.user)
format_str = payload.format or ''
command = payload.command or ''
try:
action_alias_db = ActionAlias.get_by_name(action_alias_name)
except ValueError:
action_alias_db = None
if not action_alias_db:
msg = 'Unable to identify action alias with name "%s".' % (action_alias_name)
abort(http_client.NOT_FOUND, msg)
return
if not action_alias_db.enabled:
msg = 'Action alias with name "%s" is disabled.' % (action_alias_name)
abort(http_client.BAD_REQUEST, msg)
return
if match_multiple:
multiple_execution_parameters = extract_parameters_for_action_alias_db(
action_alias_db=action_alias_db,
format_str=format_str,
param_stream=command,
match_multiple=match_multiple)
else:
multiple_execution_parameters = [
extract_parameters_for_action_alias_db(
action_alias_db=action_alias_db,
format_str=format_str,
param_stream=command,
match_multiple=match_multiple)
]
notify = self._get_notify_field(payload)
context = {
'action_alias_ref': reference.get_ref_from_model(action_alias_db),
'api_user': payload.user,
'user': requester_user.name,
'source_channel': payload.source_channel
}
results = []
for execution_parameters in multiple_execution_parameters:
execution = self._schedule_execution(action_alias_db=action_alias_db,
params=execution_parameters,
notify=notify,
context=context,
show_secrets=show_secrets,
requester_user=requester_user)
result = {
'execution': execution,
'actionalias': ActionAliasAPI.from_model(action_alias_db)
}
if action_alias_db.ack:
try:
if 'format' in action_alias_db.ack:
message = render({'alias': action_alias_db.ack['format']}, result)['alias']
result.update({
'message': message
})
except UndefinedError as e:
result.update({
'message': ('Cannot render "format" in field "ack" for alias. ' +
six.text_type(e))
})
try:
if 'extra' in action_alias_db.ack:
result.update({
'extra': render(action_alias_db.ack['extra'], result)
})
except UndefinedError as e:
result.update({
'extra': ('Cannot render "extra" in field "ack" for alias. ' +
six.text_type(e))
})
results.append(result)
return results