public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Abner Chang" <abner.chang@hpe.com>
To: devel@edk2.groups.io
Cc: Nickle Wang <nickle.wang@hpe.com>, Liming Gao <gaoliming@byosoft.com.cn>
Subject: [staging/edk2-redfish-client Tools PATCH 4/6] RedfishClientPkg/Redfish-Profile-Simulator: HTTP methods on Memory Collection
Date: Thu, 22 Jul 2021 14:08:15 +0800	[thread overview]
Message-ID: <20210722060817.18564-5-abner.chang@hpe.com> (raw)
In-Reply-To: <20210722060817.18564-1-abner.chang@hpe.com>

Add POST and PATCH methods on Memory collection and resource.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
---
 .../v1sim/redfishURIs.py                      | 25 +++++++++++
 .../v1sim/systems.py                          | 43 +++++++++++++++++++
 2 files changed, 68 insertions(+)

diff --git a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py
index 3c912f7ce1..35d3794cc6 100644
--- a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/redfishURIs.py
+++ b/RedfishClientPkg/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/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py b/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py
index b8b3788054..690101fb10 100644
--- a/RedfishClientPkg/Tools/Redfish-Profile-Simulator/v1sim/systems.py
+++ b/RedfishClientPkg/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


  parent reply	other threads:[~2021-07-22  7:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  6:08 [staging/edk2-redfish-client Tools PATCH 0/6] Initial commit of Redfish Profile Simulator Abner Chang
2021-07-22  6:08 ` [staging/edk2-redfish-client Tools PATCH 1/6] RedfishClientPkg/Tools: " Abner Chang
2021-08-08 13:05   ` Nickle Wang
2021-07-22  6:08 ` [staging/edk2-redfish-client Tools PATCH 2/6] RedfishClientPkg/Tools: Add more Redfish resource Abner Chang
2021-08-08 13:05   ` Nickle Wang
2021-07-22  6:08 ` [staging/edk2-redfish-client Tools PATCH 3/6] RedfishClientPkg/Redfish-Profile-Simulator: Add more features Abner Chang
2021-08-08 13:09   ` Nickle Wang
2021-07-22  6:08 ` Abner Chang [this message]
2021-07-22 14:58   ` [staging/edk2-redfish-client Tools PATCH 4/6] RedfishClientPkg/Redfish-Profile-Simulator: HTTP methods on Memory Collection Nickle Wang
2021-07-22  6:08 ` [staging/edk2-redfish-client Tools PATCH 5/6] RedfishClientPkg/Redfish-Profile-Simulator: Add ETAG on memory resource Abner Chang
2021-07-22 14:58   ` Nickle Wang
2021-07-22  6:08 ` [staging/edk2-redfish-client Tools PATCH 6/6] RedfishClientPkg/Redfish-Profile-Simulator: Add requirements Abner Chang
2021-07-22 14:59   ` Nickle Wang

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=20210722060817.18564-5-abner.chang@hpe.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