Skip to content

Commit

Permalink
add dbus commands for dynamic creation of instances
Browse files Browse the repository at this point in the history
Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
  • Loading branch information
adriaan42 committed Feb 7, 2024
1 parent dee5d6f commit aad02c7
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
20 changes: 20 additions & 0 deletions com.redhat.tuned.policy
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,24 @@
</defaults>
</action>

<action id="com.redhat.tuned.instance_create">
<description>Create new plugin instance</description>
<message>Authentication is required to create a new plugin instance</message>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>

<action id="com.redhat.tuned.instance_destroy">
<description>Delete a dynamically created plugin instance</description>
<message>Authentication is required to destroy the instance</message>
<defaults>
<allow_any>yes</allow_any>
<allow_inactive>yes</allow_inactive>
<allow_active>yes</allow_active>
</defaults>
</action>

</policyconfig>
58 changes: 58 additions & 0 deletions tuned/daemon/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,61 @@ def instance_get_devices(self, instance_name, caller = None):
rets = "Instance '%s' not found" % instance_name
log.error(rets)
return (False, rets, [])

@exports.export("ssa{ss}", "(bs)")
def instance_create(self, plugin_name, instance_name, options, caller = None):
"""Dynamically create a plugin instance
Parameters:
plugin_name -- name of the plugin
instance_name -- name of the new instance
dict of string-string -- options for the new instance
Return:
bool -- True on success
string -- error message or "OK"
"""
plugins = {p.name: p for p in self._daemon._unit_manager.plugins}
if not plugin_name in plugins.keys():
rets = "Plugin '%s' not found" % plugin_name
log.error(rets)
return (False, rets)
plugin = plugins[plugin_name]
instance = plugin.create_instance(instance_name, None, None, None, None, options)
plugin.initialize_instance(instance)
self._daemon._unit_manager.instances.append(instance)
log.info("Created dynamic instance '%s' of plugin '%s'" % (instance_name, plugin_name))
return (True, "OK")

@exports.export("s", "(bs)")
def instance_destroy(self, instance_name, caller = None):
"""Destroy a dynamically created plugin instance
Parameters:
instance_name -- name of the new instance
Return:
bool -- True on success
string -- error message or "OK"
"""
try:
instance = [i for i in self._daemon._unit_manager.instances if i.name == instance_name][0]
except IndexError:
rets = "Instance '%s' not found" % instance_name
log.error(rets)
return (False, rets)
if len(instance.processed_devices) > 0:
rets = "Cannot delete instance '%s' because it still has attached devices" % instance_name
log.error(rets)
return (False, rets)
try:
self._daemon._unit_manager.instances.remove(instance)
plugin = instance.plugin
plugin.instance_unapply_tuning(instance)
plugin.destroy_instance(instance)
except Exception as e:
rets = "Error deleting instance '%s': %s" % (instance_name, str(e))
log.error(rets)
return (False, rets)
log.info("Deleted instance '%s'" % instance_name)
return (True, "OK")

0 comments on commit aad02c7

Please sign in to comment.