-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved objects and events custom handler dispatching
Signed-off-by: Christian Pinto <christian.pinto@ibm.com>
- Loading branch information
1 parent
963736e
commit aee63d8
Showing
2 changed files
with
136 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,39 @@ | ||
# Copyright IBM Corp. 2023 | ||
# This software is available to you under a BSD 3-Clause License. | ||
# The full license terms are available here: https://github.com/OpenFabrics/sunfish_library_reference/blob/main/LICENSE | ||
import logging | ||
|
||
import sunfish.lib.core | ||
from sunfish.models.types import * | ||
|
||
logger = logging.getLogger("RedfishObjectHandler") | ||
|
||
|
||
class RedfishObjectHandlersTable: | ||
@classmethod | ||
def ComputerSystem(cls, core: 'sunfish.lib.core.Core', path: str, operation: SunfishRequestType, payload: dict): | ||
return "ObjectHandler ComputerSystem" | ||
|
||
@classmethod | ||
def EventDestination(cls, core: 'sunfish.lib.core.Core', path: str, operation: SunfishRequestType, payload: dict): | ||
if operation == SunfishRequestType.CREATE: | ||
core.subscription_handler.new_subscription(payload) | ||
elif operation == SunfishRequestType.REPLACE or operation == SunfishRequestType.PATCH: | ||
core.subscription_handler.delete_subscription(payload) | ||
core.subscription_handler.new_subscription(payload) | ||
elif operation == SunfishRequestType.DELETE: | ||
core.subscription_handler.delete_subscription(path) | ||
|
||
|
||
class RedfishObjectHandler: | ||
dispatch_table = { | ||
"ComputerSystem": RedfishObjectHandlersTable.ComputerSystem, | ||
"EventDestination": RedfishObjectHandlersTable.EventDestination | ||
} | ||
@classmethod | ||
def dispatch(cls, core: 'sunfish.lib.core.Core', object_type: str, path: str, | ||
operation: SunfishRequestType, payload: dict = None): | ||
if object_type in cls.dispatch_table: | ||
return cls.dispatch_table[object_type](core, path, operation, payload) | ||
logger.debug(f"Object type '{object_type}' does not have a custom handler") | ||
|
||
class ObjectHandler: | ||
def __init__(self, core): | ||
"""init that sets the conf and calls the load subcriptions method | ||
Args: | ||
conf (dict): dictionary where are specified the storage implementation type and the specific backend configuration. | ||
""" | ||
self.core = core | ||
|
||
def ComputerSystem(self, payload): | ||
return "ObjectHandler ComputerSystem" |