From 689d3b705dcafa8dd04ee547eed513c86aa0cefa Mon Sep 17 00:00:00 2001 From: Petr Lautrbach Date: Thu, 8 Oct 2009 16:45:50 +0200 Subject: [PATCH] Revert "tuned-adm: remove dependence on kobo, arguments parsed with getopt, Tuned_adm class" This reverts commit aec313a8228048ed254bfc35e44e9bc91573b11a. --- commands/__init__.py | 0 commands/cmd_list.py | 33 ++++++++++++ commands/cmd_off_mode.py | 33 ++++++++++++ commands/cmd_profile.py | 70 ++++++++++++++++++++++++ tuned-adm | 84 ++++++----------------------- tuned.spec | 8 ++- tuned_adm.py | 113 --------------------------------------- 7 files changed, 156 insertions(+), 185 deletions(-) create mode 100644 commands/__init__.py create mode 100644 commands/cmd_list.py create mode 100644 commands/cmd_off_mode.py create mode 100644 commands/cmd_profile.py delete mode 100644 tuned_adm.py diff --git a/commands/__init__.py b/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/commands/cmd_list.py b/commands/cmd_list.py new file mode 100644 index 0000000..2f71a1f --- /dev/null +++ b/commands/cmd_list.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +import os +import os.path +import glob +import kobo.shortcuts +from kobo.cli import Command + +class List(Command): + """list all available profiles""" + enabled = True + + def options(self): + self.parser.usage = "%%prog %s" % self.normalized_name + + self.parser.add_option( + "--show-disabled", + default=False, + action="store_true", + help="show disabled workers" + ) + + + def run(self, *args, **kwargs): + # link config files into directory which is exectued by ktune + if os.path.exists("/etc/tune-profiles/"): + modes = os.listdir("/etc/tune-profiles") + if len(modes) > 0: + print "Modes: " + for i in range(len(modes)): + print modes[i] + else: + print "No other profiles than default defined." diff --git a/commands/cmd_off_mode.py b/commands/cmd_off_mode.py new file mode 100644 index 0000000..779ac50 --- /dev/null +++ b/commands/cmd_off_mode.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +import os +import glob +import kobo.shortcuts +from kobo.cli import Command + +class Off(Command): + """switch off all tunning""" + enabled = True + + def options(self): + self.parser.usage = "%%prog %s" % self.normalized_name + + self.parser.add_option( + "--show-disabled", + default=False, + action="store_true", + help="show disabled workers" + ) + + + def run(self, *args, **kwargs): + os.system("rm -rf /etc/ktune.d/*.conf") + os.system("rm -rf /etc/ktune.d/*.sh") + if os.path.exists("/etc/sysconfig/ktune.bckp"): + os.rename("/etc/sysconfig/ktune.bckp", "/etc/sysconfig/ktune") + if os.path.exists("/etc/tuned.conf.bckp") and os.path.exists("/etc/tuned.conf"): + os.rename("/etc/tuned.conf.bckp", "/etc/tuned.conf") + os.system('service ktune stop') + os.system('service tuned stop') + os.system('chkconfig --del ktune') + os.system('chkconfig --del tuned') diff --git a/commands/cmd_profile.py b/commands/cmd_profile.py new file mode 100644 index 0000000..96cc0f5 --- /dev/null +++ b/commands/cmd_profile.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- + +import os +import os.path +import glob +import kobo.shortcuts +from kobo.cli import Command + +class Profile(Command): + """ switch to given profile""" + enabled = True + + def options(self): + self.parser.usage = "%%prog %s" % self.normalized_name + + self.parser.add_option( + "--show-disabled", + default=False, + action="store_true", + help="show disabled workers" + ) + + + def run(self, *args, **kwargs): + # link config files into directory which is exectued by ktune + enablektune = False + enabletuned = False + if len(args) == 0: + print "No profile given. To list all available profiles please run:" + print "tuned-adm list" + return + if not os.path.exists("/etc/tune-profiles/"+args[0]): + print "No profile with name %s found." % args[0] + return + if os.path.exists("/etc/tune-profiles/"): + os.system('service ktune stop') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune off') + os.system('service tuned stop') + os.system('chkconfig --add tuned && chkconfig --level 345 tuned off') + modes = os.listdir("/etc/tune-profiles") + if modes > 0: + print 'Switching to profile %s' % args[0] + if os.path.exists('/etc/ktune.d/tunedadm.sh'): + os.remove('/etc/ktune.d/tunedadm.sh') + if os.path.exists('/etc/ktune.d/tunedadm.conf'): + os.remove('/etc/ktune.d/tunedadm.conf') + file = ('/etc/tune-profiles/%s/ktune.sysconfig' % args[0]) + if os.path.exists(file): + enablektune = True + os.rename('/etc/sysconfig/ktune', '/etc/sysconfig/ktune.bckp') + os.symlink(file, '/etc/sysconfig/ktune') + file = ('/etc/tune-profiles/%s/ktune.sh' % args[0]) + if os.path.exists(file): + os.symlink(file, '/etc/ktune.d/tunedadm.sh') + file = ('/etc/tune-profiles/%s/sysctl.ktune' % args[0]) + if os.path.exists(file): + os.symlink(file, '/etc/ktune.d/tunedadm.conf') + file = ('/etc/tune-profiles/%s/tuned.conf' % args[0]) + if os.path.exists(file): + enabletuned = True + os.rename('/etc/tuned.conf', '/etc/tuned.conf.bckp') + os.symlink(file, '/etc/tuned.conf') + + if enablektune: + os.system('service ktune start') + os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') + + if enabletuned: + os.system('service tuned start') + os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') diff --git a/tuned-adm b/tuned-adm index eabd2ed..7a4b511 100755 --- a/tuned-adm +++ b/tuned-adm @@ -1,76 +1,26 @@ #!/usr/bin/python -# -# tuned-adm: A command line utility for switching between user -# definable tuning profiles. -# -# Copyright (C) 2008, 2009 Red Hat, Inc. -# Authors: Marcela Maslanova -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# import os import sys import locale -import getopt +from kobo.cli import * -def usage(): - print """ -Usage: tuned-adm [-p ] [-h] [args] -Options: - -p directory with profiles - -h, --help show this help message and exit -commands: - list list all available profiles - off switch off all tunning - profile switch to given profile -""" +from kobo.tback import * +set_except_hook() + + +TUNEDDIR="/usr/share/tuned" +if TUNEDDIR not in sys.path: + sys.path.insert(0, TUNEDDIR) + +import commands +CommandContainer.register_module(commands) + + +def main(argv): + parser = CommandOptionParser(command_container=CommandContainer(), default_command="help") + parser.run() if __name__ == "__main__": - - profile_dir = "/etc/tune-profiles/" - - try: - opts, args = getopt.getopt(sys.argv[1:], "hp:", ["help"]) - except getopt.error, e: - print >>sys.stderr, "Error parsing command-line arguments: %s" % e - usage() - sys.exit(1) - - for (opt, val) in opts: - if opt in ['-h', "--help"]: - usage() - sys.exit(0) - if opt in ['-p']: - profile_dir = val - - if len(args) < 1: - print >>sys.stderr, ("Missing arguments.") - usage() - sys.exit(1) - - TUNEDDIR="/usr/share/tuned" - if TUNEDDIR not in sys.path: - sys.path.insert(0, TUNEDDIR) - - from tuned_adm import tuned_adm - - tuned_adm.init(profile_dir) - if (tuned_adm.run(args)): - usage() - sys.exit(1) - - + main(sys.argv[1:]) diff --git a/tuned.spec b/tuned.spec index f6f44bd..8410bd5 100644 --- a/tuned.spec +++ b/tuned.spec @@ -1,7 +1,7 @@ Summary: A dynamic adaptive system tuning daemon Name: tuned -Version: 0.2.5 -Release: 0.1%{?dist} +Version: 0.2.4 +Release: 2%{?dist} License: GPLv2+ Group: System Environment/Daemons # The source for this package was pulled from upstream git. Use the @@ -18,6 +18,7 @@ Requires(preun): chkconfig Requires(preun): initscripts Requires(postun): initscripts BuildArch: noarch +Requires: kobo %description The tuned package contains a daemon that tunes system settings dynamically. @@ -96,9 +97,6 @@ fi %changelog -* Fri Oct 2 2009 Petr Lautrbach 0.2.5-0.1 -- tuned-adm without kobo dependence - * Wed Sep 23 2009 Petr Lautrbach 0.2.4-2 - fixed url to fedorahosted project page - Resolves: #519019 diff --git a/tuned_adm.py b/tuned_adm.py deleted file mode 100644 index 8001d13..0000000 --- a/tuned_adm.py +++ /dev/null @@ -1,113 +0,0 @@ -# Copyright (C) 2008, 2009 Red Hat, Inc. -# Authors: Phil Knirsch -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# - -import sys,os,glob - -class Tuned_adm: - def __init__(self): - self.profile_dir = "/etc/tune-profiles/" - - - def init(self, profile_dir): - self.profile_dir = profile_dir - - - def run(self, args): - if args[0] == "list": - self.list() - elif args[0] == "off": - self.off() - elif args[0] == "profile": - self.profile(args[1:]) - else: - print >>sys.stderr, "Nonexistent argument %s" % args[0] - return 1 - - - def list(self): - if os.path.exists(self.profile_dir): - modes = os.listdir(self.profile_dir) - if len(modes) > 0: - print "Modes: " - for i in range(len(modes)): - print modes[i] - else: - print "No profiles defined." - - def off(self): - os.system("rm -rf /etc/ktune.d/*.conf") - os.system("rm -rf /etc/ktune.d/*.sh") - if os.path.exists("/etc/sysconfig/ktune.bckp"): - os.rename("/etc/sysconfig/ktune.bckp", "/etc/sysconfig/ktune") - if os.path.exists("/etc/tuned.conf.bckp") and os.path.exists("/etc/tuned.conf"): - os.rename("/etc/tuned.conf.bckp", "/etc/tuned.conf") - os.system('service ktune stop') - os.system('service tuned stop') - os.system('chkconfig --del ktune') - os.system('chkconfig --del tuned') - - - def profile(self, args): - enablektune = False - enabletuned = False - if len(args) == 0: - print "No profile given. To list all available profiles please run:" - print "tuned-adm list" - return - if not os.path.exists(self.profile_dir+"/"+args[0]): - print "No profile with name %s found." % args[0] - return - if os.path.exists(self.profile_dir): - os.system('service ktune stop') - os.system('chkconfig --add ktune && chkconfig --level 345 ktune off') - os.system('service tuned stop') - os.system('chkconfig --add tuned && chkconfig --level 345 tuned off') - modes = os.listdir(self.profile_dir) - if modes > 0: - print 'Switching to profile %s' % args[0] - if os.path.exists('/etc/ktune.d/tunedadm.sh'): - os.remove('/etc/ktune.d/tunedadm.sh') - if os.path.exists('/etc/ktune.d/tunedadm.conf'): - os.remove('/etc/ktune.d/tunedadm.conf') - file = ('%s/%s/ktune.sysconfig' % (self.profile_dir, args[0])) - if os.path.exists(file): - enablektune = True - os.rename('/etc/sysconfig/ktune', '/etc/sysconfig/ktune.bckp') - os.symlink(file, '/etc/sysconfig/ktune') - file = ('%s/%s/ktune.sh' % (self.profile_dir, args[0])) - if os.path.exists(file): - os.symlink(file, '/etc/ktune.d/tunedadm.sh') - file = ('%s/%s/sysctl.ktune' % (self.profile_dir, args[0])) - if os.path.exists(file): - os.symlink(file, '/etc/ktune.d/tunedadm.conf') - file = ('%s/%s/tuned.conf' % (self.profile_dir, args[0])) - if os.path.exists(file): - enabletuned = True - os.rename('/etc/tuned.conf', '/etc/tuned.conf.bckp') - os.symlink(file, '/etc/tuned.conf') - - if enablektune: - os.system('service ktune start') - os.system('chkconfig --add ktune && chkconfig --level 345 ktune on') - - if enabletuned: - os.system('service tuned start') - os.system('chkconfig --add tuned && chkconfig --level 345 tuned on') - - -tuned_adm = Tuned_adm()