1
0
Fork 0

builtin functions: added virt_check function and support expansion in include

The virt_check builtin function expands to the first argument if
running inside virtual machine, otherwise it expands to the second
argument (when on bare metal or in case of error). It uses virt-what
as a backend.

So now the following can be used to lower fragmentation of Tuned profiles:

[main]
include=virtual-${f:virt_check:guest:host}

So it will include virtual-guest if running inside virtual machine,
otherwise it includes virtual-host.

Resolves: rhbz#1426654

Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
Jaroslav Škarvada 2017-04-04 15:11:45 +02:00
parent 9a9afb6ef6
commit a1b9e60644
No known key found for this signature in database
GPG key ID: D8E1C00E076E840B
2 changed files with 23 additions and 1 deletions

View file

@ -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]

View file

@ -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)