예제 #1
0
파일: loader.py 프로젝트: QSFT/unix-agent
def get_all_plugins(conf):
    conffile = conf.plugin_configfile
    if conffile is None or not os.path.exists(conffile):
        raise AgentPluginConfigException(
            "The plugin configuration file %s could not be found" % conffile)

    parser = configparser.SafeConfigParser()
    parser.read([conffile])
    section = parser.sections()

    all_plugins = {}
    for s in section:
        if s.startswith("plugin:"):
            try:
                items = parser.items(s)
                items_map = {}
                for i in items:
                    items_map[i[0]] = i[1]

                if "type" not in items_map:
                    _g_logger.warn("The section %s does not have an entry "
                                   "for type." % s)
                atype = items_map["type"]
                if atype not in _g_type_to_obj_map:
                    _g_logger.warn("The module type %s is not valid." % atype)
                all_plugins[s[7:]] = items_map
            except configparser.NoOptionError as conf_ex:
                raise AgentPluginConfigException(str(conf_ex))
    return all_plugins
예제 #2
0
 def __init__(self, conf, request_id, items_map, name, arguments):
     super(ExePlugin, self).__init__(conf, request_id, items_map, name,
                                     arguments)
     if 'path' not in items_map:
         raise AgentPluginConfigException(
             "The configuration for the %s plugin does not have "
             "an path entry." % name)
     exe_path = items_map['path']
     if not os.path.exists(exe_path):
         raise AgentPluginConfigException(
             "Module %s is misconfigured.  The path %s "
             "does not exists" % (name, exe_path))
     self.exe = os.path.abspath(exe_path)
     self.cwd = os.path.dirname(self.exe)
예제 #3
0
파일: loader.py 프로젝트: QSFT/unix-agent
def _load_python(conf, request_id, items_map, name, arguments):
    if 'module_name' not in items_map:
        raise AgentPluginConfigException(
            "The configuration for the %s plugin does not contain a "
            "module_name entry." % name)
    module_name = items_map['module_name']
    return load_python_module(module_name, conf, request_id, items_map, name,
                              arguments)
예제 #4
0
파일: loader.py 프로젝트: QSFT/unix-agent
def load_python_module(module_name, conf, request_id, items_map, name,
                       arguments):
    try:
        module = import_module(module_name)
        _g_logger.debug("Module acquired " + str(dir(module)))
        rc = module.load_plugin(conf, request_id, items_map, name, arguments)
        return rc
    except ImportError as iee:
        raise AgentPluginConfigException(
            "The module named %s could not be imported." % module_name, iee)
    except AttributeError as ae:
        _g_logger.exception("Could not load " + module_name)
        raise AgentPluginConfigException(
            "The module named %s does not have the load function." %
            module_name, ae)
    except:
        _g_logger.exception("An exception occurred loading the module")
        raise
예제 #5
0
파일: loader.py 프로젝트: QSFT/unix-agent
def load_plugin(conf, items_map, request_id, name, arguments):
    _g_logger.debug("ENTER load_plugin")
    type_name = items_map["type"]
    if type_name not in _g_type_to_obj_map:
        raise AgentPluginConfigException("The module type %s is not valid." %
                                         type_name)

    func = _g_type_to_obj_map[type_name]
    _g_logger.debug("calling load function")
    return func(conf, request_id, items_map, name, arguments)
예제 #6
0
파일: loader.py 프로젝트: QSFT/unix-agent
def parse_plugin_doc(conf, name):
    _g_logger.debug("ENTER load_plugin")

    conffile = conf.plugin_configfile
    if conffile is None or not os.path.exists(conffile):
        raise AgentPluginConfigException(
            "The plugin configuration file %s could not be found" % conffile)

    parser = configparser.SafeConfigParser()
    parser.read([conffile])
    section = parser.sections()

    section_name = 'plugin:' + name
    for s in section:
        p = re.compile(s + "$")
        if p.match(section_name):
            _g_logger.debug("load_plugin: found a match %s: %s" %
                            (s, section_name))

            try:
                items = parser.items(s)
                items_map = {}
                for i in items:
                    items_map[i[0]] = i[1]

                if "type" not in items_map:
                    raise AgentPluginConfigException(
                        "The section %s does not have an entry for type." %
                        section_name)
                atype = items_map["type"]
                if atype not in _g_type_to_obj_map:
                    raise AgentPluginConfigException(
                        "The module type %s is not valid." % atype)

                return items_map
            except configparser.NoOptionError as conf_ex:
                raise AgentPluginConfigException(str(conf_ex))

    raise AgentPluginConfigException("Plugin %s was not found." % name)
예제 #7
0
파일: config.py 프로젝트: QSFT/unix-agent
    def get_script_location(self, name):
        if self.storage_script_dir is not None:
            path = os.path.join(self.storage_script_dir, name)
            _g_logger.debug("Script location %s" % path)
            if not os.path.exists(path):
                raise AgentPluginConfigException(
                    "There is no proper configuration for %s" % name)
            return path

        script_dir = get_python_script_dir()
        _g_logger.debug("Script Dir %s" % script_dir)
        for platform in self.platform_script_locations:
            _g_logger.debug("Script platform %s" % platform)
            path = os.path.join(script_dir, platform, name)
            _g_logger.debug("Script location %s" % path)
            if os.path.exists(path):
                return path
        return None