当前位置: 首页>>代码示例>>Python>>正文


Python ActionAlias.get_by_name方法代码示例

本文整理汇总了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
开发者ID:ruslantum,项目名称:st2,代码行数:29,代码来源:aliasesregistrar.py

示例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)
开发者ID:SamMarkowitz,项目名称:st2,代码行数:35,代码来源:aliasexecution.py

示例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
开发者ID:Bala96,项目名称:st2,代码行数:60,代码来源:aliasexecution.py

示例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
开发者ID:rlugojr,项目名称:st2,代码行数:17,代码来源:aliasesregistrar.py

示例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
开发者ID:MohammadHabbab,项目名称:st2,代码行数:18,代码来源:aliasesregistrar.py

示例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)
开发者ID:agilee,项目名称:st2,代码行数:44,代码来源:aliasexecution.py

示例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
开发者ID:nzlosh,项目名称:st2,代码行数:26,代码来源:aliasesregistrar.py

示例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
开发者ID:nzlosh,项目名称:st2,代码行数:96,代码来源:aliasexecution.py


注:本文中的st2common.persistence.actionalias.ActionAlias.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。