public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-redfish-client][PATCH 2/4] Redfish-Profile-Simulator: HTTP methods on Memory Collection
@ 2023-05-02  7:50 Nickle Wang
  0 siblings, 0 replies; only message in thread
From: Nickle Wang @ 2023-05-02  7:50 UTC (permalink / raw)
  To: devel; +Cc: Abner Chang, Igor Kulchytskyy

Add POST and PATCH methods on Memory collection and resource.

Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
---
 .../v1sim/redfishURIs.py                      | 25 +++++++++++
 .../v1sim/systems.py                          | 43 +++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py b/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py
index 3c912f7..35d3794 100644
--- a/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py
+++ b/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py
@@ -1,6 +1,7 @@
 #
 # Copyright Notice:
 # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 # Copyright Notice:
@@ -308,6 +309,30 @@ def rfApi_SimpleServer(root, versions, host="127.0.0.1", port=5000, cert="", key
         else:
             return err_string, status_code
 
+    @app.route("/redfish/v1/Systems/<string:system_id>/Memory", methods=['POST'])
+    @auth.rfAuthRequired
+    def rf_computer_memory_post(system_id):
+        print ("in POST memory collection")
+        rdata = json.loads(request.data,object_pairs_hook=OrderedDict)
+        print("rdata:{}".format(rdata))
+        rc, status_code, err_string, resp = root.components['Systems'].get_element(system_id).components['Memory'].post_resource(rdata)
+        if rc == 0:
+            return resp, status_code
+        else:
+            return err_string, status_code
+
+    @app.route("/redfish/v1/Systems/<string:system_id>/Memory/<string:MemoryIdx>", methods=['PATCH'])
+    @auth.rfAuthRequired
+    def rf_computer_memory_patch(system_id, MemoryIdx):
+        print ("in PATCH memory[%s] resource" % MemoryIdx)
+        rdata = json.loads(request.data,object_pairs_hook=OrderedDict)
+        print("rdata:{}".format(rdata))
+        rc, status_code, err_string, resp = root.components['Systems'].get_element(system_id).components['Memory'].patch_memory(MemoryIdx, rdata)
+        if rc == 0:
+            return resp, status_code
+        else:
+            return err_string, status_code
+
     def resolve_path(service, path):
         parts = path.split('/')
         result = service
diff --git a/Tools/Redfish-Profile-Simulator/v1sim/systems.py b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
index b8b3788..690101f 100644
--- a/Tools/Redfish-Profile-Simulator/v1sim/systems.py
+++ b/Tools/Redfish-Profile-Simulator/v1sim/systems.py
@@ -2,6 +2,7 @@
 # Copyright Notice:
 #
 # Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
+# (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 # Copyright Notice:
@@ -123,9 +124,50 @@ class RfSystemObj(RfResource):
 
 # subclass Logs Collection
 class RfMemoryCollection(RfCollection):
+    def final_init_processing(self, base_path, rel_path):
+        self.maxIdx = self.res_data["Members@odata.count"]
+
     def element_type(self):
         return RfMemory
 
+    def post_resource(self, post_data):
+        print("Members@odata.count:{}".format(self.res_data["Members@odata.count"]))
+        print("Members:{}".format(self.res_data["Members"]))
+        print("post_data:{}".format(post_data))
+
+        self.res_data["Members@odata.count"] = self.res_data["Members@odata.count"] + 1
+        self.maxIdx = self.maxIdx + 1
+        newMemoryIdx = self.maxIdx
+        newMemoryUrl = self.res_data["@odata.id"] + "/" + str(newMemoryIdx)
+        self.res_data["Members"].append({"@odata.id":newMemoryUrl})
+
+        post_data["@odata.id"] = newMemoryUrl
+        self.elements[str(newMemoryIdx)] = post_data
+
+        resp = flask.Response(json.dumps(post_data,indent=4))
+        resp.headers["Location"] = newMemoryUrl
+        return 0, 200, None, resp
+
+    def patch_memory(self, Idx, patch_data):
+        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
+
+    def get_memory(self, Idx):
+        return json.dumps(self.elements[Idx],indent=4)
+
+    def delete_memory(self, Idx):
+        print("in delete_memory")
+
+        resp = flask.Response(json.dumps(self.elements[Idx],indent=4))
+
+        self.elements.pop(Idx)
+        self.res_data["Members@odata.count"] = self.res_data["Members@odata.count"] - 1
+
+        newMemoryUrl = self.res_data["@odata.id"] + "/" + str(Idx)
+        self.res_data["Members"].remove({"@odata.id":newMemoryUrl})
+        return 0, 200, None, resp
+
 
 class RfMemory(RfResource):
     pass
@@ -267,3 +309,4 @@ class RfBootOptionCollection(RfCollection):
         return 0, 200, None, resp
 
 class RfBootOption(RfResource):
+    pass
-- 
2.17.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-02  7:51 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-02  7:50 [edk2-redfish-client][PATCH 2/4] Redfish-Profile-Simulator: HTTP methods on Memory Collection Nickle Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox