Skip to content

Commit

Permalink
Removed circular call where the core library calls itself instead of …
Browse files Browse the repository at this point in the history
…the plugins (#32)
  • Loading branch information
christian-pinto authored Aug 12, 2024
2 parents c4b61f8 + b1569ed commit 8b81489
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions sunfish_plugins/events_handlers/redfish/redfish_event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import os
import uuid
import warnings

import requests
Expand Down Expand Up @@ -40,29 +41,28 @@ def AggregationSourceDiscovered(cls, event_handler: EventHandlerInterface, event
response = response.json()

### Save agent registration
connection_method_name = connectionMethodId.split('/')[-1]
connection_method_name = connectionMethodId[:-len(connection_method_name)]
event_handler.core.create_object(connection_method_name, response)
# connection_method_name = connectionMethodId.split('/')[-1]
# connection_method_name = connectionMethodId[:-len(connection_method_name)]
event_handler.core.storage_backend.write(response)

connection_method_template = {
aggregation_source_id = str(uuid.uuid4())
aggregation_source_template = {
"@odata.type": "#AggregationSource.v1_2_.AggregationSource",
"@odata.id": f"{event_handler.core.conf['redfish_root']}/AggregationService/AggregationSources/{aggregation_source_id}",
"HostName": hostname,
"Id": aggregation_source_id,
"Links": {
"ConnectionMethod": {
"@odata.id": connectionMethodId
},
"ResourcesAccessed": []
}
}

try:
resp_post = event_handler.core.create_object(
os.path.join(event_handler.core.conf["redfish_root"], "AggregationService/AggregationSources"),
connection_method_template)
event_handler.core.storage_backend.write(aggregation_source_template)
except Exception:
raise Exception()

aggregation_source_id = resp_post['@odata.id']
agent_subscription_context = {"Context": aggregation_source_id.split('/')[-1]}

resp_patch = requests.patch(f"{hostname}/redfish/v1/EventService/Subscriptions/SunfishServer",
Expand Down Expand Up @@ -91,7 +91,13 @@ def ResourceCreated(cls, event_handler: EventHandlerInterface, event: dict, cont

add_aggregation_source_reference(response, aggregation_source)

event_handler.core.create_object(id, response)
# here we are assuming that we are getting a fully populated redfish
# object from the agent.
if "@odata.id" not in response:
logger.warning(f"Resource {id} did not have @odata.id set when retrieved from Agent. Initializing its value with {id}")
response["odata.id"] = id

event_handler.core.storage_backend.write(response)

RedfishEventHandler.bfsInspection(event_handler.core, response, aggregation_source)

Expand All @@ -114,7 +120,6 @@ def __init__(self, core):
self.redfish_root = core.conf["redfish_root"]
self.fs_root = core.conf["backend_conf"]["fs_root"]
self.subscribers_root = core.conf["backend_conf"]["subscribers_root"]
self.backend = core.storage_backend
@classmethod
def dispatch(cls, message_id: str, event_handler: EventHandlerInterface, event: dict, context: str):
if message_id in cls.dispatch_table:
Expand Down Expand Up @@ -177,7 +182,7 @@ def check_data_type(self, origin):
resource = origin[length:]
path = os.path.join(self.redfish_root, resource)
try:
data = self.core.get_object(path)
data = self.core.storage_backend.read(path)
except ResourceNotFound as e:
raise ResourceNotFound(path)
type = data["@odata.type"].split('.')[0]
Expand All @@ -201,7 +206,7 @@ def forward_event(self, list, payload):
for id in list:
path = os.path.join(self.redfish_root, 'EventService', 'Subscriptions', id)
try:
data = self.core.get_object(path)
data = self.core.storage_backend.read(path)
# print('send to: ', data["Id"])
resp = requests.post(data['Destination'], json=payload)
resp.raise_for_status()
Expand Down

0 comments on commit 8b81489

Please sign in to comment.