@@ -58,7 +58,7 @@ def get(self, ComputerSystemId, ProcessorId):
58
58
msg , code = check_authentication (self .auth )
59
59
60
60
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 )
62
62
return get_json_data (path )
63
63
else :
64
64
return msg , code
@@ -79,6 +79,7 @@ def post(self, ComputerSystemId, ProcessorId):
79
79
resp = 404
80
80
return resp
81
81
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 )
82
83
parent_path = os .path .dirname (path )
83
84
if not os .path .exists (path ):
84
85
os .mkdir (path )
@@ -121,7 +122,8 @@ def post(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
121
122
122
123
if code == 200 :
123
124
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 )
125
127
if not os .path .exists (collection_path ):
126
128
AccelerationFunction0CollectionAPI .post (self , ComputerSystemId , ProcessorId )
127
129
if AccelerationFunctionId in members :
@@ -151,62 +153,152 @@ def post(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
151
153
152
154
# HTTP PUT
153
155
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
+ )
154
216
logging .info ('AccelerationFunction0 put called' )
155
217
msg , code = check_authentication (self .auth )
156
218
157
219
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 )
159
222
old_data = get_json_data (path )
160
223
put_object (path )
161
224
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
- )
170
225
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
- )
179
226
return self .get (ComputerSystemId , ProcessorId , AccelerationFunctionId )
180
227
else :
181
228
return msg , code
182
229
183
230
# HTTP PATCH
184
231
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
+ )
185
292
logging .info ('AccelerationFunction0 patch called' )
186
293
msg , code = check_authentication (self .auth )
187
294
188
295
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 )
190
298
old_data = get_json_data (path )
191
299
patch_object (path )
192
300
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
- )
201
301
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
- )
210
302
return self .get (ComputerSystemId , ProcessorId , AccelerationFunctionId )
211
303
else :
212
304
return msg , code
@@ -218,15 +310,15 @@ def delete(self, ComputerSystemId, ProcessorId, AccelerationFunctionId):
218
310
219
311
if code == 200 :
220
312
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 )
221
314
base_path = create_path (self .root , 'Systems/{0}/Processors/{1}/AccelerationFunctions' ).format (ComputerSystemId , ProcessorId )
222
315
obj = get_json_data (path )
223
316
send_event (
224
317
"ResourceRemoved" ,
225
- "ResourceRemoved" ,
318
+ "ResourceEvent.1.4.2. ResourceRemoved" ,
226
319
"The resource was removed successfully." ,
227
320
"OK" ,
228
- path ,
229
- obj
321
+ redfish_path
230
322
)
231
323
delete_object (path , base_path )
232
324
return '' , 204
0 commit comments