diff --git a/scripts/rf_raw_request.py b/scripts/rf_raw_request.py index 4b4f5ab..946dba2 100644 --- a/scripts/rf_raw_request.py +++ b/scripts/rf_raw_request.py @@ -15,6 +15,7 @@ import json import os import redfish +import re # Get the input arguments argget = argparse.ArgumentParser( description = "A tool perform a raw request to a Redfish service" ) @@ -27,6 +28,17 @@ argget.add_argument( "--verbose", "-v", action = "store_true", help = "Indicates if HTTP response codes and headers are displayed", default = False ) args = argget.parse_args() +def ifmatch_header(redfish_obj, path, headers=None): + if headers is None: + headers = {} + try: + response = redfish_obj.get(path) + etag = response.getheader( "ETag" ) + if etag is not None: + headers[ "If-Match"] = etag + except Exception: + pass + return headers # Connect to the service with redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password ) as redfish_obj: # Encode the body @@ -50,9 +62,11 @@ elif args.method == "POST": resp = redfish_obj.post( args.request, body = body ) elif args.method == "PATCH": - resp = redfish_obj.patch( args.request, body = body ) + headers = ifmatch_header(redfish_obj, args.request, headers = headers) + resp = redfish_obj.patch( args.request, body = body, headers = headers) elif args.method == "PUT": - resp = redfish_obj.put( args.request, body = body ) + headers = ifmatch_header(redfish_obj, args.request, headers = headers) + resp = redfish_obj.put( args.request, body = body, headers = headers) elif args.method == "DELETE": resp = redfish_obj.delete( args.request ) else: