Skip to content

Commit

Permalink
Marking all resources pull from agents with the Sunfish ResourceManag…
Browse files Browse the repository at this point in the history
…ement OEM extension
  • Loading branch information
christian-pinto committed Nov 1, 2023
1 parent 97974c9 commit 1c0b1ab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
18 changes: 6 additions & 12 deletions api_emulator/redfish/EventListener_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,10 @@ def getAggregationSource():
if resource in agsource['Links']['ResourcesAccessed']:
return agsource

def createResource(redfish_obj):
def createResource(redfish_obj, aggregation_source):
obj_path = getRelativePath(redfish_obj)
file_path = create_path(constants.PATHS['Root'], obj_path)
create_object(redfish_obj, [], [], file_path)






create_object(redfish_obj, [], [], file_path, aggregation_source["@odata.id"])

class EventProcessor(Resource):
def __init__(self):
Expand Down Expand Up @@ -102,11 +96,11 @@ def handleNestedObject(obj):
handleNestedObject(val)
return visited

def createInspectedObject(self,redfish_obj):
def createInspectedObject(self,redfish_obj, aggregation_source):

obj_path = getRelativePath(redfish_obj)
file_path = create_path(constants.PATHS['Root'], obj_path)
create_object(redfish_obj, [], [], file_path)
create_object(redfish_obj, [], [], file_path, aggregation_source["@odata.id"])

if ("Fabric" in redfish_obj['@odata.type']
or "System" in redfish_obj['@odata.type']
Expand All @@ -130,7 +124,7 @@ def fetchResource(self,obj_id, aggregation_source):
if response.status_code == 200:
redfish_obj = response.json()

EventProcessor.createInspectedObject(self,redfish_obj)
EventProcessor.createInspectedObject(self,redfish_obj, aggregation_source)
if redfish_obj['@odata.id'] not in aggregation_source["Links"]["ResourcesAccessed"]:
aggregation_source["Links"]["ResourcesAccessed"].append(redfish_obj['@odata.id'])
return redfish_obj
Expand Down Expand Up @@ -176,7 +170,7 @@ def ResourceCreated(self, event):

request.data = json.dumps(redfish_obj, indent=2).encode('utf-8')
# Update ManagerCollection before fetching the resource subtree
createResource(redfish_obj)
createResource(redfish_obj, aggregation_source)
EventProcessor.bfsInspection(self,redfish_obj,aggregation_source)

request.data = json.dumps(aggregation_source)
Expand Down
15 changes: 14 additions & 1 deletion api_emulator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,22 @@ def get_json_data(path):
# return jsonify(data)
return data

def create_object (config, members, member_ids, path):
def create_object (config, members, member_ids, path, agent = None):
# For POST Singleton API:

if agent is not None:
# This means this object is being created in response to a new object being advertised by an agent
# We mark the boject as belonging to an agent through the oem field.
oem = {
"@odata.type": "#SunfishExtensions.v1_0_0.ResourceExtensions",
"ManagingAgent": {
"@odata.id": agent
}
}
if "oem" not in config:
config["oem"] = {}
config["oem"]["Sunfish_RM"] = oem

members.append(config)
member_ids.append({'@odata.id': config['@odata.id']})

Expand Down

0 comments on commit 1c0b1ab

Please sign in to comment.