Skip to content

Removed circular call where the core library calls itself instead of the plugins #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading