OpenFabrics / sunfish_library_reference

The core Sunfish implementation
BSD 3-Clause "New" or "Revised" License
2 stars 4 forks source link

Added support for dynamically loadable plugins #29

Open christian-pinto opened 1 week ago

christian-pinto commented 1 week ago

This pull request adds support for dynamically loaded plugins

The Sunfish core library uses a plugin mechanism that allows dynamic loading of certain classes. This helps users with updating the behavior of the sunfish library without having to modify its core classes. At the moment we support plugins for the storage backend, for the redfish event handlers and for the main redifsh objects handlers. Plugins are implemented as namespaced packages and must be placed in a folder at the top of the project named "sunfish_plugins", with subfolders named "storage" and/or "events_handlers" and/or "objects_handlers". The python packages defined inside each subfolder are totally user defined.

 ── sunfish_plugins
         ├── storage
         │    └──my_storage_package     <--- User defined
         │        ├── __init__.py
         │        └── my_storage_backend.py
         └── events_handlers
         │     └──my_handler_package     <--- User defined
         │         ├── __init__.py
         │         └── my_handler.py
         └── objects_handlers
              └──my_objects_handler_package     <--- User defined
                  ├── __init__.py
                  └── my_objects_handler.py

When initializing the Sunfish libraries can load their storage or event handler plugin by specifying them in the configuration as in the below example:

"storage_backend" : {
    "module_name": "storage.my_storage_package.my_storage_backend",
    "class_name": "StorageBackend"
},
"events_handler" : {
    "module_name": "events_handlers.my_handler_package.my_handler",
    "class_name": "EventHandler"
},
"objects_handler" : {
    "module_name": "objects_handlers.my_objects_handler_package.my_objects_handler",
    "class_name": "ObjectsHandler"
},

In all cases "class_name" represents the name of the class that is initialized and implements the respective interface.

The object _handler interface is not only defining which handler to execute for each specific RedFish object but also the actions to execute when forwarding the current request to the object manager (i.e., the agent). The ObjectHandlerInterface class includes a method called forward_to_manager that is used exactly for this purpose.

christian-pinto commented 1 day ago

@cayton @mjaguil @mgazz could any of you review this PR?