1
0
Fork 0
tuned/tuned-adm.py
Jan Vcelak a49f53e60f GPL headers only into executables and main module
GPL license does not require all files to have the copyright notice
and header. To save some space, I removed the headers from all files
except the executables and the main Python module.
2012-11-09 12:27:20 +01:00

75 lines
2.3 KiB
Python
Executable file

#!/usr/bin/python -Es
#
# tuned: daemon for monitoring and adaptive tuning of system devices
#
# Copyright (C) 2008-2012 Red Hat, Inc.
#
# 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 argparse
import sys
import traceback
import tuned.admin
DBUS_BUS = "com.redhat.tuned"
DBUS_OBJECT = "/Tuned"
DBUS_INTERFACE = "com.redhat.tuned.control"
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Manage tuned daemon.")
parser.add_argument("--debug", action="store_true", help=argparse.SUPPRESS)
subparsers = parser.add_subparsers()
parser_list = subparsers.add_parser("list", help="list available profiles")
parser_list.set_defaults(action="list")
parser_active = subparsers.add_parser("active", help="show active profile")
parser_active.set_defaults(action="active")
parser_off = subparsers.add_parser("off", help="switch off all tunings")
parser_off.set_defaults(action="off")
parser_profile = subparsers.add_parser("profile", help="switch to a given profile")
parser_profile.set_defaults(action="profile")
parser_profile.add_argument("profiles", metavar="profile", type=str, nargs="+", help="profile name")
args = parser.parse_args(sys.argv[1:])
options = vars(args)
debug = options.pop("debug")
action_name = options.pop("action")
result = False
try:
controller = tuned.admin.DBusController(DBUS_BUS, DBUS_OBJECT, DBUS_INTERFACE)
admin = tuned.admin.Admin(controller)
action = getattr(admin, action_name)
result = action(**options)
except tuned.admin.TunedAdminException as e:
if not debug:
print >>sys.stderr, e
else:
traceback.print_exc()
sys.exit(2)
except:
traceback.print_exc()
sys.exit(3)
if result == False:
sys.exit(1)
else:
sys.exit(0)