diff --git a/tuned.spec b/tuned.spec index 2b4f039..3bf0db2 100644 --- a/tuned.spec +++ b/tuned.spec @@ -67,6 +67,9 @@ Requires: util-linux, dbus, polkit %if 0%{?fedora} > 22 || 0%{?rhel} > 7 Recommends: kernel-tools %endif +%if 0%{?rhel} > 7 +Requires: python3-syspurpose +%endif %description The tuned package contains a daemon that tunes system settings dynamically. diff --git a/tuned/utils/commands.py b/tuned/utils/commands.py index 8bb31a3..9a81baf 100644 --- a/tuned/utils/commands.py +++ b/tuned/utils/commands.py @@ -10,6 +10,11 @@ import procfs from subprocess import * from tuned.exceptions import TunedException import dmidecode +try: + import syspurpose.files + have_syspurpose = True +except: + have_syspurpose = False log = tuned.logs.get() @@ -421,6 +426,23 @@ class commands: break else: match = False + elif option == "syspurpose_role": + if have_syspurpose: + s = syspurpose.files.SyspurposeStore( + syspurpose.files.USER_SYSPURPOSE, + raise_on_error = True) + role = "" + try: + s.read_file() + role = s.contents["role"] + except (IOError, OSError, KeyError) as e: + if hasattr(e, "errno") and e.errno != errno.ENOENT: + log.error("Failed to load the syspurpose file: %s" % e) + if re.match(value, role, re.IGNORECASE) is None: + match = False + else: + log.error("Failed to process 'syspurpose_role' in '%s', the syspurpose module is not available" % fname) + if match: # remove the ",.*" suffix r = re.compile(r",[^,]*$")