Skip to content

Commit

Permalink
Merge pull request #19 from christian-pinto/agent-aggregation-source
Browse files Browse the repository at this point in the history
Agent aggregation source
  • Loading branch information
dledford committed Aug 11, 2023
2 parents 59f075f + f4c70bd commit c947a08
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 16 deletions.
14 changes: 14 additions & 0 deletions Resources/AggregationService/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"@odata.type": "#AggregationService.v1_0_1.AggregationService",
"Id": "AggregationService",
"Name": "Aggregation Service",
"Description": "Open Fabric Manager Aggregation Service",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"ServiceEnabled": true,

"@odata.id": "/redfish/v1/AggregationService",
"@Redfish.Copyright": "Copyright 2023 OpenFabrics Alliance. All rights reserved."
}
3 changes: 3 additions & 0 deletions Resources/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"Name": "Root Service",
"RedfishVersion": "1.14.0",
"UUID": "92384634-2938-2342-8820-489239905423",
"AggregationService": {
"@odata.id": "/redfish/v1/AggregationService"
},
"Chassis": {
"@odata.id": "/redfish/v1/Chassis"
},
Expand Down
2 changes: 1 addition & 1 deletion api_emulator/redfish/AggregationService_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get(self):
msg, code = check_authentication(self.auth)

if code == 200:
path = os.path.join(self.root, 'index.json')
path = os.path.join(self.root, 'AggregationService', 'index.json')
return get_json_data (path)
else:
return msg, code
Expand Down
59 changes: 45 additions & 14 deletions api_emulator/redfish/EventListener_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
from .constants import *
import requests
import json

import g
from api_emulator.utils import create_path, create_object

from api_emulator.redfish.Manager_api import ManagerCollectionAPI
from api_emulator.redfish.AggregationSource_api import AggregationSourceAPI
from api_emulator.redfish.templates import AggregationSource as AggregationSourceTemplate

import logging

Expand Down Expand Up @@ -59,21 +61,50 @@ def recursiveFetch(self, obj_dict, obj_root, host, port):
for element in value:
EventProcessor.recursiveFetch(self, element, obj_root, host, port)

def ManagerCreated(self):
def ManagerCreated(self, event):
logging.info("ManagerCreated method called")
config = json.loads(request.data)
for event in config['Events']:
host = event['MessageArgs'][0]
port = event['MessageArgs'][1]
response = requests.get(f"{host}:{port}/{event['OriginOfCondition']['@odata.id']}")
if response.status_code == 200:
redfish_obj = response.json()
host = event['MessageArgs'][0]
port = event['MessageArgs'][1]
response = requests.get(f"{host}:{port}/{event['OriginOfCondition']['@odata.id']}")
if response.status_code == 200:
redfish_obj = response.json()

request.data = json.dumps(redfish_obj, indent=2).encode('utf-8')
# Update ManagerCollection before fetching the resource subtree
ManagerCollectionAPI.post(self)
EventProcessor.recursiveFetch(self, redfish_obj, redfish_obj['@odata.id'], host, port)
request.data = json.dumps(redfish_obj, indent=2).encode('utf-8')
# Update ManagerCollection before fetching the resource subtree
ManagerCollectionAPI.post(self)
EventProcessor.recursiveFetch(self, redfish_obj, redfish_obj['@odata.id'], host, port)

def AggregationSourceDiscovered(self, event):
###
# Fabric Agents are modelled as AggregationSource objects (RedFish v2023.1 at the time of writing this comment)
# Registration will happen with the OFMF receiving a and event with MessageId: AggregationSourceDiscovered
# The arguments of the event message are:
# - Arg1: "Redfish"
# - Arg2: "agent_ip:port"
# I am also assuming that the agent name to be used is contained in the OriginOfCondifiton field of the event as in the below example:
# {
# "OriginOfCondition: [
# "@odata.id" : "/redfish/v1/AggregationService/AggregationSource/AgentName"
# ]"
# }
logging.info("AggregationSourceDiscovered method called")
aggregationSourceId = event['OriginOfCondition']['@odata.id'].split("/")[-1]
wildcards = {
"AggregationSourceId": aggregationSourceId,
"rb": g.rest_base
}
aggregation_source_template = AggregationSourceTemplate.get_AggregationSource_instance(wildcards)
aggregation_source_template["HostName"] = f"{event['MessageArgs'][0]}:{event['MessageArgs'][1]}"
aggregation_source_template["Name"] = f"Agent {aggregationSourceId}"
aggregation_source_template["Links"] = {
"ConnectionMethod" : {},
"ResourcesAccessed" : []
}
logging.debug(f"aggregatoin_source_template: {aggregation_source_template}")

# At this stage we are not taking care of authenticating with an agent
request.data = json.dumps(aggregation_source_template)
AggregationSourceAPI.post(self, aggregationSourceId)

def handle_events(res):
config = json.loads(request.data)
Expand All @@ -88,7 +119,7 @@ def handle_events(res):
# }
###
handlerfunc = getattr(EventProcessor, event['MessageId'].split(".")[-1])
handlerfunc(res)
handlerfunc(res, event)


# EventListener API
Expand Down
34 changes: 33 additions & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
BASE_DIR=$(pwd)
WORK_DIR=../OFMF

API_PORT=5000
API_PORT=5001
SETUP_ONLY=
RESET_RESOURCES=

COMMON_NAME="$1"
EXTFILE=certificate_config.cnf
Expand All @@ -55,6 +56,9 @@ Options:
-n | --no-start -- Prepare the emulator but do not start it.
-u | --update -- Update working dir with modified files
-r | --reset -- Reset the Resources folder (RedFish tree)
EOF
}

Expand All @@ -72,6 +76,12 @@ while [ "$1" != "" ]; do
-n | --no-start)
SETUP_ONLY="true"
;;
-u | --update)
UPDATE_ONLY="true"
;;
-r | --reset)
RESET_RESOURCES="true"
;;
*)
print_help
exit 1
Expand Down Expand Up @@ -107,6 +117,28 @@ if ! [ -x "$(command -v git)" ]; then
exit 1
fi

if [ "$RESET_RESOURCES" == "true" ]; then
echo ""
echo "Wiping resources folder with original files"
echo ""

rm -r $WORK_DIR/Resources
cp -r Resources $WORK_DIR/
fi

if [ "$UPDATE_ONLY" == "true" ]; then
echo ""
echo "Updating installed emulator with modified files"
echo ""

for f in `git ls-files -m`; do
echo "Updating: $f"
cp -f $f $WORK_DIR/$f
done

exit 0
fi

echo "Creating workspace: '$WORK_DIR'..."
rm -fr $WORK_DIR
mkdir $WORK_DIR
Expand Down

0 comments on commit c947a08

Please sign in to comment.