11# BSD 3-Clause License
22#
3- # Copyright 2022 Hewlett Packard Enterprise Development LP
3+ # Copyright 2022-2023 Hewlett Packard Enterprise Development LP
44#
55# Redistribution and use in source and binary forms, with or without
66# modification, are permitted provided that the following conditions are met:
@@ -259,7 +259,7 @@ def __init__(self, **kwargs):
259259
260260 # HTTP GET
261261 def get (self , ident ):
262- logging .info ('SubscriptionAPI GET called' )
262+ logging .info (f 'SubscriptionAPI GET called: { ident } ' )
263263 try :
264264 resp = error_404_response (request .path )
265265 if ident in members :
@@ -271,7 +271,7 @@ def get(self, ident):
271271
272272 # HTTP PUT
273273 def put (self , ident ):
274- logging .info ('SubscriptionAPI PUT called' )
274+ logging .info (f 'SubscriptionAPI PUT called: { ident } ' )
275275 try :
276276 resp = error_404_response (request .path )
277277 if ident in members :
@@ -283,7 +283,7 @@ def put(self, ident):
283283
284284 # HTTP POST
285285 def post (self , ident ):
286- logging .info ('SubscriptionAPI POST called' )
286+ logging .info (f 'SubscriptionAPI POST called: { ident } ' )
287287 try :
288288 resp = error_404_response (request .path )
289289 if ident in members :
@@ -295,7 +295,7 @@ def post(self, ident):
295295
296296 # HTTP PATCH
297297 def patch (self , ident ):
298- logging .info ('SubscriptionAPI PATCH called' )
298+ logging .info (f 'SubscriptionAPI PATCH called: { ident } ' )
299299 raw_dict = request .get_json (force = True )
300300 try :
301301 resp = error_404_response (request .path )
@@ -317,14 +317,22 @@ def patch(self, ident):
317317
318318 # HTTP DELETE
319319 def delete (self , ident ):
320- logging .info ('SubscriptionAPI DELETE called' )
320+ logging .info (f 'SubscriptionAPI DELETE called: { ident } ' )
321321 try :
322322 resp = error_404_response (request .path )
323323 if ident in members :
324- s_config ['Members' ].remove (members [ident ]['@odata.id' ])
325- del members [ident ]
326- s_config ['Members@odata.count' ] -= 1
327- resp = success_response ('Resource deleted' , 200 )
324+ data_id = members [ident ]['@odata.id' ]
325+ # s_config['Members'] are of the form
326+ # "Members": [
327+ # { "@odata.id": "/redfish/v1/EventService/Subscriptions/1" },
328+ # { "@odata.id": "/redfish/v1/EventService/Subscriptions/2" } ]
329+ for i in range (len (s_config ['Members' ])):
330+ if data_id == s_config ['Members' ][i ]['@odata.id' ]:
331+ del s_config ['Members' ][i ]
332+ del members [ident ]
333+ s_config ['Members@odata.count' ] -= 1
334+ resp = success_response ('Resource deleted' , 200 )
335+ break
328336 except Exception :
329337 traceback .print_exc ()
330338 resp = simple_error_response ('Server encountered an unexpected Error' , 500 )
@@ -377,4 +385,4 @@ def CreateSubscription(ident, destination, event_types, context=None, registry_p
377385 except Exception :
378386 traceback .print_exc ()
379387 resp = simple_error_response ('Server encountered an unexpected Error' , 500 )
380- return resp
388+ return resp
0 commit comments