Skip to content

Commit 8ff054d

Browse files
committed
Updated to include latest schema support and event service. Resource events will be generated for most resources.
1 parent ce8b887 commit 8ff054d

File tree

8,963 files changed

+4187772
-9459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

8,963 files changed

+4187772
-9459
lines changed

api_emulator/redfish/AccelerationFunction0_api.py

Lines changed: 131 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get(self, ComputerSystemId, ProcessorId):
5858
msg, code = check_authentication(self.auth)
5959

6060
if code == 200:
61-
path = os.path.join(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions', 'index.json').format(ComputerSystemId, ProcessorId)
61+
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions', 'index.json').format(ComputerSystemId, ProcessorId)
6262
return get_json_data(path)
6363
else:
6464
return msg, code
@@ -79,6 +79,7 @@ def post(self, ComputerSystemId, ProcessorId):
7979
resp = 404
8080
return resp
8181
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions').format(ComputerSystemId, ProcessorId)
82+
redfish_path = create_path('/redfish/v1/', 'Systems/{0}/Processors/{1}/AccelerationFunctions').format(ComputerSystemId, ProcessorId)
8283
parent_path = os.path.dirname(path)
8384
if not os.path.exists(path):
8485
os.mkdir(path)
@@ -121,7 +122,8 @@ def post(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
121122

122123
if code == 200:
123124
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
124-
collection_path = os.path.join(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions', 'index.json').format(ComputerSystemId, ProcessorId)
125+
redfish_path = create_path('/redfish/v1/', 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
126+
collection_path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions', 'index.json').format(ComputerSystemId, ProcessorId)
125127
if not os.path.exists(collection_path):
126128
AccelerationFunction0CollectionAPI.post(self, ComputerSystemId, ProcessorId)
127129
if AccelerationFunctionId in members:
@@ -151,62 +153,152 @@ def post(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
151153

152154
# HTTP PUT
153155
def put(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
156+
# Read old version and compare with new data for event logic
157+
old_version = None
158+
try:
159+
with open(path, 'r') as data_json:
160+
old_version = json.load(data_json)
161+
except Exception:
162+
old_version = {}
163+
health_changed_to = None
164+
state_changed = False
165+
new_state = None
166+
if request.data:
167+
request_data = json.loads(request.data)
168+
old_health = old_version.get('State', {}).get('Health')
169+
new_health = request_data.get('State', {}).get('Health', old_health)
170+
if old_health != new_health:
171+
health_changed_to = new_health
172+
old_status = old_version.get('State', {}).get('Status')
173+
new_status = request_data.get('State', {}).get('Status', old_status)
174+
if old_status != new_status:
175+
state_changed = True
176+
new_state = new_status
177+
send_event(
178+
"ResourceChanged",
179+
"ResourceEvent.1.4.2ResourceChanged",
180+
"One or more resource properties have changed.",
181+
"OK",
182+
redfish_path
183+
)
184+
if health_changed_to == "OK":
185+
send_event(
186+
"ResourceStatusChangedOK",
187+
"ResourceEvent.1.4.2.ResourceStatusChangedOK",
188+
f"The health of resource '{redfish_path}' has changed to OK.",
189+
"OK",
190+
redfish_path
191+
)
192+
if health_changed_to == "Critical":
193+
send_event(
194+
"ResourceStatusChangedCritical",
195+
"ResourceEvent.1.4.2.ResourceStatusChangedCritical",
196+
f"The health of resource '{redfish_path}' has changed to Critical.",
197+
"Critical",
198+
redfish_path
199+
)
200+
if health_changed_to == "Warning":
201+
send_event(
202+
"ResourceStatusChangedWarning",
203+
"ResourceEvent.1.4.2.ResourceStatusChangedCritical",
204+
f"The health of resource '{redfish_path}' has changed to Warning.",
205+
"Warning",
206+
redfish_path
207+
)
208+
if state_changed:
209+
send_event(
210+
"ResourceStateChanged",
211+
"ResourceEvent.1.4.2.ResourceStateChanged",
212+
f"The state of resource '{redfish_path}' has changed to {new_state}.",
213+
"OK",
214+
redfish_path
215+
)
154216
logging.info('AccelerationFunction0 put called')
155217
msg, code = check_authentication(self.auth)
156218

157219
if code == 200:
158-
path = os.path.join(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
220+
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
221+
redfish_path = create_path('/redfish/v1/', 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
159222
old_data = get_json_data(path)
160223
put_object(path)
161224
new_data = get_json_data(path)
162-
send_event(
163-
"ResourceChanged",
164-
"ResourceChanged",
165-
f"AccelerationFunction {AccelerationFunctionId} changed",
166-
"OK",
167-
path,
168-
new_data
169-
)
170225
if old_data.get('Status') != new_data.get('Status'):
171-
send_event(
172-
"ResourceStatusChanged",
173-
"ResourceStatusChanged",
174-
f"AccelerationFunction {AccelerationFunctionId} status changed",
175-
"OK",
176-
path,
177-
new_data
178-
)
179226
return self.get(ComputerSystemId, ProcessorId, AccelerationFunctionId)
180227
else:
181228
return msg, code
182229

183230
# HTTP PATCH
184231
def patch(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
232+
# Read old version and compare with new data for event logic
233+
old_version = None
234+
try:
235+
with open(path, 'r') as data_json:
236+
old_version = json.load(data_json)
237+
except Exception:
238+
old_version = {}
239+
health_changed_to = None
240+
state_changed = False
241+
new_state = None
242+
if request.data:
243+
request_data = json.loads(request.data)
244+
old_health = old_version.get('State', {}).get('Health')
245+
new_health = request_data.get('State', {}).get('Health', old_health)
246+
if old_health != new_health:
247+
health_changed_to = new_health
248+
old_status = old_version.get('State', {}).get('Status')
249+
new_status = request_data.get('State', {}).get('Status', old_status)
250+
if old_status != new_status:
251+
state_changed = True
252+
new_state = new_status
253+
send_event(
254+
"ResourceChanged",
255+
"ResourceEvent.1.4.2ResourceChanged",
256+
"One or more resource properties have changed.",
257+
"OK",
258+
redfish_path
259+
)
260+
if health_changed_to == "OK":
261+
send_event(
262+
"ResourceStatusChangedOK",
263+
"ResourceEvent.1.4.2.ResourceStatusChangedOK",
264+
f"The health of resource '{redfish_path}' has changed to OK.",
265+
"OK",
266+
redfish_path
267+
)
268+
if health_changed_to == "Critical":
269+
send_event(
270+
"ResourceStatusChangedCritical",
271+
"ResourceEvent.1.4.2.ResourceStatusChangedCritical",
272+
f"The health of resource '{redfish_path}' has changed to Critical.",
273+
"Critical",
274+
redfish_path
275+
)
276+
if health_changed_to == "Warning":
277+
send_event(
278+
"ResourceStatusChangedWarning",
279+
"ResourceEvent.1.4.2.ResourceStatusChangedCritical",
280+
f"The health of resource '{redfish_path}' has changed to Warning.",
281+
"Warning",
282+
redfish_path
283+
)
284+
if state_changed:
285+
send_event(
286+
"ResourceStateChanged",
287+
"ResourceEvent.1.4.2.ResourceStateChanged",
288+
f"The state of resource '{redfish_path}' has changed to {new_state}.",
289+
"OK",
290+
redfish_path
291+
)
185292
logging.info('AccelerationFunction0 patch called')
186293
msg, code = check_authentication(self.auth)
187294

188295
if code == 200:
189-
path = os.path.join(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
296+
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
297+
redfish_path = create_path('/redfish/v1/', 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}', 'index.json').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
190298
old_data = get_json_data(path)
191299
patch_object(path)
192300
new_data = get_json_data(path)
193-
send_event(
194-
"ResourceChanged",
195-
"ResourceChanged",
196-
f"AccelerationFunction {AccelerationFunctionId} changed",
197-
"OK",
198-
path,
199-
new_data
200-
)
201301
if old_data.get('Status') != new_data.get('Status'):
202-
send_event(
203-
"ResourceStatusChanged",
204-
"ResourceStatusChanged",
205-
f"AccelerationFunction {AccelerationFunctionId} status changed",
206-
"OK",
207-
path,
208-
new_data
209-
)
210302
return self.get(ComputerSystemId, ProcessorId, AccelerationFunctionId)
211303
else:
212304
return msg, code
@@ -218,15 +310,15 @@ def delete(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
218310

219311
if code == 200:
220312
path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
313+
redfish_path = create_path('/redfish/v1/', 'Systems/{0}/Processors/{1}/AccelerationFunctions/{2}').format(ComputerSystemId, ProcessorId, AccelerationFunctionId)
221314
base_path = create_path(self.root, 'Systems/{0}/Processors/{1}/AccelerationFunctions').format(ComputerSystemId, ProcessorId)
222315
obj = get_json_data(path)
223316
send_event(
224317
"ResourceRemoved",
225-
"ResourceRemoved",
318+
"ResourceEvent.1.4.2.ResourceRemoved",
226319
"The resource was removed successfully.",
227320
"OK",
228-
path,
229-
obj
321+
redfish_path
230322
)
231323
delete_object(path, base_path)
232324
return '', 204

0 commit comments

Comments
 (0)