Skip to content

Commit

Permalink
Added description of plugins mechanism in README
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Pinto <[email protected]>
  • Loading branch information
christian-pinto committed Sep 5, 2024
1 parent c4b61f8 commit 9cb5f4c
Showing 1 changed file with 74 additions and 15 deletions.
89 changes: 74 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,89 @@ To run the tests run the command
make test
```

## Plugins

## Usage
To use sunfishcorelib you need to specify the **configuration parameters** into the conf.json file, an example could be:
The Sunfish core library uses a plugin based mechanism for providing custom implementation of:

- Storage backends: implementation of the Sunfish storage interface used for controlling how RedFish storage are persisted. Plugins in this class must implement the `BackendInterface` class in `storage.backend_interface`.
- Event handlers: Sunfish interactions with hardware agents and clients is implemented through RedFish events. When an event is received, users might want to execute a specific action depending on the specific event. These are provided via this plugin. Plugins in this class must implement the `EventHandlerInterface` class in `events.event_handler_interface`.
- Objects handlers: Whenever a request for an object (get, create, replace, patch, delete) is received on the Sunfish external api the core library checks whether a special handler is to be executed for that specific object. Examples are an object is created and it requires other objects to be created in turn as a result. Plugins in this class must implement the `ObjectHandlerInterface` class in `lib.object_handler_interface`.
- Objects managers: Sunfish keeps all objects in the form of a RedFish tree. Objects belong to a manager (e.g., a Sunfish agent) and this plugin provides the methods for Sungish to interact with the manager. Plugins in this class must implement the `ObjectManagerInterface` class in `lib.object_manager_interface`.

Plugins are based on python's namespaced packages and are required to be placed in a specific folder at the top of your project. Only the actual plugins have a user defined name. Please see the below example.

```commandline
─ 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
├── objects_managers
│ └──my_objects_manager_package <--- User defined
│ ├── __init__.py
│ └── my_objects_manager.py
```

Please note no setup.py or project.toml should be placed in any of the plugins folders, including the pre-defined folders (i.e., sunfish_plugins, storage, events_handlers, objects_handlers, objects_managers). Failing to do so will make the plugins impossible to be discovered.


When initializing the library, users can specify their implementation of their plugins as part of the sunfish configuration. See the below example.

```python
sunfish_config = {

}
```

This plugin mechanism allows user to modify the standard behavior of Sunfish without having to modify the core library. Users can place the `sunifsh_plugins` folder at the top of their project that imports the sunfish core library and benefit from the flexibility of a plugin.

If no plugins are specified in the configuration, the Sunfish library will load the default implementations. See the code for more details.

## Usage

When initializing the sunfish core library, users need to specify the **configuration parameters** as a dict to be passed to the `init` function. The below snippet shows all the possible fields :
```json
{
"storage_backend": "FS",
"redfish_root": "/redfish/v1/",
"backend_conf" : {
"fs_root": "Resources",
"subscribers_root": "EventService/Subscriptions"
},
"handlers": {
"subscription_handler": "redfish",
"event_handler": "redfish"
"subscription_handler": "redfish"
},
"storage_backend": {
"module_name": "storage.file_system_backend.backend_FS",
"class_name": "BackendFS"
},
"events_handler": {
"module_name": "events_handlers.redfish.redfish_event_handler",
"class_name": "RedfishEventHandler"
},
"objects_handler": {
"module_name": "objects_handlers.sunfish_server.redfish_object_handler",
"class_name": "RedfishObjectHandler"
},
"objects_manager": {
"module_name": "objects_managers.sunfish_agent.sunfish_agent_manager",
"class_name": "SunfishAgentManager"
}
}
```

where:
- _storage_backend_ specifies the persistency implementation that you want to use
- _redfish_root_ specifies the Redfish version that must be included in all the requests
- _backend_conf[fs_root]_ specifies the root directory of Redfish objects' file system
- _subscription_handler_ specifies the type of handler implementation that you want to use to handle subscriptions
- _event_handler_ specifies the type of handler implementation that you want to use to handle events
Where:
- `redfish_root`: the root of the RedFish service served by the Sunfish core library.
- `subscripition_hadler`: Identifies how to handle subscriptions to events. At the moment only `redfish` is supported and follows the Redfish standard
- `storage_backend`: specifies the storage plugin to load.
- `events_handler`: specifies the event handling plugin to load.
- `objects_handler`: specifies the object handling plugin to load.
- `objects_manager`: specifies the object manager plugin to load.

All plugins must specify the module and class name via the `module_name` and `class_name` fields respectively.

Sunfish should be installed and imported in an existing Python project. To use it:
- instantiate an object Core(conf)
Expand Down

0 comments on commit 9cb5f4c

Please sign in to comment.