tuned-adm: added check if requested profile exists
This commit is contained in:
parent
fead260bc3
commit
ea412c9064
1 changed files with 10 additions and 5 deletions
15
tuned-adm.py
15
tuned-adm.py
|
|
@ -89,7 +89,7 @@ class Tuned_adm:
|
|||
except:
|
||||
pass
|
||||
|
||||
def show_profiles(self):
|
||||
def get_profiles(self):
|
||||
profiles = []
|
||||
try:
|
||||
profiles += listdir_joined("/usr/lib/tuned")
|
||||
|
|
@ -100,11 +100,13 @@ class Tuned_adm:
|
|||
except:
|
||||
pass
|
||||
|
||||
print "Available profiles:"
|
||||
for profile in profiles:
|
||||
if os.path.exists(os.path.join(profile, "tuned.conf")):
|
||||
print "-", os.path.basename(profile)
|
||||
return map(lambda p: os.path.basename(p), \
|
||||
filter(lambda p: os.path.exists(os.path.join(p, "tuned.conf")), profiles))
|
||||
|
||||
def show_profiles(self):
|
||||
print "Available profiles:"
|
||||
for p in self.get_profiles():
|
||||
print "- " + p
|
||||
self.show_active_profile()
|
||||
|
||||
def set_active_profile(self, profile):
|
||||
|
|
@ -115,6 +117,9 @@ class Tuned_adm:
|
|||
except (OSError,IOError) as e:
|
||||
self.error("Cannot read %s: %s" % (PIDFILE, str(e)))
|
||||
|
||||
if not profile in self.get_profiles():
|
||||
self.error("Profile %s does''t exist." % profile)
|
||||
|
||||
if pid:
|
||||
try:
|
||||
with open("/etc/tuned/active_profile", "w") as f:
|
||||
|
|
|
|||
Loading…
Reference in a new issue