diff --git a/tuned/profiles/functions/function_virt_check.py b/tuned/profiles/functions/function_virt_check.py new file mode 100644 index 0000000..2caba3f --- /dev/null +++ b/tuned/profiles/functions/function_virt_check.py @@ -0,0 +1,22 @@ +import os +import tuned.logs +import base +from tuned.utils.commands import commands + +class virt_check(base.Function): + """ + Checks whether running inside virtual machine (VM) or on bare metal. + If running inside VM expands to argument 1, otherwise expands to + argument 2 (even on error). + """ + def __init__(self): + # 2 arguments + super(self.__class__, self).__init__("virt_check", 2) + + def execute(self, args): + if not super(self.__class__, self).execute(args): + return None + (ret, out) = self._cmd.execute(["virt-what"]) + if ret == 0 and len(out) > 0: + return args[0] + return args[1] diff --git a/tuned/profiles/loader.py b/tuned/profiles/loader.py index 5ee7bed..0c7520c 100644 --- a/tuned/profiles/loader.py +++ b/tuned/profiles/loader.py @@ -72,7 +72,7 @@ class Loader(object): config = self._load_config_data(filename) profile = self._profile_factory.create(name, config) if "include" in profile.options: - include_name = profile.options.pop("include") + include_name = self._variables.expand(profile.options.pop("include")) self._load_profile([include_name], profiles, processed_files) profiles.append(profile)