public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nickle Wang" <nicklew@nvidia.com>
To: <devel@edk2.groups.io>
Cc: Abner Chang <abner.chang@amd.com>, Igor Kulchytskyy <igork@ami.com>
Subject: [edk2-redfish-client][PATCH 3/4] Redfish-Profile-Simulator: Add ETAG on memory resource
Date: Tue, 2 May 2023 15:51:04 +0800	[thread overview]
Message-ID: <20230502075104.16659-1-nicklew@nvidia.com> (raw)

Add ETAG support on Memory resource.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 Tools/Redfish-Profile-Simulator/v1sim/systems.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
index 690101f..de4b839 100644
--- a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
+++ b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
@@ -18,6 +18,7 @@ from .resource import RfResource, RfCollection
 from .storage import RfSimpleStorageCollection, RfSmartStorage
 import flask
 import json
+import hashlib
 from collections import OrderedDict
 
 class RfSystemsCollection(RfCollection):
@@ -142,13 +143,25 @@ class RfMemoryCollection(RfCollection):
         self.res_data["Members"].append({"@odata.id":newMemoryUrl})
 
         post_data["@odata.id"] = newMemoryUrl
+
+        md5 = hashlib.md5()
+        md5.update(json.dumps(post_data).encode("utf-8"))
+        etag_str = 'W/"' + md5.hexdigest() + '"'
+        post_data["@odata.etag"] = etag_str
         self.elements[str(newMemoryIdx)] = post_data
 
         resp = flask.Response(json.dumps(post_data,indent=4))
         resp.headers["Location"] = newMemoryUrl
+        resp.headers["ETag"] = etag_str
+
         return 0, 200, None, resp
 
     def patch_memory(self, Idx, patch_data):
+        md5 = hashlib.md5()
+        md5.update(json.dumps(patch_data).encode("utf-8"))
+        etag_str = 'W/"' + md5.hexdigest() + '"'
+        patch_data["@odata.etag"] = etag_str
+
         self.elements[str(Idx)] = {**self.elements[str(Idx)], **patch_data}
         resp = flask.Response(json.dumps(self.elements[str(Idx)],indent=4))
         return 0, 200, None, resp
-- 
2.17.1


                 reply	other threads:[~2023-05-02  7:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230502075104.16659-1-nicklew@nvidia.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox