示例#1
0
def execute(action, parameters):
    """ wrapper for inline functions

    :param action: action object ( processhandler.Action type )
    :param parameters: parameter string
    :return: status ( string )
    """
    if action.command == 'template.reload':
        # generate template
        tmpl = template.Template(action.root_dir)
        conf = config.Config(action.config)
        tmpl.set_config(conf.get())
        # XXX backwards-compat for '.' syntax, remove post-17.1
        parameters = parameters.replace('.', '/')
        filenames = tmpl.generate(parameters)

        del conf
        del tmpl

        # send generated filenames to syslog
        if filenames is not None:
            for filename in filenames:
                syslog.syslog(syslog.LOG_DEBUG,
                              ' %s generated %s' % (parameters, filename))
            return 'OK'
        else:
            return 'ERR'
    elif action.command == 'template.list':
        # traverse all installed templates and return list
        # the number of registered targets is returned between []
        tmpl = template.Template(action.root_dir)
        all_templates = tmpl.list_modules()
        retval = []
        for tag in sorted(all_templates.keys()):
            template_name = '%s [%d]' % (tag,
                                         len(all_templates[tag]['+TARGETS']))
            retval.append(template_name)

        del tmpl

        return '\n'.join(retval)
    elif action.command == 'configd.actions':
        # list all available configd actions
        from processhandler import ActionHandler
        act_handler = ActionHandler()
        actions = act_handler.list_actions(['message', 'description'])

        if unicode(parameters).lower() == 'json':
            import json
            return json.dumps(actions)
        else:
            result = []
            for action in actions:
                result.append('%s [ %s ]' %
                              (action, actions[action]['description']))

            return '\n'.join(result)

    return 'ERR'
示例#2
0
def execute(action, parameters):
    """ wrapper for inline functions

    :param action: action object ( processhandler.Action type )
    :param parameters: parameter string
    :return: status ( string )
    """
    if action.command == 'template.reload':
        # generate template
        tmpl = template.Template(action.root_dir)
        conf = config.Config(action.config)
        tmpl.set_config(conf.get())
        filenames = tmpl.generate(parameters)

        del conf
        del tmpl

        # send generated filenames to syslog
        if filenames is not None:
            for filename in filenames:
                syslog.syslog(syslog.LOG_DEBUG, ' %s generated %s' % (parameters, filename))
            return 'OK'
        else:
            return 'ERR'
    elif action.command == 'template.list':
        # traverse all installed templates and return list
        # the number of registered targets is returned between []
        tmpl = template.Template(action.root_dir)
        all_templates = tmpl.list_modules()
        retval = []
        for tag in sorted(all_templates.keys()):
            template_name = '%s [%d]' % (tag, len(all_templates[tag]['+TARGETS']))
            retval.append(template_name)

        del tmpl

        return '\n'.join(retval)
    elif action.command == 'configd.actions':
        # list all available configd actions
        from processhandler import ActionHandler
        act_handler = ActionHandler()
        actions = act_handler.list_actions(['message', 'description'])

        if unicode(parameters).lower() == 'json':
            import json
            return json.dumps(actions)
        else:
            result = []
            for action in actions:
                result.append('%s [ %s ]' % (action, actions[action]['description']))

            return '\n'.join(result)

    return 'ERR'
示例#3
0
def execute(action, parameters):
    """ wrapper for inline functions

    :param action: action object ( processhandler.Action type )
    :param parameters: parameter string
    :return: status ( string )
    """
    if action.command == 'template.reload':
        import template
        import config
        tmpl = template.Template(action.root_dir)
        conf = config.Config(action.config)
        tmpl.setConfig(conf.get())
        filenames = tmpl.generate(parameters)

        # send generated filenames to syslog
        for filename in filenames:
            syslog.syslog(syslog.LOG_DEBUG,
                          ' %s generated %s' % (parameters, filename))

        del conf
        del tmpl

        return 'OK'
    elif action.command == 'configd.actions':
        # list all available configd actions
        from processhandler import ActionHandler

        actHandler = ActionHandler()
        actions = actHandler.listActions(['message', 'description'])

        if unicode(parameters).lower() == 'json':
            import json
            return json.dumps(actions)
        else:
            result = []
            for action in actions:
                result.append('%s [ %s ]' %
                              (action, actions[action]['description']))

            return '\n'.join(result)

    return 'ERR'
示例#4
0
def execute(action, parameters):
    """ wrapper for inline functions

    :param action: action object ( processhandler.Action type )
    :param parameters: parameter string
    :return: status ( string )
    """
    if action.command == 'template.reload':
        import template
        import config
        tmpl = template.Template(action.root_dir)
        conf = config.Config(action.config)
        tmpl.setConfig(conf.get())
        filenames = tmpl.generate(parameters)

        # send generated filenames to syslog
        for filename in filenames:
            syslog.syslog(syslog.LOG_DEBUG, ' %s generated %s' % (parameters, filename))

        del conf
        del tmpl

        return 'OK'
    elif action.command == 'configd.actions':
        # list all available configd actions
        from processhandler import ActionHandler

        actHandler = ActionHandler()
        actions = actHandler.listActions(['message', 'description'])

        if unicode(parameters).lower() == 'json':
            import json
            return json.dumps(actions)
        else:
            result = []
            for action in actions:
                result.append('%s [ %s ]'%(action,actions[action]['description']))

            return '\n'.join(result)

    return 'ERR'