units: move configuration parsing from manager to unit
This commit is contained in:
parent
223af44d3d
commit
92ccd91f29
2 changed files with 18 additions and 18 deletions
|
|
@ -22,9 +22,8 @@ class UnitManager(tuned.patterns.Singleton):
|
|||
|
||||
def create(self, name, plugin_name, config):
|
||||
log.info("creating unit %s" % name)
|
||||
(device, options) = self._get_plugin_params(config)
|
||||
try:
|
||||
new_unit = tuned.units.unit.Unit(name, plugin_name, [], options)
|
||||
new_unit = tuned.units.unit.Unit(name, plugin_name, config)
|
||||
self._units.add(new_unit)
|
||||
return new_unit
|
||||
except tuned.exceptions.TunedException as e:
|
||||
|
|
@ -40,16 +39,3 @@ class UnitManager(tuned.patterns.Singleton):
|
|||
for unit in self._units:
|
||||
unit.clean()
|
||||
self._units.clear()
|
||||
|
||||
def _get_plugin_params(self, config):
|
||||
if config is None:
|
||||
return (None, {})
|
||||
|
||||
assert type(config) is dict
|
||||
if "devices" in config:
|
||||
devices = config[devices].strip().split()
|
||||
if len(devices) == 0:
|
||||
devices = None
|
||||
del(config["devices"])
|
||||
|
||||
return (devices, config)
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ class Unit(object):
|
|||
|
||||
__slots__ = ["_name", "_plugin"]
|
||||
|
||||
def __init__(self, name, plugin_name, devices = None, options = None):
|
||||
def __init__(self, name, plugin_name, config):
|
||||
assert type(name) is str
|
||||
assert type(plugin_name) is str
|
||||
assert devices is None or type(devices) is list
|
||||
assert options is None or type(options) is dict
|
||||
assert config is None or type(config) is dict
|
||||
|
||||
(devices, options) = self._get_plugin_params(config)
|
||||
|
||||
self._name = name
|
||||
self._plugin = tuned.plugins.get_repository().create(plugin_name, devices, options)
|
||||
|
|
@ -31,3 +32,16 @@ class Unit(object):
|
|||
def clean(self):
|
||||
tuned.plugins.get_repository().delete(self._plugin)
|
||||
self._plugin = None
|
||||
|
||||
def _get_plugin_params(self, config):
|
||||
if config is None:
|
||||
return (None, {})
|
||||
|
||||
assert type(config) is dict
|
||||
if "devices" in config:
|
||||
devices = config[devices].strip().split()
|
||||
if len(devices) == 0:
|
||||
devices = None
|
||||
del(config["devices"])
|
||||
|
||||
return (devices, config)
|
||||
|
|
|
|||
Loading…
Reference in a new issue