Added storage class for persistent data storage
This commit is contained in:
parent
e43ee5f96b
commit
733b5eb753
2 changed files with 63 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import tuned.plugins
|
||||
import tuned.logs
|
||||
import tuned.monitors
|
||||
import tuned.utils.storage
|
||||
import os
|
||||
import struct
|
||||
import glob
|
||||
|
|
@ -53,6 +54,11 @@ class SysctlPlugin(tuned.plugins.Plugin):
|
|||
self._sysctl_original[k] = v
|
||||
|
||||
self._exec_sysctl(key + "=" + value, True)
|
||||
|
||||
storage = tuned.utils.storage.Storage.get_instance()
|
||||
storage.data = {"sysctl" : self._sysctl_original}
|
||||
storage.save()
|
||||
|
||||
return True
|
||||
|
||||
def _revert_sysctl(self):
|
||||
|
|
|
|||
57
tuned/utils/storage.py
Normal file
57
tuned/utils/storage.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
# Copyright (C) 2008-2012 Red Hat, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import tuned.patterns
|
||||
import tuned.logs
|
||||
import tuned.utils
|
||||
import pickle
|
||||
|
||||
log = tuned.logs.get()
|
||||
|
||||
DEFAULT_STORAGE_FILE = "./save.pickle"
|
||||
|
||||
class Storage(tuned.patterns.Singleton):
|
||||
def __init__(self):
|
||||
super(self.__class__, self).__init__()
|
||||
self._data = {}
|
||||
self.load()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
|
||||
@data.setter
|
||||
def data(self, data):
|
||||
self._data.update(data)
|
||||
|
||||
def save(self):
|
||||
try:
|
||||
with open(DEFAULT_STORAGE_FILE, "w") as f:
|
||||
pickle.dump(self._data, f)
|
||||
except (OSError,IOError) as e:
|
||||
log.error("Error saving storage file %s: %s" % (DEFAULT_STORAGE_FILE, e))
|
||||
|
||||
def load(self):
|
||||
try:
|
||||
with open(DEFAULT_STORAGE_FILE, "r") as f:
|
||||
self._data = pickle.load(f)
|
||||
except (OSError,IOError) as e:
|
||||
log.error("Error loading storage file %s: %s" % (DEFAULT_STORAGE_FILE, e))
|
||||
self._data = {}
|
||||
except EOFError:
|
||||
self._data = {}
|
||||
|
||||
Loading…
Reference in a new issue