1
0
Fork 0

Revert "tuned-adm: remove dependence on kobo, arguments parsed with getopt, Tuned_adm class"

This reverts commit aec313a822.
This commit is contained in:
Petr Lautrbach 2009-10-08 16:45:50 +02:00
parent aec313a822
commit 689d3b705d
7 changed files with 156 additions and 185 deletions

0
commands/__init__.py Normal file
View file

33
commands/cmd_list.py Normal file
View file

@ -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."

33
commands/cmd_off_mode.py Normal file
View file

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

70
commands/cmd_profile.py Normal file
View file

@ -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):
"""<profile> 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')

View file

@ -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 <profile_dir>] [-h] <command> [args]
Options:
-p <profile_dir> directory with profiles
-h, --help show this help message and exit
commands:
list list all available profiles
off switch off all tunning
profile <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:])

View file

@ -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 <plautrba@redhat.com> 0.2.5-0.1
- tuned-adm without kobo dependence
* Wed Sep 23 2009 Petr Lautrbach <plautrba@redhat.com> 0.2.4-2
- fixed url to fedorahosted project page
- Resolves: #519019

View file

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