Add 'tuned-adm profile_mode' command
Implement a new 'tuned-adm profile_mode' command, which prints the current profile mode - automatic vs. manual. Related: rhbz#1459146 Signed-off-by: Ondřej Lysoněk <olysonek@redhat.com>
This commit is contained in:
parent
bc8ffcfb23
commit
cd655df597
6 changed files with 56 additions and 2 deletions
|
|
@ -17,6 +17,16 @@
|
|||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="com.redhat.tuned.profile_mode">
|
||||
<description>Show current profile selection mode</description>
|
||||
<message>Authentication is required to show current profile selection mode</message>
|
||||
<defaults>
|
||||
<allow_any>yes</allow_any>
|
||||
<allow_inactive>yes</allow_inactive>
|
||||
<allow_active>yes</allow_active>
|
||||
</defaults>
|
||||
</action>
|
||||
|
||||
<action id="com.redhat.tuned.disable">
|
||||
<description>Disable Tuned</description>
|
||||
<message>Authentication is required to disable Tuned</message>
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ if __name__ == "__main__":
|
|||
parser_auto_profile = subparsers.add_parser("auto_profile", help="enable automatic profile selection mode, switch to the recommended profile")
|
||||
parser_auto_profile.set_defaults(action="auto_profile")
|
||||
|
||||
parser_profile_mode = subparsers.add_parser("profile_mode", help="show current profile selection mode")
|
||||
parser_profile_mode.set_defaults(action="profile_mode")
|
||||
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
|
||||
options = vars(args)
|
||||
|
|
|
|||
|
|
@ -122,6 +122,19 @@ class Admin(object):
|
|||
profile_name = None
|
||||
return profile_name
|
||||
|
||||
def _get_profile_mode(self):
|
||||
contents = str.strip(self._cmd.read_file(consts.ACTIVE_PROFILE_FILE))
|
||||
if contents == '':
|
||||
mode = consts.ACTIVE_PROFILE_AUTO
|
||||
else:
|
||||
arr = contents.split('\n')
|
||||
if len(arr) == 1:
|
||||
# The file was generated by old Tuned -> manual mode
|
||||
mode = consts.ACTIVE_PROFILE_MANUAL
|
||||
else:
|
||||
mode = arr[1]
|
||||
return mode
|
||||
|
||||
def _print_profile_info(self, profile, profile_info):
|
||||
if profile_info[0] == True:
|
||||
print("Profile name:")
|
||||
|
|
@ -166,7 +179,18 @@ class Admin(object):
|
|||
return True
|
||||
return self._print_profile_name(profile_name)
|
||||
|
||||
# TODO action profile mode - auto/manual
|
||||
def _print_profile_mode(self, mode):
|
||||
print("Profile selection mode: " + mode)
|
||||
|
||||
def _action_dbus_profile_mode(self):
|
||||
mode = self._controller.profile_mode()
|
||||
self._print_profile_mode(mode)
|
||||
return self._controller.exit(True)
|
||||
|
||||
def _action_profile_mode(self):
|
||||
mode = self._get_profile_mode()
|
||||
self._print_profile_mode(mode)
|
||||
return True
|
||||
|
||||
def _profile_print_status(self, ret, msg):
|
||||
if ret:
|
||||
|
|
|
|||
|
|
@ -99,6 +99,9 @@ class DBusController(object):
|
|||
def active_profile(self):
|
||||
return self._call("active_profile")
|
||||
|
||||
def profile_mode(self):
|
||||
return self._call("profile_mode")
|
||||
|
||||
def switch_profile(self, new_profile):
|
||||
if new_profile == "":
|
||||
return (False, "No profile specified")
|
||||
|
|
|
|||
|
|
@ -128,6 +128,15 @@ class Controller(tuned.exports.interfaces.ExportableInterface):
|
|||
else:
|
||||
return ""
|
||||
|
||||
@exports.export("", "s")
|
||||
def profile_mode(self, caller = None):
|
||||
if caller == "":
|
||||
return ""
|
||||
if self._daemon.manual:
|
||||
return consts.ACTIVE_PROFILE_MANUAL
|
||||
else:
|
||||
return consts.ACTIVE_PROFILE_AUTO
|
||||
|
||||
@exports.export("", "b")
|
||||
def disable(self, caller = None):
|
||||
if caller == "":
|
||||
|
|
@ -135,7 +144,7 @@ class Controller(tuned.exports.interfaces.ExportableInterface):
|
|||
if self._daemon.is_running():
|
||||
self._daemon.stop()
|
||||
if self._daemon.is_enabled():
|
||||
self._daemon.set_profile(None, True, save_instantly=True)
|
||||
self._daemon.set_profile(None, None, save_instantly=True)
|
||||
return True
|
||||
|
||||
@exports.export("", "b")
|
||||
|
|
|
|||
|
|
@ -90,6 +90,11 @@ class Daemon(object):
|
|||
def profile(self):
|
||||
return self._profile
|
||||
|
||||
@property
|
||||
def manual(self):
|
||||
# manual == None means /etc/tuned/active_profile is empty -> automatic mode
|
||||
return self._manual == True or self._manual is None
|
||||
|
||||
@property
|
||||
def profile_loader(self):
|
||||
return self._profile_loader
|
||||
|
|
|
|||
Loading…
Reference in a new issue