in osbenchmark/builder/provision_config.py [0:0]
def load_plugin(self, name, config_names, plugin_params=None):
if config_names is not None:
self.logger.info("Loading plugin [%s] with configuration(s) [%s].", name, config_names)
else:
self.logger.info("Loading plugin [%s] with default configuration.", name)
root_path = self._plugin_root_path(name)
# used to determine whether this is a core plugin
core_plugin = self._core_plugin(name)
if not config_names:
# maybe we only have a config folder but nothing else (e.g. if there is only an install hook)
if io.exists(root_path):
return PluginDescriptor(name=name,
core_plugin=core_plugin is not None,
config=config_names,
root_path=root_path,
variables=plugin_params)
else:
if core_plugin:
return core_plugin
# If we just have a plugin name then we assume that this is a community plugin and the user has specified a download URL
else:
self.logger.info("The plugin [%s] is neither a configured nor an official plugin. Assuming that this is a community "
"plugin not requiring any configuration and you have set a proper download URL.", name)
return PluginDescriptor(name, variables=plugin_params)
else:
variables = {}
config_paths = []
# used for deduplication
known_config_bases = set()
for config_name in config_names:
config_file = self._plugin_file(name, config_name)
# Do we have an explicit configuration for this plugin?
if not io.exists(config_file):
if core_plugin:
raise exceptions.SystemSetupError("Plugin [%s] does not provide configuration [%s]. List the available plugins "
"and configurations with %s list opensearch-plugins "
"--distribution-version=VERSION." % (name, config_name, PROGRAM_NAME))
else:
raise exceptions.SystemSetupError("Unknown plugin [%s]. List the available plugins with %s list "
"opensearch-plugins --distribution-version=VERSION." % (name, PROGRAM_NAME))
config = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation())
# Do not modify the case of option keys but read them as is
config.optionxform = lambda option: option
config.read(config_file)
if "config" in config and "base" in config["config"]:
config_bases = config["config"]["base"].split(",")
for base in config_bases:
if base and base not in known_config_bases:
config_paths.append(os.path.join(root_path, base, "templates"))
known_config_bases.add(base)
if "variables" in config.sections():
for k, v in config["variables"].items():
variables[k] = v
# add all plugin params here to override any defaults
if plugin_params:
variables.update(plugin_params)
# maybe one of the configs is really just for providing variables. However, we still require one config base overall.
if len(config_paths) == 0:
raise exceptions.SystemSetupError("At least one config base is required for plugin [%s]" % name)
return PluginDescriptor(name=name, core_plugin=core_plugin is not None, config=config_names, root_path=root_path,
config_paths=config_paths, variables=variables)