An attempt to port Tuned to python3 and keeping it python2 compatible
Signed-off-by: Jaroslav Škarvada <jskarvad@redhat.com>
This commit is contained in:
parent
60bb8e293f
commit
f563c7d756
75 changed files with 248 additions and 235 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/python -Es
|
#!/usr/bin/python -Es
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import Xlib
|
import Xlib
|
||||||
|
|
||||||
|
|
@ -38,8 +40,8 @@ def loop():
|
||||||
else:
|
else:
|
||||||
if not win in showed:
|
if not win in showed:
|
||||||
showed.append(win)
|
showed.append(win)
|
||||||
print "Showed:", showed
|
print("Showed:", showed)
|
||||||
print "Minimized:", hidden
|
print("Minimized:", hidden)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
loop()
|
loop()
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
from builtins import chr
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
@ -26,8 +28,13 @@ import shutil
|
||||||
import argparse
|
import argparse
|
||||||
import codecs
|
import codecs
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
from HTMLParser import HTMLParser
|
try:
|
||||||
from htmlentitydefs import name2codepoint
|
from html.parser import HTMLParser
|
||||||
|
from html.entities import name2codepoint
|
||||||
|
except ImportError:
|
||||||
|
from HTMLParser import HTMLParser
|
||||||
|
from htmlentitydefs import name2codepoint
|
||||||
|
|
||||||
|
|
||||||
SCRIPT_SH = """#!/bin/sh
|
SCRIPT_SH = """#!/bin/sh
|
||||||
|
|
||||||
|
|
@ -141,7 +148,7 @@ class PowertopHTMLParser(HTMLParser):
|
||||||
|
|
||||||
def handle_entityref(self, name):
|
def handle_entityref(self, name):
|
||||||
if self.inScript:
|
if self.inScript:
|
||||||
self.currentScript += unichr(name2codepoint[name])
|
self.currentScript += chr(name2codepoint[name])
|
||||||
|
|
||||||
def handle_data(self, data):
|
def handle_data(self, data):
|
||||||
prefix = self.prefix
|
prefix = self.prefix
|
||||||
|
|
@ -179,23 +186,23 @@ class PowertopProfile:
|
||||||
def checkPrivs(self):
|
def checkPrivs(self):
|
||||||
myuid = os.geteuid()
|
myuid = os.geteuid()
|
||||||
if myuid != 0:
|
if myuid != 0:
|
||||||
print >> sys.stderr, 'Run this program as root'
|
print('Run this program as root', file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def generateHTML(self):
|
def generateHTML(self):
|
||||||
print "Running PowerTOP, please wait..."
|
print("Running PowerTOP, please wait...")
|
||||||
environment = os.environ.copy()
|
environment = os.environ.copy()
|
||||||
environment["LC_ALL"] = "C"
|
environment["LC_ALL"] = "C"
|
||||||
try:
|
try:
|
||||||
proc = Popen(["/usr/sbin/powertop", "--html=/tmp/powertop", "--time=1"], stdout=PIPE, stderr=PIPE, env=environment)
|
proc = Popen(["/usr/sbin/powertop", "--html=/tmp/powertop", "--time=1"], stdout=PIPE, stderr=PIPE, env=environment)
|
||||||
output = proc.communicate()[1]
|
output = proc.communicate()[1]
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
print >> sys.stderr, 'Unable to execute PowerTOP, is PowerTOP installed?'
|
print('Unable to execute PowerTOP, is PowerTOP installed?', file=sys.stderr)
|
||||||
return -2
|
return -2
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
print >> sys.stderr, 'PowerTOP returned error code: %d' % proc.returncode
|
print('PowerTOP returned error code: %d' % proc.returncode, file=sys.stderr)
|
||||||
return -2
|
return -2
|
||||||
|
|
||||||
prefix = "PowerTOP outputing using base filename "
|
prefix = "PowerTOP outputing using base filename "
|
||||||
|
|
@ -226,31 +233,31 @@ class PowertopProfile:
|
||||||
return parser.getParsedData(), parser.getPlugins()
|
return parser.getParsedData(), parser.getPlugins()
|
||||||
|
|
||||||
def generateShellScript(self, data):
|
def generateShellScript(self, data):
|
||||||
print "Generating shell script", os.path.join(self.output, "script.sh")
|
print("Generating shell script", os.path.join(self.output, "script.sh"))
|
||||||
f = None
|
f = None
|
||||||
try:
|
try:
|
||||||
f = codecs.open(os.path.join(self.output, "script.sh"), "w", "utf-8")
|
f = codecs.open(os.path.join(self.output, "script.sh"), "w", "utf-8")
|
||||||
f.write(SCRIPT_SH % (data, ""))
|
f.write(SCRIPT_SH % (data, ""))
|
||||||
os.fchmod(f.fileno(), 0755)
|
os.fchmod(f.fileno(), 0o755)
|
||||||
f.close()
|
f.close()
|
||||||
except (OSError, IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
print >> sys.stderr, "Error writing shell script: %s" % e
|
print("Error writing shell script: %s" % e, file=sys.stderr)
|
||||||
if f is not None:
|
if f is not None:
|
||||||
f.close()
|
f.close()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def generateTunedConf(self, profile, plugins):
|
def generateTunedConf(self, profile, plugins):
|
||||||
print "Generating Tuned config file", os.path.join(self.output, "tuned.conf")
|
print("Generating Tuned config file", os.path.join(self.output, "tuned.conf"))
|
||||||
f = codecs.open(os.path.join(self.output, "tuned.conf"), "w", "utf-8")
|
f = codecs.open(os.path.join(self.output, "tuned.conf"), "w", "utf-8")
|
||||||
f.write(TUNED_CONF_PROLOG)
|
f.write(TUNED_CONF_PROLOG)
|
||||||
if profile is not None:
|
if profile is not None:
|
||||||
if self.profile_name == profile:
|
if self.profile_name == profile:
|
||||||
print >> sys.stderr, 'New profile has same name as active profile, not including active profile (avoiding circular deps).'
|
print('New profile has same name as active profile, not including active profile (avoiding circular deps).', file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
f.write(TUNED_CONF_INCLUDE % ("include=" + profile))
|
f.write(TUNED_CONF_INCLUDE % ("include=" + profile))
|
||||||
|
|
||||||
for plugin in plugins.values():
|
for plugin in list(plugins.values()):
|
||||||
f.write(plugin + "\n")
|
f.write(plugin + "\n")
|
||||||
|
|
||||||
f.write(TUNED_CONF_EPILOG)
|
f.write(TUNED_CONF_EPILOG)
|
||||||
|
|
@ -274,7 +281,7 @@ class PowertopProfile:
|
||||||
os.unlink(self.name)
|
os.unlink(self.name)
|
||||||
|
|
||||||
if len(data) == 0 and len(plugins) == 0:
|
if len(data) == 0 and len(plugins) == 0:
|
||||||
print >> sys.stderr, 'Your Powertop version is incompatible (maybe too old) or the generated HTML output is malformed'
|
print('Your Powertop version is incompatible (maybe too old) or the generated HTML output is malformed', file=sys.stderr)
|
||||||
return self.PARSING_ERROR
|
return self.PARSING_ERROR
|
||||||
|
|
||||||
if new_profile is False:
|
if new_profile is False:
|
||||||
|
|
@ -297,9 +304,9 @@ class PowertopProfile:
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Creates Tuned profile from Powertop HTML output.')
|
parser = argparse.ArgumentParser(description='Creates Tuned profile from Powertop HTML output.')
|
||||||
parser.add_argument('profile', metavar='profile_name', type=unicode, nargs='?', help='Name for the profile to be written.')
|
parser.add_argument('profile', metavar='profile_name', type=str, nargs='?', help='Name for the profile to be written.')
|
||||||
parser.add_argument('-i', '--input', metavar='input_html', type=unicode, help='Path to Powertop HTML report. If not given, it is generated automatically.')
|
parser.add_argument('-i', '--input', metavar='input_html', type=str, help='Path to Powertop HTML report. If not given, it is generated automatically.')
|
||||||
parser.add_argument('-o', '--output', metavar='output_directory', type=unicode, help='Directory where the profile will be written, default is /etc/tuned/profile_name directory.')
|
parser.add_argument('-o', '--output', metavar='output_directory', type=str, help='Directory where the profile will be written, default is /etc/tuned/profile_name directory.')
|
||||||
parser.add_argument('-n', '--new-profile', action='store_true', help='Creates new profile, otherwise it merges (include) your current profile.')
|
parser.add_argument('-n', '--new-profile', action='store_true', help='Creates new profile, otherwise it merges (include) your current profile.')
|
||||||
parser.add_argument('-m', '--merge-profile', action = 'store', help = 'Merges (includes) the specified profile (can be suppressed by -n option).')
|
parser.add_argument('-m', '--merge-profile', action = 'store', help = 'Merges (includes) the specified profile (can be suppressed by -n option).')
|
||||||
parser.add_argument('-f', '--force', action='store_true', help='Overwrites the output directory if it already exists.')
|
parser.add_argument('-f', '--force', action='store_true', help='Overwrites the output directory if it already exists.')
|
||||||
|
|
@ -308,7 +315,7 @@ if __name__ == "__main__":
|
||||||
args = vars(args)
|
args = vars(args)
|
||||||
|
|
||||||
if not args['profile'] and not args['output']:
|
if not args['profile'] and not args['output']:
|
||||||
print >> sys.stderr, 'You have to specify the profile_name or output directory using the --output argument.'
|
print('You have to specify the profile_name or output directory using the --output argument.', file=sys.stderr)
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
|
|
@ -322,7 +329,7 @@ if __name__ == "__main__":
|
||||||
args['input'] = ''
|
args['input'] = ''
|
||||||
|
|
||||||
if os.path.exists(args['output']) and not args['force']:
|
if os.path.exists(args['output']) and not args['force']:
|
||||||
print >> sys.stderr, 'Output directory already exists, use --force to overwrite it.'
|
print('Output directory already exists, use --force to overwrite it.', file=sys.stderr)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
p = PowertopProfile(args['output'], args['profile'], args['input'])
|
p = PowertopProfile(args['output'], args['profile'], args['input'])
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import struct
|
import struct
|
||||||
|
|
@ -47,7 +48,7 @@ def close_fds():
|
||||||
os.dup2(s_err.fileno(), sys.stderr.fileno())
|
os.dup2(s_err.fileno(), sys.stderr.fileno())
|
||||||
|
|
||||||
def write_pidfile():
|
def write_pidfile():
|
||||||
f = os.open(PIDFILE, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0644)
|
f = os.open(PIDFILE, os.O_CREAT | os.O_TRUNC | os.O_WRONLY, 0o644)
|
||||||
os.write(f, "%d" % os.getpid())
|
os.write(f, "%d" % os.getpid())
|
||||||
os.close(f)
|
os.close(f)
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ def set_pmqos(name, value):
|
||||||
try:
|
try:
|
||||||
fd = os.open(filename, os.O_WRONLY)
|
fd = os.open(filename, os.O_WRONLY)
|
||||||
except OSError:
|
except OSError:
|
||||||
print >>sys.stderr, "Cannot open (%s)." % filename
|
print("Cannot open (%s)." % filename, file=sys.stderr)
|
||||||
return None
|
return None
|
||||||
os.write(fd, bin_value)
|
os.write(fd, bin_value)
|
||||||
return fd
|
return fd
|
||||||
|
|
@ -86,14 +87,14 @@ def run_daemon(options):
|
||||||
daemonize()
|
daemonize()
|
||||||
write_pidfile()
|
write_pidfile()
|
||||||
signal.signal(signal.SIGTERM, sigterm_handler)
|
signal.signal(signal.SIGTERM, sigterm_handler)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print >>sys.stderr, "Cannot daemonize (%s)." % e
|
print("Cannot daemonize (%s)." % e, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
global pmqos_fds
|
global pmqos_fds
|
||||||
pmqos_fds = []
|
pmqos_fds = []
|
||||||
|
|
||||||
for (name, value) in options.items():
|
for (name, value) in list(options.items()):
|
||||||
try:
|
try:
|
||||||
new_fd = set_pmqos(name, value)
|
new_fd = set_pmqos(name, value)
|
||||||
if new_fd is not None:
|
if new_fd is not None:
|
||||||
|
|
@ -111,20 +112,20 @@ def kill_daemon(force = False):
|
||||||
try:
|
try:
|
||||||
with open(PIDFILE, "r") as pidfile:
|
with open(PIDFILE, "r") as pidfile:
|
||||||
daemon_pid = int(pidfile.read())
|
daemon_pid = int(pidfile.read())
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
if not force: print >>sys.stderr, "Cannot open PID file (%s)." % e
|
if not force: print("Cannot open PID file (%s)." % e, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.kill(daemon_pid, signal.SIGTERM)
|
os.kill(daemon_pid, signal.SIGTERM)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if not force: print >>sys.stderr, "Cannot terminate the daemon (%s)." % e
|
if not force: print("Cannot terminate the daemon (%s)." % e, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.unlink(PIDFILE)
|
os.unlink(PIDFILE)
|
||||||
except OSError, e:
|
except OSError as e:
|
||||||
if not force: print >>sys.stderr, "Cannot delete the PID file (%s)." % e
|
if not force: print("Cannot delete the PID file (%s)." % e, file=sys.stderr)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
@ -148,14 +149,14 @@ if __name__ == "__main__":
|
||||||
if name in ALLOWED_INTERFACES and len(value) > 0:
|
if name in ALLOWED_INTERFACES and len(value) > 0:
|
||||||
options[name] = value
|
options[name] = value
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, "Invalid option (%s)." % option
|
print("Invalid option (%s)." % option, file=sys.stderr)
|
||||||
|
|
||||||
|
|
||||||
if disable:
|
if disable:
|
||||||
sys.exit(0 if kill_daemon() else 1)
|
sys.exit(0 if kill_daemon() else 1)
|
||||||
|
|
||||||
if len(options) == 0:
|
if len(options) == 0:
|
||||||
print >>sys.stderr, "No options set. Not starting."
|
print("No options set. Not starting.", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
kill_daemon(True)
|
kill_daemon(True)
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ class LoaderTestCase(unittest.TestCase):
|
||||||
profile = self.loader.load("default")
|
profile = self.loader.load("default")
|
||||||
self.assertIn("main", profile.test_config)
|
self.assertIn("main", profile.test_config)
|
||||||
self.assertIn("disk", profile.test_config)
|
self.assertIn("disk", profile.test_config)
|
||||||
self.assertEquals(profile.test_config["network"]["devices"], "em*")
|
self.assertEqual(profile.test_config["network"]["devices"], "em*")
|
||||||
|
|
||||||
def test_load_empty(self):
|
def test_load_empty(self):
|
||||||
profile = self.loader.load("empty")
|
profile = self.loader.load("empty")
|
||||||
|
|
@ -85,7 +85,7 @@ class LoaderTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_load_order(self):
|
def test_load_order(self):
|
||||||
profile = self.loader.load("custom")
|
profile = self.loader.load("custom")
|
||||||
self.assertEquals(profile.test_config["custom"]["type"], "two")
|
self.assertEqual(profile.test_config["custom"]["type"], "two")
|
||||||
|
|
||||||
def test_default_load(self):
|
def test_default_load(self):
|
||||||
profile = self.loader.load("empty")
|
profile = self.loader.load("empty")
|
||||||
|
|
|
||||||
|
|
@ -45,19 +45,19 @@ class LocatorTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_config(self):
|
def test_get_config(self):
|
||||||
config_name = self.locator.get_config("custom")
|
config_name = self.locator.get_config("custom")
|
||||||
self.assertEquals(config_name, os.path.join(self._tmp_load_dirs[1], "custom", "tuned.conf"))
|
self.assertEqual(config_name, os.path.join(self._tmp_load_dirs[1], "custom", "tuned.conf"))
|
||||||
|
|
||||||
def test_get_config_priority(self):
|
def test_get_config_priority(self):
|
||||||
customized = self.locator.get_config("balanced")
|
customized = self.locator.get_config("balanced")
|
||||||
self.assertEquals(customized, os.path.join(self._tmp_load_dirs[1], "balanced", "tuned.conf"))
|
self.assertEqual(customized, os.path.join(self._tmp_load_dirs[1], "balanced", "tuned.conf"))
|
||||||
system = self.locator.get_config("balanced", [customized])
|
system = self.locator.get_config("balanced", [customized])
|
||||||
self.assertEquals(system, os.path.join(self._tmp_load_dirs[0], "balanced", "tuned.conf"))
|
self.assertEqual(system, os.path.join(self._tmp_load_dirs[0], "balanced", "tuned.conf"))
|
||||||
none = self.locator.get_config("balanced", [customized, system])
|
none = self.locator.get_config("balanced", [customized, system])
|
||||||
self.assertIsNone(none)
|
self.assertIsNone(none)
|
||||||
|
|
||||||
def test_ignore_nonexistent_dirs(self):
|
def test_ignore_nonexistent_dirs(self):
|
||||||
locator = Locator([self._tmp_load_dirs[0], "/tmp/some-dir-which-does-not-exist-for-sure"])
|
locator = Locator([self._tmp_load_dirs[0], "/tmp/some-dir-which-does-not-exist-for-sure"])
|
||||||
balanced = locator.get_config("balanced")
|
balanced = locator.get_config("balanced")
|
||||||
self.assertEquals(balanced, os.path.join(self._tmp_load_dirs[0], "balanced", "tuned.conf"))
|
self.assertEqual(balanced, os.path.join(self._tmp_load_dirs[0], "balanced", "tuned.conf"))
|
||||||
known = locator.get_known_names()
|
known = locator.get_known_names()
|
||||||
self.assertListEqual(known, ["balanced", "powersafe"])
|
self.assertListEqual(known, ["balanced", "powersafe"])
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class ProfileTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.assertIs(type(profile.units), collections.OrderedDict)
|
self.assertIs(type(profile.units), collections.OrderedDict)
|
||||||
self.assertEqual(len(profile.units), 2)
|
self.assertEqual(len(profile.units), 2)
|
||||||
self.assertListEqual(sorted(map(lambda (name, config): name, profile.units)), sorted(["network", "storage"]))
|
self.assertListEqual(sorted([name_config[0] for name_config in profile.units]), sorted(["network", "storage"]))
|
||||||
|
|
||||||
def test_create_units_empty(self):
|
def test_create_units_empty(self):
|
||||||
profile = MockProfile("test", {"main":{}})
|
profile = MockProfile("test", {"main":{}})
|
||||||
|
|
@ -47,7 +47,7 @@ class ProfileTestCase(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
self.assertIs(type(profile.options), dict)
|
self.assertIs(type(profile.options), dict)
|
||||||
self.assertEquals(profile.options["anything"], 10)
|
self.assertEqual(profile.options["anything"], 10)
|
||||||
|
|
||||||
def test_sets_options_empty(self):
|
def test_sets_options_empty(self):
|
||||||
profile = MockProfile("test", {
|
profile = MockProfile("test", {
|
||||||
|
|
@ -55,4 +55,4 @@ class ProfileTestCase(unittest.TestCase):
|
||||||
})
|
})
|
||||||
|
|
||||||
self.assertIs(type(profile.options), dict)
|
self.assertIs(type(profile.options), dict)
|
||||||
self.assertEquals(len(profile.options), 0)
|
self.assertEqual(len(profile.options), 0)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -94,7 +95,7 @@ if __name__ == "__main__":
|
||||||
result = admin.action(action_name, **options)
|
result = admin.action(action_name, **options)
|
||||||
except tuned.admin.TunedAdminException as e:
|
except tuned.admin.TunedAdminException as e:
|
||||||
if not debug:
|
if not debug:
|
||||||
print >>sys.stderr, e
|
print(e, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
|
||||||
17
tuned-gui.py
17
tuned-gui.py
|
|
@ -24,6 +24,7 @@ Created on Oct 15, 2013
|
||||||
|
|
||||||
@author: mstana
|
@author: mstana
|
||||||
'''
|
'''
|
||||||
|
from __future__ import print_function
|
||||||
try:
|
try:
|
||||||
import gi
|
import gi
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -92,7 +93,7 @@ class Base(object):
|
||||||
tuned.admin.DBusController(consts.DBUS_BUS,
|
tuned.admin.DBusController(consts.DBUS_BUS,
|
||||||
consts.DBUS_INTERFACE, consts.DBUS_OBJECT)
|
consts.DBUS_INTERFACE, consts.DBUS_OBJECT)
|
||||||
self.controller.is_running()
|
self.controller.is_running()
|
||||||
except tuned.admin.exceptions.TunedAdminDBusException, ex:
|
except tuned.admin.exceptions.TunedAdminDBusException as ex:
|
||||||
response = self.tuned_daemon_exception_dialog.run()
|
response = self.tuned_daemon_exception_dialog.run()
|
||||||
if response == 0:
|
if response == 0:
|
||||||
|
|
||||||
|
|
@ -120,7 +121,7 @@ class Base(object):
|
||||||
try:
|
try:
|
||||||
self.builder.add_from_file(GLADEUI)
|
self.builder.add_from_file(GLADEUI)
|
||||||
except GObject.GError as e:
|
except GObject.GError as e:
|
||||||
print >> sys.stderr, "Error loading '%s'" % GLADEUI
|
print("Error loading '%s'" % GLADEUI, file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
#
|
#
|
||||||
# DIALOGS
|
# DIALOGS
|
||||||
|
|
@ -535,7 +536,7 @@ class Base(object):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
options = '\n'.join('%s = %r' % (key, val) for (key, val) in
|
options = '\n'.join('%s = %r' % (key, val) for (key, val) in
|
||||||
plugin._get_config_options().iteritems())
|
plugin._get_config_options().items())
|
||||||
|
|
||||||
self.textview_plugin_avaible_text.get_buffer().set_text(options)
|
self.textview_plugin_avaible_text.get_buffer().set_text(options)
|
||||||
self.textview_plugin_documentation_text.get_buffer().set_text(plugin.__doc__)
|
self.textview_plugin_documentation_text.get_buffer().set_text(plugin.__doc__)
|
||||||
|
|
@ -570,7 +571,7 @@ class Base(object):
|
||||||
if item[0] == profile:
|
if item[0] == profile:
|
||||||
iter = self.treestore_profiles.get_iter(item.path)
|
iter = self.treestore_profiles.get_iter(item.path)
|
||||||
self.treestore_profiles.remove(iter)
|
self.treestore_profiles.remove(iter)
|
||||||
except ManagerException, ex:
|
except ManagerException as ex:
|
||||||
self.error_dialog('Profile can not be remove', ex.__str__())
|
self.error_dialog('Profile can not be remove', ex.__str__())
|
||||||
|
|
||||||
def execute_cancel_window_profile_editor(self, button):
|
def execute_cancel_window_profile_editor(self, button):
|
||||||
|
|
@ -767,7 +768,7 @@ class Base(object):
|
||||||
|
|
||||||
# load all values not just normal
|
# load all values not just normal
|
||||||
|
|
||||||
for (name, unit) in profile.units.items():
|
for (name, unit) in list(profile.units.items()):
|
||||||
self.notebook_plugins.append_page_menu(self.treeview_for_data(unit.options),
|
self.notebook_plugins.append_page_menu(self.treeview_for_data(unit.options),
|
||||||
Gtk.Label(unit.name), Gtk.Label(unit.name))
|
Gtk.Label(unit.name), Gtk.Label(unit.name))
|
||||||
self.notebook_plugins.show_all()
|
self.notebook_plugins.show_all()
|
||||||
|
|
@ -783,7 +784,7 @@ class Base(object):
|
||||||
treestore = Gtk.ListStore(GObject.TYPE_STRING,
|
treestore = Gtk.ListStore(GObject.TYPE_STRING,
|
||||||
GObject.TYPE_STRING)
|
GObject.TYPE_STRING)
|
||||||
|
|
||||||
for (option, value) in data.items():
|
for (option, value) in list(data.items()):
|
||||||
treestore.append([str(value), option])
|
treestore.append([str(value), option])
|
||||||
treeview = Gtk.TreeView(treestore)
|
treeview = Gtk.TreeView(treestore)
|
||||||
renderer = Gtk.CellRendererText()
|
renderer = Gtk.CellRendererText()
|
||||||
|
|
@ -1021,12 +1022,12 @@ if __name__ == '__main__':
|
||||||
# Explicitly disabling shell to be safe
|
# Explicitly disabling shell to be safe
|
||||||
ec = subprocess.call(['pkexec', EXECNAME] + sys.argv[1:], shell = False)
|
ec = subprocess.call(['pkexec', EXECNAME] + sys.argv[1:], shell = False)
|
||||||
except (subprocess.CalledProcessError) as e:
|
except (subprocess.CalledProcessError) as e:
|
||||||
print >> sys.stderr, 'Error elevating privileges: %s' % e
|
print('Error elevating privileges: %s' % e, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
# If not pkexec error
|
# If not pkexec error
|
||||||
if ec not in [126, 127]:
|
if ec not in [126, 127]:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
# In case of error elevating privileges
|
# In case of error elevating privileges
|
||||||
print >> sys.stderr, 'Superuser permissions are required to run the daemon.'
|
print('Superuser permissions are required to run the daemon.', file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
base = Base()
|
base = Base()
|
||||||
|
|
|
||||||
3
tuned.py
3
tuned.py
|
|
@ -19,6 +19,7 @@
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -31,7 +32,7 @@ import tuned.version as ver
|
||||||
from tuned.utils.global_config import GlobalConfig
|
from tuned.utils.global_config import GlobalConfig
|
||||||
|
|
||||||
def error(message):
|
def error(message):
|
||||||
print >>sys.stderr, message
|
print(message, file=sys.stderr)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description = "Daemon for monitoring and adaptive tuning of system devices.")
|
parser = argparse.ArgumentParser(description = "Daemon for monitoring and adaptive tuning of system devices.")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
from admin import *
|
from .admin import *
|
||||||
from exceptions import *
|
from .exceptions import *
|
||||||
from dbus_controller import *
|
from .dbus_controller import *
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import tuned.admin
|
import tuned.admin
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
from tuned.profiles import Locator as profiles_locator
|
from tuned.profiles import Locator as profiles_locator
|
||||||
from exceptions import TunedAdminDBusException
|
from .exceptions import TunedAdminDBusException
|
||||||
from tuned.exceptions import TunedException
|
from tuned.exceptions import TunedException
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
import os
|
import os
|
||||||
|
|
@ -94,7 +95,7 @@ class Admin(object):
|
||||||
profile_names = self._controller.profiles2()
|
profile_names = self._controller.profiles2()
|
||||||
except TunedAdminDBusException as e:
|
except TunedAdminDBusException as e:
|
||||||
# fallback to older API
|
# fallback to older API
|
||||||
profile_names = map(lambda profile:(profile, ""), self._controller.profiles())
|
profile_names = [(profile, "") for profile in self._controller.profiles()]
|
||||||
self._print_profiles(profile_names)
|
self._print_profiles(profile_names)
|
||||||
self._action_dbus_active()
|
self._action_dbus_active()
|
||||||
return self._controller.exit(True)
|
return self._controller.exit(True)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import dbus.exceptions
|
||||||
import time
|
import time
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
from gi.repository import GLib, GObject
|
from gi.repository import GLib, GObject
|
||||||
from exceptions import TunedAdminDBusException
|
from .exceptions import TunedAdminDBusException
|
||||||
|
|
||||||
__all__ = ["DBusController"]
|
__all__ = ["DBusController"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
from application import *
|
from .application import *
|
||||||
from controller import *
|
from .controller import *
|
||||||
from daemon import *
|
from .daemon import *
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from tuned import storage, units, monitors, plugins, profiles, exports, hardware
|
from tuned import storage, units, monitors, plugins, profiles, exports, hardware
|
||||||
from tuned.exceptions import TunedException
|
from tuned.exceptions import TunedException
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import controller
|
from . import controller
|
||||||
import daemon
|
from . import daemon
|
||||||
import signal
|
import signal
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import interfaces
|
from . import interfaces
|
||||||
import controller
|
from . import controller
|
||||||
import dbus_exporter as dbus
|
from . import dbus_exporter as dbus
|
||||||
|
|
||||||
def export(*args, **kwargs):
|
def export(*args, **kwargs):
|
||||||
"""Decorator, use to mark exportable methods."""
|
"""Decorator, use to mark exportable methods."""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import interfaces
|
from . import interfaces
|
||||||
import inspect
|
import inspect
|
||||||
import tuned.patterns
|
import tuned.patterns
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import interfaces
|
from . import interfaces
|
||||||
import decorator
|
import decorator
|
||||||
import dbus.service
|
import dbus.service
|
||||||
import dbus.mainloop.glib
|
import dbus.mainloop.glib
|
||||||
|
|
@ -87,7 +87,7 @@ class DBusExporter(interfaces.ExporterInterface):
|
||||||
args[-1] = ""
|
args[-1] = ""
|
||||||
return method(*args, **kwargs)
|
return method(*args, **kwargs)
|
||||||
|
|
||||||
wrapper = decorator.decorator(wrapper, method.im_func)
|
wrapper = decorator.decorator(wrapper, method.__func__)
|
||||||
wrapper = dbus.service.method(self._interface_name, in_signature, out_signature, sender_keyword = "caller")(wrapper)
|
wrapper = dbus.service.method(self._interface_name, in_signature, out_signature, sender_keyword = "caller")(wrapper)
|
||||||
|
|
||||||
self._dbus_methods[method_name] = wrapper
|
self._dbus_methods[method_name] = wrapper
|
||||||
|
|
@ -103,7 +103,7 @@ class DBusExporter(interfaces.ExporterInterface):
|
||||||
def wrapper(wrapped, owner, *args, **kwargs):
|
def wrapper(wrapped, owner, *args, **kwargs):
|
||||||
return method(*args, **kwargs)
|
return method(*args, **kwargs)
|
||||||
|
|
||||||
wrapper = decorator.decorator(wrapper, method.im_func)
|
wrapper = decorator.decorator(wrapper, method.__func__)
|
||||||
wrapper = dbus.service.signal(self._interface_name, out_signature)(wrapper)
|
wrapper = dbus.service.signal(self._interface_name, out_signature)(wrapper)
|
||||||
|
|
||||||
self._dbus_methods[method_name] = wrapper
|
self._dbus_methods[method_name] = wrapper
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ class GuiProfileLoader(object):
|
||||||
# profile dont have main section
|
# profile dont have main section
|
||||||
|
|
||||||
pass
|
pass
|
||||||
for (name, unit) in profile.units.items():
|
for (name, unit) in list(profile.units.items()):
|
||||||
config[name] = unit.options
|
config[name] = unit.options
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
|
|
@ -150,7 +150,7 @@ class GuiProfileLoader(object):
|
||||||
# profile dont have main section
|
# profile dont have main section
|
||||||
|
|
||||||
pass
|
pass
|
||||||
for (name, unit) in profile.units.items():
|
for (name, unit) in list(profile.units.items()):
|
||||||
config[name] = unit.options
|
config[name] = unit.options
|
||||||
|
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
|
@ -159,7 +159,7 @@ class GuiProfileLoader(object):
|
||||||
self._refresh_profiles()
|
self._refresh_profiles()
|
||||||
|
|
||||||
def get_names(self):
|
def get_names(self):
|
||||||
return self.profiles.keys()
|
return list(self.profiles.keys())
|
||||||
|
|
||||||
def get_profile(self, profile):
|
def get_profile(self, profile):
|
||||||
return self.profiles[profile]
|
return self.profiles[profile]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
from inventory import *
|
from .inventory import *
|
||||||
from device_matcher import *
|
from .device_matcher import *
|
||||||
from device_matcher_udev import *
|
from .device_matcher_udev import *
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,10 @@ class DeviceMatcher(object):
|
||||||
which matches all devices is added. The device matches if and only
|
which matches all devices is added. The device matches if and only
|
||||||
if it matches some positive rule, but no negative rule.
|
if it matches some positive rule, but no negative rule.
|
||||||
"""
|
"""
|
||||||
if isinstance(rules, basestring):
|
if isinstance(rules, str):
|
||||||
rules = re.split(r"\s|,\s*", rules)
|
rules = re.split(r"\s|,\s*", rules)
|
||||||
|
|
||||||
positive_rules = filter(lambda rule: not rule.startswith("!") and not rule.strip() == '', rules)
|
positive_rules = [rule for rule in rules if not rule.startswith("!") and not rule.strip() == '']
|
||||||
negative_rules = [rule[1:] for rule in rules if rule not in positive_rules]
|
negative_rules = [rule[1:] for rule in rules if rule not in positive_rules]
|
||||||
|
|
||||||
if len(positive_rules) == 0:
|
if len(positive_rules) == 0:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import device_matcher
|
from . import device_matcher
|
||||||
import re
|
import re
|
||||||
|
|
||||||
__all__ = ["DeviceMatcherUdev"]
|
__all__ = ["DeviceMatcherUdev"]
|
||||||
|
|
@ -12,7 +12,7 @@ class DeviceMatcherUdev(device_matcher.DeviceMatcher):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
properties = ''
|
properties = ''
|
||||||
for key, val in device.items():
|
for key, val in list(device.items()):
|
||||||
properties += key + '=' + val + '\n'
|
properties += key + '=' + val + '\n'
|
||||||
|
|
||||||
return re.search(regex, properties, re.MULTILINE) is not None
|
return re.search(regex, properties, re.MULTILINE) is not None
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
from base import *
|
from .base import *
|
||||||
from repository import *
|
from .repository import *
|
||||||
|
|
|
||||||
|
|
@ -99,19 +99,19 @@ class Monitor(object):
|
||||||
self._refresh_updating_devices()
|
self._refresh_updating_devices()
|
||||||
|
|
||||||
def add_device(self, device):
|
def add_device(self, device):
|
||||||
assert isinstance(device, basestring)
|
assert isinstance(device, str)
|
||||||
if device in self._available_devices:
|
if device in self._available_devices:
|
||||||
self._devices.add(device)
|
self._devices.add(device)
|
||||||
self._updating_devices.add(device)
|
self._updating_devices.add(device)
|
||||||
|
|
||||||
def remove_device(self, device):
|
def remove_device(self, device):
|
||||||
assert isinstance(device, basestring)
|
assert isinstance(device, str)
|
||||||
if device in self._devices:
|
if device in self._devices:
|
||||||
self._devices.remove(device)
|
self._devices.remove(device)
|
||||||
self._updating_devices.remove(device)
|
self._updating_devices.remove(device)
|
||||||
|
|
||||||
def get_load(self):
|
def get_load(self):
|
||||||
return dict(filter(lambda (dev, load): dev in self._devices, self._load.items()))
|
return dict([dev_load for dev_load in list(self._load.items()) if dev_load[0] in self._devices])
|
||||||
|
|
||||||
def get_device_load(self, device):
|
def get_device_load(self, device):
|
||||||
return self._load.get(device, None)
|
return self._load.get(device, None)
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,4 @@ class DiskMonitor(tuned.monitors.Monitor):
|
||||||
@classmethod
|
@classmethod
|
||||||
def _update_disk(cls, dev):
|
def _update_disk(cls, dev):
|
||||||
with open("/sys/block/" + dev + "/stat") as statfile:
|
with open("/sys/block/" + dev + "/stat") as statfile:
|
||||||
cls._load[dev] = map(int, statfile.read().split())
|
cls._load[dev] = list(map(int, statfile.read().split()))
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
from repository import *
|
from .repository import *
|
||||||
import instance
|
from . import instance
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class Plugin(object):
|
||||||
|
|
||||||
def destroy_instances(self):
|
def destroy_instances(self):
|
||||||
"""Destroy all instances."""
|
"""Destroy all instances."""
|
||||||
for instance in self._instances.values():
|
for instance in list(self._instances.values()):
|
||||||
log.debug("destroying instance %s (%s)" % (instance.name, self.name))
|
log.debug("destroying instance %s (%s)" % (instance.name, self.name))
|
||||||
self._destroy_instance(instance)
|
self._destroy_instance(instance)
|
||||||
self._instances.clear()
|
self._instances.clear()
|
||||||
|
|
@ -151,7 +151,7 @@ class Plugin(object):
|
||||||
log.error("Plugin '%s' does not support the 'devices_udev_regex' option", self.name)
|
log.error("Plugin '%s' does not support the 'devices_udev_regex' option", self.name)
|
||||||
return set()
|
return set()
|
||||||
udev_devices = self._device_matcher_udev.match_list(instance.devices_udev_regex, udev_devices)
|
udev_devices = self._device_matcher_udev.match_list(instance.devices_udev_regex, udev_devices)
|
||||||
return set(map(lambda x: x.sys_name, udev_devices))
|
return set([x.sys_name for x in udev_devices])
|
||||||
|
|
||||||
def assign_free_devices(self, instance):
|
def assign_free_devices(self, instance):
|
||||||
if not self._devices_supported:
|
if not self._devices_supported:
|
||||||
|
|
@ -221,7 +221,7 @@ class Plugin(object):
|
||||||
arguments.append("full_rollback")
|
arguments.append("full_rollback")
|
||||||
arguments.append(dev)
|
arguments.append(dev)
|
||||||
log.info("calling script '%s' with arguments '%s'" % (script, str(arguments)))
|
log.info("calling script '%s' with arguments '%s'" % (script, str(arguments)))
|
||||||
log.debug("using environment '%s'" % str(environ.items()))
|
log.debug("using environment '%s'" % str(list(environ.items())))
|
||||||
try:
|
try:
|
||||||
proc = Popen([script] + arguments, stdout=PIPE, stderr=PIPE, close_fds=True, env=environ, \
|
proc = Popen([script] + arguments, stdout=PIPE, stderr=PIPE, close_fds=True, env=environ, \
|
||||||
cwd = dir_name)
|
cwd = dir_name)
|
||||||
|
|
@ -307,7 +307,7 @@ class Plugin(object):
|
||||||
self._cleanup_all_non_device_commands(instance)
|
self._cleanup_all_non_device_commands(instance)
|
||||||
|
|
||||||
def _instance_apply_dynamic(self, instance, device):
|
def _instance_apply_dynamic(self, instance, device):
|
||||||
for option in filter(lambda opt: self._storage_get(instance, self._commands[opt], device) is None, self._options_used_by_dynamic):
|
for option in [opt for opt in self._options_used_by_dynamic if self._storage_get(instance, self._commands[opt], device) is None]:
|
||||||
self._check_and_save_value(instance, self._commands[option], device)
|
self._check_and_save_value(instance, self._commands[option], device)
|
||||||
|
|
||||||
self._instance_update_dynamic(instance, device)
|
self._instance_update_dynamic(instance, device)
|
||||||
|
|
@ -359,13 +359,13 @@ class Plugin(object):
|
||||||
self._commands[command_name] = info
|
self._commands[command_name] = info
|
||||||
|
|
||||||
# sort commands by priority
|
# sort commands by priority
|
||||||
self._commands = collections.OrderedDict(sorted(self._commands.iteritems(), key=lambda (name, info): info["priority"]))
|
self._commands = collections.OrderedDict(sorted(iter(self._commands.items()), key=lambda name_info: name_info[1]["priority"]))
|
||||||
|
|
||||||
def _check_commands(self):
|
def _check_commands(self):
|
||||||
"""
|
"""
|
||||||
Check if all commands are defined correctly.
|
Check if all commands are defined correctly.
|
||||||
"""
|
"""
|
||||||
for command_name, command in self._commands.items():
|
for command_name, command in list(self._commands.items()):
|
||||||
# do not check custom commands
|
# do not check custom commands
|
||||||
if command.get("custom", False):
|
if command.get("custom", False):
|
||||||
continue
|
continue
|
||||||
|
|
@ -400,13 +400,13 @@ class Plugin(object):
|
||||||
#
|
#
|
||||||
|
|
||||||
def _execute_all_non_device_commands(self, instance):
|
def _execute_all_non_device_commands(self, instance):
|
||||||
for command in filter(lambda command: not command["per_device"], self._commands.values()):
|
for command in [command for command in list(self._commands.values()) if not command["per_device"]]:
|
||||||
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
||||||
if new_value is not None:
|
if new_value is not None:
|
||||||
self._execute_non_device_command(instance, command, new_value)
|
self._execute_non_device_command(instance, command, new_value)
|
||||||
|
|
||||||
def _execute_all_device_commands(self, instance, devices):
|
def _execute_all_device_commands(self, instance, devices):
|
||||||
for command in filter(lambda command: command["per_device"], self._commands.values()):
|
for command in [command for command in list(self._commands.values()) if command["per_device"]]:
|
||||||
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
||||||
if new_value is None:
|
if new_value is None:
|
||||||
continue
|
continue
|
||||||
|
|
@ -415,7 +415,7 @@ class Plugin(object):
|
||||||
|
|
||||||
def _verify_all_non_device_commands(self, instance, ignore_missing):
|
def _verify_all_non_device_commands(self, instance, ignore_missing):
|
||||||
ret = True
|
ret = True
|
||||||
for command in filter(lambda command: not command["per_device"], self._commands.values()):
|
for command in [command for command in list(self._commands.values()) if not command["per_device"]]:
|
||||||
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
new_value = self._variables.expand(instance.options.get(command["name"], None))
|
||||||
if new_value is not None:
|
if new_value is not None:
|
||||||
if self._verify_non_device_command(instance, command, new_value, ignore_missing) == False:
|
if self._verify_non_device_command(instance, command, new_value, ignore_missing) == False:
|
||||||
|
|
@ -424,7 +424,7 @@ class Plugin(object):
|
||||||
|
|
||||||
def _verify_all_device_commands(self, instance, devices, ignore_missing):
|
def _verify_all_device_commands(self, instance, devices, ignore_missing):
|
||||||
ret = True
|
ret = True
|
||||||
for command in filter(lambda command: command["per_device"], self._commands.values()):
|
for command in [command for command in list(self._commands.values()) if command["per_device"]]:
|
||||||
new_value = instance.options.get(command["name"], None)
|
new_value = instance.options.get(command["name"], None)
|
||||||
if new_value is None:
|
if new_value is None:
|
||||||
continue
|
continue
|
||||||
|
|
@ -547,12 +547,12 @@ class Plugin(object):
|
||||||
return self._verify_value(command["name"], new_value, current_value, ignore_missing)
|
return self._verify_value(command["name"], new_value, current_value, ignore_missing)
|
||||||
|
|
||||||
def _cleanup_all_non_device_commands(self, instance):
|
def _cleanup_all_non_device_commands(self, instance):
|
||||||
for command in reversed(filter(lambda command: not command["per_device"], self._commands.values())):
|
for command in reversed([command for command in list(self._commands.values()) if not command["per_device"]]):
|
||||||
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
|
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
|
||||||
self._cleanup_non_device_command(instance, command)
|
self._cleanup_non_device_command(instance, command)
|
||||||
|
|
||||||
def _cleanup_all_device_commands(self, instance, devices):
|
def _cleanup_all_device_commands(self, instance, devices):
|
||||||
for command in reversed(filter(lambda command: command["per_device"], self._commands.values())):
|
for command in reversed([command for command in list(self._commands.values()) if command["per_device"]]):
|
||||||
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
|
if (instance.options.get(command["name"], None) is not None) or (command["name"] in self._options_used_by_dynamic):
|
||||||
for device in devices:
|
for device in devices:
|
||||||
self._cleanup_device_command(instance, command, device)
|
self._cleanup_device_command(instance, command, device)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import base
|
from . import base
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
|
|
||||||
|
|
@ -36,7 +36,7 @@ class Plugin(base.Plugin):
|
||||||
if device_name in (self._assigned_devices | self._free_devices):
|
if device_name in (self._assigned_devices | self._free_devices):
|
||||||
return
|
return
|
||||||
|
|
||||||
for instance_name, instance in self._instances.items():
|
for instance_name, instance in list(self._instances.items()):
|
||||||
if len(self._get_matching_devices(instance, [device_name])) == 1:
|
if len(self._get_matching_devices(instance, [device_name])) == 1:
|
||||||
log.info("instance %s: adding new device %s" % (instance_name, device_name))
|
log.info("instance %s: adding new device %s" % (instance_name, device_name))
|
||||||
self._assigned_devices.add(device_name)
|
self._assigned_devices.add(device_name)
|
||||||
|
|
@ -54,7 +54,7 @@ class Plugin(base.Plugin):
|
||||||
if device_name not in (self._assigned_devices | self._free_devices):
|
if device_name not in (self._assigned_devices | self._free_devices):
|
||||||
return
|
return
|
||||||
|
|
||||||
for instance in self._instances.values():
|
for instance in list(self._instances.values()):
|
||||||
if device_name in instance.devices:
|
if device_name in instance.devices:
|
||||||
self._call_device_script(instance, instance.script_post, "unapply", [device_name])
|
self._call_device_script(instance, instance.script_post, "unapply", [device_name])
|
||||||
self._removed_device_unapply_tuning(instance, device_name)
|
self._removed_device_unapply_tuning(instance, device_name)
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
from instance import Instance
|
from .instance import Instance
|
||||||
from factory import Factory
|
from .factory import Factory
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from instance import Instance
|
from .instance import Instance
|
||||||
|
|
||||||
class Factory(object):
|
class Factory(object):
|
||||||
def create(self, *args, **kwargs):
|
def create(self, *args, **kwargs):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import exceptions
|
from . import exceptions
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
|
|
@ -41,7 +41,7 @@ class CPULatencyPlugin(base.Plugin):
|
||||||
self._assigned_devices = set()
|
self._assigned_devices = set()
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("cpu", x), devices)
|
return [self._hardware_inventory.get_device("cpu", x) for x in devices]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_config_options(self):
|
def _get_config_options(self):
|
||||||
|
|
@ -95,7 +95,7 @@ class CPULatencyPlugin(base.Plugin):
|
||||||
instance._has_dynamic_tuning = False
|
instance._has_dynamic_tuning = False
|
||||||
|
|
||||||
# only the first instance of the plugin can control the latency
|
# only the first instance of the plugin can control the latency
|
||||||
if self._instances.values()[0] == instance:
|
if list(self._instances.values())[0] == instance:
|
||||||
instance._first_instance = True
|
instance._first_instance = True
|
||||||
try:
|
try:
|
||||||
self._cpu_latency_fd = os.open(consts.PATH_CPU_DMA_LATENCY, os.O_WRONLY)
|
self._cpu_latency_fd = os.open(consts.PATH_CPU_DMA_LATENCY, os.O_WRONLY)
|
||||||
|
|
@ -236,7 +236,7 @@ class CPULatencyPlugin(base.Plugin):
|
||||||
if governor is None:
|
if governor is None:
|
||||||
log.debug("ignoring sampling_down_factor setting for CPU '%s', cannot match governor" % device)
|
log.debug("ignoring sampling_down_factor setting for CPU '%s', cannot match governor" % device)
|
||||||
return None
|
return None
|
||||||
if governor not in self._governors_map.values():
|
if governor not in list(self._governors_map.values()):
|
||||||
self._governors_map[device] = governor
|
self._governors_map[device] = governor
|
||||||
path = self._sampling_down_factor_path(governor)
|
path = self._sampling_down_factor_path(governor)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import errno
|
import errno
|
||||||
import hotplug
|
from . import hotplug
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -34,7 +34,7 @@ class DiskPlugin(hotplug.Plugin):
|
||||||
self._assigned_devices = set()
|
self._assigned_devices = set()
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("block", x), devices)
|
return [self._hardware_inventory.get_device("block", x) for x in devices]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _device_is_supported(cls, device):
|
def _device_is_supported(cls, device):
|
||||||
|
|
@ -196,12 +196,12 @@ class DiskPlugin(hotplug.Plugin):
|
||||||
instance._stats[device]["new"] = new_load
|
instance._stats[device]["new"] = new_load
|
||||||
|
|
||||||
# load difference
|
# load difference
|
||||||
diff = map(lambda (new, old): new - old, zip(new_load, old_load))
|
diff = [new_old[0] - new_old[1] for new_old in zip(new_load, old_load)]
|
||||||
instance._stats[device]["diff"] = diff
|
instance._stats[device]["diff"] = diff
|
||||||
|
|
||||||
# adapt maximum expected load if the difference is higer
|
# adapt maximum expected load if the difference is higer
|
||||||
old_max_load = instance._stats[device]["max"]
|
old_max_load = instance._stats[device]["max"]
|
||||||
max_load = map(lambda pair: max(pair), zip(old_max_load, diff))
|
max_load = [max(pair) for pair in zip(old_max_load, diff)]
|
||||||
instance._stats[device]["max"] = max_load
|
instance._stats[device]["max"] = max_load
|
||||||
|
|
||||||
# read/write ratio
|
# read/write ratio
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
import exceptions
|
from . import exceptions
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import re
|
import re
|
||||||
import os.path
|
import os.path
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -45,7 +45,7 @@ class ModulesPlugin(base.Plugin):
|
||||||
retcode = 0
|
retcode = 0
|
||||||
skip_check = False
|
skip_check = False
|
||||||
reload_list = []
|
reload_list = []
|
||||||
for option, value in instance._modules.items():
|
for option, value in list(instance._modules.items()):
|
||||||
module = self._variables.expand(option)
|
module = self._variables.expand(option)
|
||||||
v = self._variables.expand(value)
|
v = self._variables.expand(value)
|
||||||
if not skip_check:
|
if not skip_check:
|
||||||
|
|
@ -78,7 +78,7 @@ class ModulesPlugin(base.Plugin):
|
||||||
# not all modules exports all their parameteters through sysfs, so hardcode check with ignore_missing
|
# not all modules exports all their parameteters through sysfs, so hardcode check with ignore_missing
|
||||||
ignore_missing = True
|
ignore_missing = True
|
||||||
r = re.compile(r"\s+")
|
r = re.compile(r"\s+")
|
||||||
for option, value in instance._modules.items():
|
for option, value in list(instance._modules.items()):
|
||||||
module = self._variables.expand(option)
|
module = self._variables.expand(option)
|
||||||
v = self._variables.expand(value)
|
v = self._variables.expand(value)
|
||||||
v = re.sub(r"^\s*\+r\s*,?\s*", "", v)
|
v = re.sub(r"^\s*\+r\s*,?\s*", "", v)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
from subprocess import Popen,PIPE
|
from subprocess import Popen,PIPE
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -24,7 +24,7 @@ class MountsPlugin(base.Plugin):
|
||||||
current_disk = None
|
current_disk = None
|
||||||
|
|
||||||
stdout, stderr = Popen(["lsblk", "-rno", "TYPE,RM,KNAME,FSTYPE,MOUNTPOINT"], stdout=PIPE, stderr=PIPE, close_fds=True).communicate()
|
stdout, stderr = Popen(["lsblk", "-rno", "TYPE,RM,KNAME,FSTYPE,MOUNTPOINT"], stdout=PIPE, stderr=PIPE, close_fds=True).communicate()
|
||||||
for columns in map(lambda line: line.split(), stdout.splitlines()):
|
for columns in [line.split() for line in stdout.splitlines()]:
|
||||||
if len(columns) < 3:
|
if len(columns) < 3:
|
||||||
continue
|
continue
|
||||||
device_type, device_removable, device_name = columns[:3]
|
device_type, device_removable, device_name = columns[:3]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.nettool import ethcard
|
from tuned.utils.nettool import ethcard
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -34,7 +34,7 @@ class NetTuningPlugin(base.Plugin):
|
||||||
log.debug("devices: %s" % str(self._free_devices));
|
log.debug("devices: %s" % str(self._free_devices));
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("net", x), devices)
|
return [self._hardware_inventory.get_device("net", x) for x in devices]
|
||||||
|
|
||||||
def _instance_init(self, instance):
|
def _instance_init(self, instance):
|
||||||
instance._has_static_tuning = True
|
instance._has_static_tuning = True
|
||||||
|
|
@ -58,7 +58,7 @@ class NetTuningPlugin(base.Plugin):
|
||||||
self._instance_update_dynamic(instance, device)
|
self._instance_update_dynamic(instance, device)
|
||||||
|
|
||||||
def _instance_update_dynamic(self, instance, device):
|
def _instance_update_dynamic(self, instance, device):
|
||||||
load = map(lambda value: int(value), instance._load_monitor.get_device_load(device))
|
load = [int(value) for value in instance._load_monitor.get_device_load(device)]
|
||||||
if load is None:
|
if load is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -145,12 +145,12 @@ class NetTuningPlugin(base.Plugin):
|
||||||
instance._stats[device]["new"] = new_load
|
instance._stats[device]["new"] = new_load
|
||||||
|
|
||||||
# load difference
|
# load difference
|
||||||
diff = map(lambda (new, old): new - old, zip(new_load, old_load))
|
diff = [new_old[0] - new_old[1] for new_old in zip(new_load, old_load)]
|
||||||
instance._stats[device]["diff"] = diff
|
instance._stats[device]["diff"] = diff
|
||||||
|
|
||||||
# adapt maximum expected load if the difference is higer
|
# adapt maximum expected load if the difference is higer
|
||||||
old_max_load = instance._stats[device]["max"]
|
old_max_load = instance._stats[device]["max"]
|
||||||
max_load = map(lambda pair: max(pair), zip(old_max_load, diff))
|
max_load = [max(pair) for pair in zip(old_max_load, diff)]
|
||||||
instance._stats[device]["max"] = max_load
|
instance._stats[device]["max"] = max_load
|
||||||
|
|
||||||
# read/write ratio
|
# read/write ratio
|
||||||
|
|
@ -190,7 +190,7 @@ class NetTuningPlugin(base.Plugin):
|
||||||
if lv == 0:
|
if lv == 0:
|
||||||
return dict()
|
return dict()
|
||||||
# convert flat list to dict
|
# convert flat list to dict
|
||||||
return dict(zip(v[::2], v[1::2]))
|
return dict(list(zip(v[::2], v[1::2])))
|
||||||
|
|
||||||
# parse features/coalesce device parameters (those returned by ethtool)
|
# parse features/coalesce device parameters (those returned by ethtool)
|
||||||
def _parse_device_parameters(self, value):
|
def _parse_device_parameters(self, value):
|
||||||
|
|
@ -206,13 +206,12 @@ class NetTuningPlugin(base.Plugin):
|
||||||
"tx-frame-high:": "tx-frames-high:",
|
"tx-frame-high:": "tx-frames-high:",
|
||||||
"large-receive-offload:": "lro:"}, value)
|
"large-receive-offload:": "lro:"}, value)
|
||||||
# remove empty lines, remove fixed parameters (those with "[fixed]")
|
# remove empty lines, remove fixed parameters (those with "[fixed]")
|
||||||
vl = filter(lambda v: len(str(v)) > 0 and not re.search("\[fixed\]$", str(v)), value.split('\n'))
|
vl = [v for v in value.split('\n') if len(str(v)) > 0 and not re.search("\[fixed\]$", str(v))]
|
||||||
if len(vl) < 2:
|
if len(vl) < 2:
|
||||||
return None
|
return None
|
||||||
# skip first line (device name), split to key/value,
|
# skip first line (device name), split to key/value,
|
||||||
# remove pairs which are not key/value
|
# remove pairs which are not key/value
|
||||||
return dict(filter(lambda u: len(u) == 2, \
|
return dict([u for u in [re.split(r":\s*", str(v)) for v in vl[1:]] if len(u) == 2])
|
||||||
map(lambda v: re.split(r":\s*", str(v)), vl[1:])))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _nf_conntrack_hashsize_path(self):
|
def _nf_conntrack_hashsize_path(self):
|
||||||
|
|
@ -285,8 +284,8 @@ class NetTuningPlugin(base.Plugin):
|
||||||
"RX": "rx",
|
"RX": "rx",
|
||||||
"TX": "tx"}, s)
|
"TX": "tx"}, s)
|
||||||
l = s.split("\n")[1:]
|
l = s.split("\n")[1:]
|
||||||
l = filter(lambda x: x != '' and not re.search(r"\[fixed\]", x), l)
|
l = [x for x in l if x != '' and not re.search(r"\[fixed\]", x)]
|
||||||
return dict(filter(lambda x: len(x) == 2, map(lambda x: re.split(r":\s*", x), l)))
|
return dict([x for x in [re.split(r":\s*", x) for x in l] if len(x) == 2])
|
||||||
|
|
||||||
# parse output of ethtool -g
|
# parse output of ethtool -g
|
||||||
def _parse_ring_parameters(self, s):
|
def _parse_ring_parameters(self, s):
|
||||||
|
|
@ -298,8 +297,8 @@ class NetTuningPlugin(base.Plugin):
|
||||||
"RX Jumbo": "rx-jumbo",
|
"RX Jumbo": "rx-jumbo",
|
||||||
"TX": "tx"}, s)
|
"TX": "tx"}, s)
|
||||||
l = s.split("\n")
|
l = s.split("\n")
|
||||||
l = filter(lambda x: x != '', l)
|
l = [x for x in l if x != '']
|
||||||
l = filter(lambda x: len(x) == 2, map(lambda x: re.split(r":\s*", x), l))
|
l = [x for x in [re.split(r":\s*", x) for x in l] if len(x) == 2]
|
||||||
return dict(l)
|
return dict(l)
|
||||||
|
|
||||||
def _get_device_parameters(self, context, device):
|
def _get_device_parameters(self, context, device):
|
||||||
|
|
@ -338,10 +337,10 @@ class NetTuningPlugin(base.Plugin):
|
||||||
cd = self._get_device_parameters(context, device)
|
cd = self._get_device_parameters(context, device)
|
||||||
d = self._set_device_parameters(context, value, device, verify)
|
d = self._set_device_parameters(context, value, device, verify)
|
||||||
# backup only parameters which are changed
|
# backup only parameters which are changed
|
||||||
sd = dict(filter(lambda (k, v): k in d, cd.items()))
|
sd = dict([k_v for k_v in list(cd.items()) if k_v[0] in d])
|
||||||
if len(d) != len(sd):
|
if len(d) != len(sd):
|
||||||
log.error("unable to save previous %s, wanted to save: '%s', but read: '%s'" % \
|
log.error("unable to save previous %s, wanted to save: '%s', but read: '%s'" % \
|
||||||
(context, str(d.keys()), str(cd.items())))
|
(context, str(list(d.keys())), str(list(cd.items()))))
|
||||||
return False
|
return False
|
||||||
if verify:
|
if verify:
|
||||||
return self._cmd.dict2list(d) == self._cmd.dict2list(sd)
|
return self._cmd.dict2list(d) == self._cmd.dict2list(sd)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
# perf code was borrowed from kernel/tools/perf/python/twatch.py
|
# perf code was borrowed from kernel/tools/perf/python/twatch.py
|
||||||
# thanks to Arnaldo Carvalho de Melo <acme@redhat.com>
|
# thanks to Arnaldo Carvalho de Melo <acme@redhat.com>
|
||||||
|
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import re
|
import re
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
|
|
@ -110,8 +110,7 @@ class SchedulerPlugin(base.Plugin):
|
||||||
(rc, out) = self._cmd.execute(["ps", "-eopid,cmd", "--no-headers"])
|
(rc, out) = self._cmd.execute(["ps", "-eopid,cmd", "--no-headers"])
|
||||||
if rc != 0 or len(out) <= 0:
|
if rc != 0 or len(out) <= 0:
|
||||||
return None
|
return None
|
||||||
return dict(map(lambda (pid, cmd): (int(pid.lstrip()), cmd.lstrip()),
|
return dict([(int(pid_cmd1[0].lstrip()), pid_cmd1[1].lstrip()) for pid_cmd1 in [i for i in [s.split(None, 1) for s in out.split("\n")] if len(i) == 2]])
|
||||||
filter(lambda i: len(i) == 2, map(lambda s: s.split(None, 1), out.split("\n")))))
|
|
||||||
|
|
||||||
def _parse_val(self, val):
|
def _parse_val(self, val):
|
||||||
v = val.split(":", 1)
|
v = val.split(":", 1)
|
||||||
|
|
@ -246,9 +245,9 @@ class SchedulerPlugin(base.Plugin):
|
||||||
if ps is None:
|
if ps is None:
|
||||||
log.error("error applying tuning, cannot get information about running processes")
|
log.error("error applying tuning, cannot get information about running processes")
|
||||||
return
|
return
|
||||||
instance._sched_cfg = map(lambda (option, value): (option, str(value).split(":", 4)), instance._scheduler.items())
|
instance._sched_cfg = [(option_value[0], str(option_value[1]).split(":", 4)) for option_value in list(instance._scheduler.items())]
|
||||||
buf = filter(lambda (option, vals): re.match(r"group\.", option) and len(vals) == 5, instance._sched_cfg)
|
buf = [option_vals3 for option_vals3 in instance._sched_cfg if re.match(r"group\.", option_vals3[0]) and len(option_vals3[1]) == 5]
|
||||||
instance._sched_cfg = sorted(buf, key=lambda (option, vals): vals[0])
|
instance._sched_cfg = sorted(buf, key=lambda option_vals: option_vals[1][0])
|
||||||
sched_all = dict()
|
sched_all = dict()
|
||||||
# for runtime tunning
|
# for runtime tunning
|
||||||
instance._sched_lookup = {}
|
instance._sched_lookup = {}
|
||||||
|
|
@ -258,15 +257,15 @@ class SchedulerPlugin(base.Plugin):
|
||||||
except re.error as e:
|
except re.error as e:
|
||||||
log.error("error compiling regular expression: '%s'" % str(vals[4]))
|
log.error("error compiling regular expression: '%s'" % str(vals[4]))
|
||||||
continue
|
continue
|
||||||
processes = filter(lambda (pid, cmd): re.search(r, cmd) is not None, ps.items())
|
processes = [pid_cmd2 for pid_cmd2 in list(ps.items()) if re.search(r, pid_cmd2[1]) is not None]
|
||||||
#cmd - process name, option - group name, vals[0] - rule prio, vals[1] - sched, vals[2] - prio,
|
#cmd - process name, option - group name, vals[0] - rule prio, vals[1] - sched, vals[2] - prio,
|
||||||
#vals[3] - affinity, vals[4] - regex
|
#vals[3] - affinity, vals[4] - regex
|
||||||
sched = dict(map(lambda (pid, cmd): (pid, (cmd, option, vals[1], vals[2], vals[3], vals[4])), processes))
|
sched = dict([(pid_cmd[0], (pid_cmd[1], option, vals[1], vals[2], vals[3], vals[4])) for pid_cmd in processes])
|
||||||
sched_all.update(sched)
|
sched_all.update(sched)
|
||||||
v4 = str(vals[4]).replace("(", r"\(")
|
v4 = str(vals[4]).replace("(", r"\(")
|
||||||
v4 = v4.replace(")", r"\)")
|
v4 = v4.replace(")", r"\)")
|
||||||
instance._sched_lookup[v4] = [vals[1], vals[2], vals[3]]
|
instance._sched_lookup[v4] = [vals[1], vals[2], vals[3]]
|
||||||
for pid, vals in sched_all.items():
|
for pid, vals in list(sched_all.items()):
|
||||||
#vals[0] - process name, vals[1] - rule prio, vals[2] - sched, vals[3] - prio, vals[4] - affinity,
|
#vals[0] - process name, vals[1] - rule prio, vals[2] - sched, vals[3] - prio, vals[4] - affinity,
|
||||||
#vals[5] - regex
|
#vals[5] - regex
|
||||||
self._tune_process(instance, pid, vals[0], vals[2], vals[3], vals[4])
|
self._tune_process(instance, pid, vals[0], vals[2], vals[3], vals[4])
|
||||||
|
|
@ -282,7 +281,7 @@ class SchedulerPlugin(base.Plugin):
|
||||||
instance._terminate.set()
|
instance._terminate.set()
|
||||||
instance._thread.join()
|
instance._thread.join()
|
||||||
|
|
||||||
for pid, vals in instance._scheduler_original.items():
|
for pid, vals in list(instance._scheduler_original.items()):
|
||||||
# if command line for the pid didn't change, it's very probably the same process
|
# if command line for the pid didn't change, it's very probably the same process
|
||||||
try:
|
try:
|
||||||
if ps[pid] == vals[0]:
|
if ps[pid] == vals[0]:
|
||||||
|
|
@ -335,7 +334,7 @@ class SchedulerPlugin(base.Plugin):
|
||||||
if verify:
|
if verify:
|
||||||
return None
|
return None
|
||||||
if enabling and value is not None:
|
if enabling and value is not None:
|
||||||
self._ps_whitelist = "|".join(map(lambda v: "(%s)" % v, re.split(r"(?<!\\);", str(value))))
|
self._ps_whitelist = "|".join(["(%s)" % v for v in re.split(r"(?<!\\);", str(value))])
|
||||||
|
|
||||||
@command_custom("ps_blacklist", per_device = False)
|
@command_custom("ps_blacklist", per_device = False)
|
||||||
def _ps_blacklist(self, enabling, value, verify, ignore_missing):
|
def _ps_blacklist(self, enabling, value, verify, ignore_missing):
|
||||||
|
|
@ -343,7 +342,7 @@ class SchedulerPlugin(base.Plugin):
|
||||||
if verify:
|
if verify:
|
||||||
return None
|
return None
|
||||||
if enabling and value is not None:
|
if enabling and value is not None:
|
||||||
self._ps_blacklist = "|".join(map(lambda v: "(%s)" % v, re.split(r"(?<!\\);", str(value))))
|
self._ps_blacklist = "|".join(["(%s)" % v for v in re.split(r"(?<!\\);", str(value))])
|
||||||
|
|
||||||
# TODO: merge with _get_affinity
|
# TODO: merge with _get_affinity
|
||||||
def _get_affinity2(self, pid):
|
def _get_affinity2(self, pid):
|
||||||
|
|
@ -391,8 +390,8 @@ class SchedulerPlugin(base.Plugin):
|
||||||
if not self._set_affinity2(obj, _affinity):
|
if not self._set_affinity2(obj, _affinity):
|
||||||
continue
|
continue
|
||||||
# process threads
|
# process threads
|
||||||
if not threads and objs[obj].has_key("threads"):
|
if not threads and "threads" in objs[obj]:
|
||||||
self._set_all_obj_affinity(dict(objs[obj]["threads"].items()), affinity, True, intersect)
|
self._set_all_obj_affinity(dict(list(objs[obj]["threads"].items())), affinity, True, intersect)
|
||||||
|
|
||||||
def _get_stat_comm(self, o):
|
def _get_stat_comm(self, o):
|
||||||
try:
|
try:
|
||||||
|
|
@ -405,15 +404,15 @@ class SchedulerPlugin(base.Plugin):
|
||||||
affinity_hex = self._cmd.cpulist2hex(_affinity)
|
affinity_hex = self._cmd.cpulist2hex(_affinity)
|
||||||
ps = procfs.pidstats()
|
ps = procfs.pidstats()
|
||||||
ps.reload_threads()
|
ps.reload_threads()
|
||||||
psl = filter(lambda v: re.search(self._ps_whitelist, self._get_stat_comm(v)) is not None, ps.values())
|
psl = [v for v in list(ps.values()) if re.search(self._ps_whitelist, self._get_stat_comm(v)) is not None]
|
||||||
if self._ps_blacklist != "":
|
if self._ps_blacklist != "":
|
||||||
psl = filter(lambda v: re.search(self._ps_blacklist, self._get_stat_comm(v)) is None, psl)
|
psl = [v for v in psl if re.search(self._ps_blacklist, self._get_stat_comm(v)) is None]
|
||||||
psd = dict(map(lambda v: (v.pid, v), psl))
|
psd = dict([(v.pid, v) for v in psl])
|
||||||
self._set_all_obj_affinity(psd, affinity, False, intersect)
|
self._set_all_obj_affinity(psd, affinity, False, intersect)
|
||||||
|
|
||||||
# process IRQs
|
# process IRQs
|
||||||
irqs = procfs.interrupts()
|
irqs = procfs.interrupts()
|
||||||
for irq in irqs.keys():
|
for irq in list(irqs.keys()):
|
||||||
try:
|
try:
|
||||||
prev_affinity = irqs[irq]["affinity"]
|
prev_affinity = irqs[irq]["affinity"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
import base
|
from . import base
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import os
|
import os
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
|
|
@ -35,7 +35,7 @@ class ScriptPlugin(base.Plugin):
|
||||||
environ = os.environ
|
environ = os.environ
|
||||||
environ.update(self._variables.get_env())
|
environ.update(self._variables.get_env())
|
||||||
log.info("calling script '%s' with arguments '%s'" % (script, str(arguments)))
|
log.info("calling script '%s' with arguments '%s'" % (script, str(arguments)))
|
||||||
log.debug("using environment '%s'" % str(environ.items()))
|
log.debug("using environment '%s'" % str(list(environ.items())))
|
||||||
try:
|
try:
|
||||||
proc = Popen([script] + arguments, stdout=PIPE, stderr=PIPE, close_fds=True, env=environ, \
|
proc = Popen([script] + arguments, stdout=PIPE, stderr=PIPE, close_fds=True, env=environ, \
|
||||||
cwd = os.path.dirname(script))
|
cwd = os.path.dirname(script))
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import errno
|
import errno
|
||||||
import hotplug
|
from . import hotplug
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -29,7 +29,7 @@ class SCSIHostPlugin(hotplug.Plugin):
|
||||||
self._assigned_devices = set()
|
self._assigned_devices = set()
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("scsi", x), devices)
|
return [self._hardware_inventory.get_device("scsi", x) for x in devices]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _device_is_supported(cls, device):
|
def _device_is_supported(cls, device):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.plugins import exceptions
|
from tuned.plugins import exceptions
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -40,7 +40,7 @@ class SysctlPlugin(base.Plugin):
|
||||||
self._storage.unset(self._sysctl_storage_key(instance))
|
self._storage.unset(self._sysctl_storage_key(instance))
|
||||||
|
|
||||||
def _instance_apply_static(self, instance):
|
def _instance_apply_static(self, instance):
|
||||||
for option, value in instance._sysctl.items():
|
for option, value in list(instance._sysctl.items()):
|
||||||
original_value = self._read_sysctl(option)
|
original_value = self._read_sysctl(option)
|
||||||
if original_value != None:
|
if original_value != None:
|
||||||
instance._sysctl_original[option] = original_value
|
instance._sysctl_original[option] = original_value
|
||||||
|
|
@ -56,14 +56,14 @@ class SysctlPlugin(base.Plugin):
|
||||||
ret = True
|
ret = True
|
||||||
# override, so always skip missing
|
# override, so always skip missing
|
||||||
ignore_missing = True
|
ignore_missing = True
|
||||||
for option, value in instance._sysctl.items():
|
for option, value in list(instance._sysctl.items()):
|
||||||
curr_val = self._read_sysctl(option)
|
curr_val = self._read_sysctl(option)
|
||||||
if self._verify_value(option, self._cmd.remove_ws(self._variables.expand(value)), curr_val, ignore_missing) == False:
|
if self._verify_value(option, self._cmd.remove_ws(self._variables.expand(value)), curr_val, ignore_missing) == False:
|
||||||
ret = False
|
ret = False
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _instance_unapply_static(self, instance, full_rollback = False):
|
def _instance_unapply_static(self, instance, full_rollback = False):
|
||||||
for option, value in instance._sysctl_original.items():
|
for option, value in list(instance._sysctl_original.items()):
|
||||||
self._write_sysctl(option, value)
|
self._write_sysctl(option, value)
|
||||||
|
|
||||||
def _execute_sysctl(self, arguments):
|
def _execute_sysctl(self, arguments):
|
||||||
|
|
@ -74,7 +74,7 @@ class SysctlPlugin(base.Plugin):
|
||||||
def _read_sysctl(self, option):
|
def _read_sysctl(self, option):
|
||||||
retcode, stdout = self._execute_sysctl(["-e", option])
|
retcode, stdout = self._execute_sysctl(["-e", option])
|
||||||
if retcode == 0:
|
if retcode == 0:
|
||||||
parts = map(lambda value: self._cmd.remove_ws(value), stdout.split("=", 1))
|
parts = [self._cmd.remove_ws(value) for value in stdout.split("=", 1)]
|
||||||
if len(parts) == 2:
|
if len(parts) == 2:
|
||||||
option, value = parts
|
option, value = parts
|
||||||
return value
|
return value
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import base
|
from . import base
|
||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
import os.path
|
import os.path
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from subprocess import *
|
from subprocess import *
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -25,14 +25,14 @@ class SysfsPlugin(base.Plugin):
|
||||||
instance._has_dynamic_tuning = False
|
instance._has_dynamic_tuning = False
|
||||||
instance._has_static_tuning = True
|
instance._has_static_tuning = True
|
||||||
|
|
||||||
instance._sysfs = dict(map(lambda (key, value): (os.path.normpath(key), value), instance.options.items()))
|
instance._sysfs = dict([(os.path.normpath(key_value[0]), key_value[1]) for key_value in list(instance.options.items())])
|
||||||
instance._sysfs_original = {}
|
instance._sysfs_original = {}
|
||||||
|
|
||||||
def _instance_cleanup(self, instance):
|
def _instance_cleanup(self, instance):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _instance_apply_static(self, instance):
|
def _instance_apply_static(self, instance):
|
||||||
for key, value in instance._sysfs.items():
|
for key, value in list(instance._sysfs.items()):
|
||||||
v = self._variables.expand(value)
|
v = self._variables.expand(value)
|
||||||
for f in glob.iglob(key):
|
for f in glob.iglob(key):
|
||||||
if self._check_sysfs(f):
|
if self._check_sysfs(f):
|
||||||
|
|
@ -43,7 +43,7 @@ class SysfsPlugin(base.Plugin):
|
||||||
|
|
||||||
def _instance_verify_static(self, instance, ignore_missing):
|
def _instance_verify_static(self, instance, ignore_missing):
|
||||||
ret = True
|
ret = True
|
||||||
for key, value in instance._sysfs.items():
|
for key, value in list(instance._sysfs.items()):
|
||||||
v = self._variables.expand(value)
|
v = self._variables.expand(value)
|
||||||
for f in glob.iglob(key):
|
for f in glob.iglob(key):
|
||||||
if self._check_sysfs(f):
|
if self._check_sysfs(f):
|
||||||
|
|
@ -53,7 +53,7 @@ class SysfsPlugin(base.Plugin):
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _instance_unapply_static(self, instance, full_rollback = False):
|
def _instance_unapply_static(self, instance, full_rollback = False):
|
||||||
for key, value in instance._sysfs_original.items():
|
for key, value in list(instance._sysfs_original.items()):
|
||||||
self._write_sysfs(key, value)
|
self._write_sysfs(key, value)
|
||||||
|
|
||||||
def _check_sysfs(self, sysfs_file):
|
def _check_sysfs(self, sysfs_file):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import exceptions
|
from . import exceptions
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import glob
|
import glob
|
||||||
|
|
@ -22,7 +22,7 @@ class USBPlugin(base.Plugin):
|
||||||
self._cmd = commands()
|
self._cmd = commands()
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("usb", x), devices)
|
return [self._hardware_inventory.get_device("usb", x) for x in devices]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_config_options(self):
|
def _get_config_options(self):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
import os
|
import os
|
||||||
|
|
@ -24,7 +24,7 @@ class VideoPlugin(base.Plugin):
|
||||||
self._cmd = commands()
|
self._cmd = commands()
|
||||||
|
|
||||||
def _get_device_objects(self, devices):
|
def _get_device_objects(self, devices):
|
||||||
return map(lambda x: self._hardware_inventory.get_device("drm", x), devices)
|
return [self._hardware_inventory.get_device("drm", x) for x in devices]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_config_options(self):
|
def _get_config_options(self):
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import base
|
from . import base
|
||||||
from decorators import *
|
from .decorators import *
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ from tuned.profiles.unit import *
|
||||||
from tuned.profiles.exceptions import *
|
from tuned.profiles.exceptions import *
|
||||||
from tuned.profiles.factory import *
|
from tuned.profiles.factory import *
|
||||||
from tuned.profiles.merger import *
|
from tuned.profiles.merger import *
|
||||||
import functions
|
from . import functions
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
from repository import Repository
|
from .repository import Repository
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
from tuned.profiles.exceptions import InvalidProfileException
|
from tuned.profiles.exceptions import InvalidProfileException
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
from tuned.profiles.exceptions import InvalidProfileException
|
from tuned.profiles.exceptions import InvalidProfileException
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
class execute(base.Function):
|
class execute(base.Function):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
log = tuned.logs.get()
|
log = tuned.logs.get()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
class kb2s(base.Function):
|
class kb2s(base.Function):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
class s2kb(base.Function):
|
class s2kb(base.Function):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
class strip(base.Function):
|
class strip(base.Function):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import base
|
from . import base
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
||||||
class virt_check(base.Function):
|
class virt_check(base.Function):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
import repository
|
from . import repository
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -46,7 +46,7 @@ class Functions():
|
||||||
sl = re.split(r'(?<!\\):', self._str[_from:self._cnt])
|
sl = re.split(r'(?<!\\):', self._str[_from:self._cnt])
|
||||||
if sl[0] != "${f":
|
if sl[0] != "${f":
|
||||||
return
|
return
|
||||||
sl = map(lambda v: str(v).replace("\:", ":"), sl)
|
sl = [str(v).replace("\:", ":") for v in sl]
|
||||||
if not re.match(r'\w+$', sl[1]):
|
if not re.match(r'\w+$', sl[1]):
|
||||||
log.error("invalid function name '%s'" % sl[1])
|
log.error("invalid function name '%s'" % sl[1])
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from tuned.utils.plugin_loader import PluginLoader
|
from tuned.utils.plugin_loader import PluginLoader
|
||||||
import base
|
from . import base
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
|
|
@ -38,6 +38,6 @@ class Repository(PluginLoader):
|
||||||
def delete(self, function):
|
def delete(self, function):
|
||||||
assert isinstance(function, self._interface)
|
assert isinstance(function, self._interface)
|
||||||
log.debug("removing function %s" % function)
|
log.debug("removing function %s" % function)
|
||||||
for k, v in self._functions.items():
|
for k, v in list(self._functions.items()):
|
||||||
if v == function:
|
if v == function:
|
||||||
del self._functions[k]
|
del self._functions[k]
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ class Loader(object):
|
||||||
if type(profile_names) is not list:
|
if type(profile_names) is not list:
|
||||||
profile_names = profile_names.split()
|
profile_names = profile_names.split()
|
||||||
|
|
||||||
profile_names = filter(self.safe_name, profile_names)
|
profile_names = list(filter(self.safe_name, profile_names))
|
||||||
if len(profile_names) == 0:
|
if len(profile_names) == 0:
|
||||||
raise InvalidProfileException("No profile or invalid profiles were specified.")
|
raise InvalidProfileException("No profile or invalid profiles were specified.")
|
||||||
|
|
||||||
|
|
@ -93,10 +93,10 @@ class Loader(object):
|
||||||
raise InvalidProfileException("Cannot parse '%s'." % file_name, e)
|
raise InvalidProfileException("Cannot parse '%s'." % file_name, e)
|
||||||
|
|
||||||
config = collections.OrderedDict()
|
config = collections.OrderedDict()
|
||||||
for section in config_obj.keys():
|
for section in list(config_obj.keys()):
|
||||||
config[section] = collections.OrderedDict()
|
config[section] = collections.OrderedDict()
|
||||||
try:
|
try:
|
||||||
keys = config_obj[section].keys()
|
keys = list(config_obj[section].keys())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise InvalidProfileException("Error parsing section '%s' in file '%s'." % (section, file_name))
|
raise InvalidProfileException("Error parsing section '%s' in file '%s'." % (section, file_name))
|
||||||
for option in keys:
|
for option in keys:
|
||||||
|
|
|
||||||
|
|
@ -102,4 +102,4 @@ class Locator(object):
|
||||||
return sorted(self.list_profiles())
|
return sorted(self.list_profiles())
|
||||||
|
|
||||||
def get_known_names_summary(self):
|
def get_known_names_summary(self):
|
||||||
return map(lambda profile: (profile, self.get_profile_attrs(profile, [consts.PROFILE_ATTR_SUMMARY], [""])[2]), sorted(self.list_profiles()))
|
return [(profile, self.get_profile_attrs(profile, [consts.PROFILE_ATTR_SUMMARY], [""])[2]) for profile in sorted(self.list_profiles())]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import collections
|
import collections
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
class Merger(object):
|
class Merger(object):
|
||||||
"""
|
"""
|
||||||
|
|
@ -25,7 +26,7 @@ class Merger(object):
|
||||||
|
|
||||||
profile_a.options.update(profile_b.options)
|
profile_a.options.update(profile_b.options)
|
||||||
|
|
||||||
for unit_name, unit in profile_b.units.items():
|
for unit_name, unit in list(profile_b.units.items()):
|
||||||
if unit.replace or unit_name not in profile_a.units:
|
if unit.replace or unit_name not in profile_a.units:
|
||||||
profile_a.units[unit_name] = unit
|
profile_a.units[unit_name] = unit
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import functions.functions as functions
|
from .functions import functions as functions
|
||||||
import tuned.consts as consts
|
import tuned.consts as consts
|
||||||
from tuned.utils.commands import commands
|
from tuned.utils.commands import commands
|
||||||
from configobj import ConfigObj, ConfigObjError
|
from configobj import ConfigObj, ConfigObjError
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import interfaces
|
from . import interfaces
|
||||||
import storage
|
from . import storage
|
||||||
|
|
||||||
class Factory(interfaces.Factory):
|
class Factory(interfaces.Factory):
|
||||||
__slots__ = ["_storage_provider"]
|
__slots__ = ["_storage_provider"]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import interfaces
|
from . import interfaces
|
||||||
import tuned.logs
|
import tuned.logs
|
||||||
import pickle
|
import pickle
|
||||||
import os
|
import os
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
from manager import *
|
from .manager import *
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class Manager(object):
|
||||||
|
|
||||||
def create(self, instances_config):
|
def create(self, instances_config):
|
||||||
instance_info_list = []
|
instance_info_list = []
|
||||||
for instance_name, instance_info in instances_config.items():
|
for instance_name, instance_info in list(instances_config.items()):
|
||||||
if not instance_info.enabled:
|
if not instance_info.enabled:
|
||||||
log.debug("skipping disabled instance '%s'" % instance_name)
|
log.debug("skipping disabled instance '%s'" % instance_name)
|
||||||
continue
|
continue
|
||||||
|
|
@ -45,7 +45,7 @@ class Manager(object):
|
||||||
instance_info.options.pop("priority")
|
instance_info.options.pop("priority")
|
||||||
plugins_by_name[instance_info.type] = None
|
plugins_by_name[instance_info.type] = None
|
||||||
|
|
||||||
for plugin_name, none in plugins_by_name.items():
|
for plugin_name, none in list(plugins_by_name.items()):
|
||||||
try:
|
try:
|
||||||
plugin = self._plugins_repository.create(plugin_name)
|
plugin = self._plugins_repository.create(plugin_name)
|
||||||
plugins_by_name[plugin_name] = plugin
|
plugins_by_name[plugin_name] = plugin
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ class commands:
|
||||||
def re_lookup_compile(self, d):
|
def re_lookup_compile(self, d):
|
||||||
if d is None:
|
if d is None:
|
||||||
return None
|
return None
|
||||||
return re.compile("(%s)" % ")|(".join(d.keys()))
|
return re.compile("(%s)" % ")|(".join(list(d.keys())))
|
||||||
|
|
||||||
# Do multiple regex replaces in 's' according to lookup table described by
|
# Do multiple regex replaces in 's' according to lookup table described by
|
||||||
# dictionary 'd', e.g.: d = {"re1": "replace1", "re2": "replace2", ...}
|
# dictionary 'd', e.g.: d = {"re1": "replace1", "re2": "replace2", ...}
|
||||||
|
|
@ -76,7 +76,7 @@ class commands:
|
||||||
return s
|
return s
|
||||||
if r is None:
|
if r is None:
|
||||||
r = self.re_lookup_compile(d)
|
r = self.re_lookup_compile(d)
|
||||||
return r.sub(lambda mo: d.values()[mo.lastindex - 1], s, flags)
|
return r.sub(lambda mo: list(d.values())[mo.lastindex - 1], s, flags)
|
||||||
|
|
||||||
# Do regex lookup on 's' according to lookup table described by
|
# Do regex lookup on 's' according to lookup table described by
|
||||||
# dictionary 'd' and return corresponding value from the dictionary,
|
# dictionary 'd' and return corresponding value from the dictionary,
|
||||||
|
|
@ -89,7 +89,7 @@ class commands:
|
||||||
r = self.re_lookup_compile(d)
|
r = self.re_lookup_compile(d)
|
||||||
mo = r.search(s)
|
mo = r.search(s)
|
||||||
if mo:
|
if mo:
|
||||||
return d.values()[mo.lastindex - 1]
|
return list(d.values())[mo.lastindex - 1]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def write_to_file(self, f, data, makedir = False, no_error = False):
|
def write_to_file(self, f, data, makedir = False, no_error = False):
|
||||||
|
|
@ -315,7 +315,7 @@ class commands:
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if len(vl) > 1:
|
if len(vl) > 1:
|
||||||
rl += range(int(vl[0]), int(vl[1]) + 1)
|
rl += list(range(int(vl[0]), int(vl[1]) + 1))
|
||||||
else:
|
else:
|
||||||
rl.append(int(vl[0]))
|
rl.append(int(vl[0]))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
@ -381,9 +381,9 @@ class commands:
|
||||||
if not os.path.isfile(fname):
|
if not os.path.isfile(fname):
|
||||||
return None
|
return None
|
||||||
config = ConfigObj(fname, list_values = False, interpolation = False)
|
config = ConfigObj(fname, list_values = False, interpolation = False)
|
||||||
for section in config.keys():
|
for section in list(config.keys()):
|
||||||
match = True
|
match = True
|
||||||
for option in config[section].keys():
|
for option in list(config[section].keys()):
|
||||||
value = config[section][option]
|
value = config[section][option]
|
||||||
if value == "":
|
if value == "":
|
||||||
value = r"^$"
|
value = r"^$"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue