1
0
Fork 0

Allow loading two profiles using tuned -c profile1 -c profile2

This commit is contained in:
HanzZ 2012-05-07 09:17:14 +02:00
parent 8513371946
commit d2800cbf55
3 changed files with 23 additions and 10 deletions

View file

@ -45,7 +45,7 @@ if __name__ == "__main__":
usage()
sys.exit(1)
config_file = None
config_file = []
daemon = False
debug = False
@ -53,7 +53,7 @@ if __name__ == "__main__":
if opt in ['-d', "--daemon"]:
daemon = True
elif opt in ['-c', "--config"]:
config_file = val
config_file.append(val)
elif opt in ['-D', "--debug"]:
debug = True

View file

@ -77,8 +77,11 @@ class Daemon(object):
@config_file.setter
def config_file(self, value):
if not os.path.exists(value):
raise ValueError("Config file does not exist")
if not isinstance(value, list):
value = [value]
for cfg in value:
if not os.path.exists(cfg):
raise ValueError("Config file %s does not exist" % (cfg))
self._config_file = value
# TODO: Maybe restart the daemon here?

View file

@ -39,9 +39,6 @@ class Profile(object):
@classmethod
def find_profile(cls, name):
if name.startswith("/"):
return name
profile = "/etc/tuned/%s/tuned.conf" % (name)
if os.path.exists(profile):
return profile
@ -106,13 +103,17 @@ class Profile(object):
break
else:
log.debug("Merging plugin %s with %s" % (name, plugin))
plugin_cfg.update(cfg)
tmp_cfg = cfg
tmp_cfg.update(plugin_cfg)
plugin_cfg = tmp_cfg
plugins_to_remove.append(plugin)
for plugin in plugins_to_remove:
log.debug("Removing plugin %s because it is useless after merge" % (plugin))
del self._plugin_configs[plugin]
return plugin_cfg
def _store_plugin_config(self, name, plugin_cfg):
plugin = plugin_cfg["type"]
@ -146,7 +147,7 @@ class Profile(object):
self._disable_plugin(name, plugin_cfg)
del plugin_cfg["replace"]
else:
self._merge_plugin(name, plugin_cfg)
plugin_cfg = self._merge_plugin(name, plugin_cfg)
self._plugin_configs[name] = plugin_cfg
def _get_unique_plugin_name(self, name):
@ -185,7 +186,16 @@ class Profile(object):
return self._load_plugins(cfg, os.path.dirname(config))
def load(self):
return (self._load_config(self._config_file) and self._apply_config())
parsed = False
# Load more config files stored as list
if isinstance(self._config_file, list):
for cfg in self._config_file:
parsed = self._load_config(cfg)
if not parsed:
break
else:
parsed = self._load_config(self._config_file)
return (parsed and self._apply_config())
def cleanup(self):
pass