-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flask server to test sunfishcore library
Signed-off-by: Erika Rosaverde <erika.rosaverde@ibm.com>
- Loading branch information
1 parent
738128a
commit 70c17f1
Showing
15 changed files
with
461 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.DS_Store | ||
venv | ||
.vscode | ||
bin | ||
include | ||
lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
# sunfish_server | ||
Standalone RESTful API Server for Sunfish API | ||
# Sunfish_flask_test | ||
This application is a basic HTTP REST Server that can be used to test the sunfishcore library. | ||
|
||
## Requirements | ||
The sunfishcore library have to be intalled. To create the .whl installable file of sunfishcore library, follow follow the instructions at: | ||
https://github.com/erika-rosaverde/sunfish_library_reference/blob/main/README.md | ||
|
||
|
||
# Sunfishcore library installation | ||
Follow the following steps to install the sunfishcore library: | ||
> pip3 install [path_to_sunfishcore_library]/dist/sunfishcore-0.1.0-py3-none-any.whl | ||
> <source flask-test/bin/activate]> | ||
> flask run | ||
|
||
## Examples of requests: | ||
curl -X GET localhost:5000/redfish/v1/<resource path> | ||
|
||
curl -X POST \ | ||
-H "Content-Type: application/json" \ | ||
-d @<filename>.json localhost:5000/redfish/v1/<resource path> | ||
|
||
curl -X PUT \ | ||
-H "Content-Type: application/json" \ | ||
-d @<filename>.json localhost:5000/redfish/v1/<resource path> | ||
|
||
curl -X PATCH \ | ||
-H "Content-Type: application/json" \ | ||
-d @<filename>.json localhost:5000/redfish/v1/<resource path> | ||
|
||
curl -X DELETE localhost:5000/redfish/v1/<resource path> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1", | ||
"@odata.type": "#ComputerSystem.1.00.0.ComputerSystem", | ||
"Boot": { | ||
"BootSourceOverrideEnabled": "Once", | ||
"BootSourceOverrideSupported": [ | ||
"None", | ||
"Pxe", | ||
"Floppy", | ||
"Cd", | ||
"Usb" | ||
], | ||
"BootSourceOverrideTarget": "Pxe", | ||
"UefiTargetBootSourceOverride": "uefi device path" | ||
}, | ||
"FabricAdapters": [ | ||
{ | ||
"@odata.id": "/redfish/1/Systems/1/FabricAdapters" | ||
} | ||
], | ||
"Id": "1", | ||
"IndicatorLED": "On", | ||
"Manufacturer": "Manufacturer Name", | ||
"Memory": { | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Enabled" | ||
}, | ||
"TotalSystemMemoryGB": 8 | ||
}, | ||
"Model": "Model Name", | ||
"Name": "Computer Node 1", | ||
"Power": "Off", | ||
"Processors": { | ||
"Count": 4, | ||
"Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Enabled" | ||
} | ||
}, | ||
"SKU": "", | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Enabled" | ||
}, | ||
"SystemType": "Physical" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1234", | ||
"@odata.type": "#ComputerSystem.1.00.0.ComputerSystem", | ||
"Boot": { | ||
"BootSourceOverrideEnabled": "Once", | ||
"BootSourceOverrideSupported": [ | ||
"None", | ||
"Pxe", | ||
"Floppy", | ||
"Cd", | ||
"Usb" | ||
], | ||
"BootSourceOverrideTarget": "Pxe", | ||
"UefiTargetBootSourceOverride": "uefi device path" | ||
}, | ||
"FabricAdapters": [ | ||
{ | ||
"@odata.id": "/redfish/1/Systems/1234/FabricAdapters" | ||
} | ||
], | ||
"Id": "1234", | ||
"IndicatorLED": "Off", | ||
"Links": { | ||
"Chassis": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Chassis/1" | ||
} | ||
] | ||
}, | ||
"Manufacturer": "Manufacturer Name", | ||
"Memory": { | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Disabled" | ||
}, | ||
"TotalSystemMemoryGB": 12 | ||
}, | ||
"Model": "Model Name", | ||
"Name": "Compute Node 1234", | ||
"Power": "On", | ||
"Processors": { | ||
"Count": 4, | ||
"Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Enabled" | ||
} | ||
}, | ||
"SKU": "sku", | ||
"Status": { | ||
"Health": "OK", | ||
"HealthRollUp": "OK", | ||
"State": "Enabled" | ||
}, | ||
"SystemType": "Physical" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems", | ||
"@odata.type": "#SystemsCollection.SystemsCollection", | ||
"Members": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1" | ||
}, | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1234" | ||
} | ||
], | ||
"Members@odata.count": 2, | ||
"Name": "Systems Collection" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"@odata.id": "/redfish/v1", | ||
"@odata.type": "#ServiceRoot.v1_14_0.ServiceRoot", | ||
"Id": "RootService", | ||
"Name": "Root Service", | ||
"RedfishVersion": "1.14.0", | ||
"Systems": { | ||
"@odata.id": "/redfish/v1/Systems" | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright IBM Corp. 2023 | ||
# This software is available to you under a BSD 3-Clause License. | ||
# The full license terms are available here: https://github.com/OpenFabrics/sunfish_server_reference/blob/main/LICENSE | ||
|
||
from flask import Flask, request | ||
from sunfishcorelib.core import Core | ||
from sunfishcorelib.exceptions import * | ||
|
||
conf = { | ||
"storage_backend": "FS", | ||
"redfish_root": "/redfish/v1/", | ||
"backend_conf" : { | ||
"fs_root": "Resources" | ||
} | ||
} | ||
|
||
# initialize flask | ||
|
||
app = Flask(__name__) | ||
sunfish_core = Core(conf) | ||
|
||
# Usa codici http | ||
@app.route('/<path:resource>', methods=["GET"]) | ||
def get(resource): | ||
|
||
try: | ||
resp = sunfish_core.get_object(resource) | ||
return resp, 200 | ||
except ResourceNotFound as e: | ||
return e.message, 404 | ||
|
||
@app.route('/<path:resource>', methods=["POST"]) | ||
def post(resource): | ||
try : | ||
resp = sunfish_core.create_object(request.json) | ||
return resp | ||
except CollectionNotSupported as e: | ||
return e.message, 405 # method not allowed | ||
except AlreadyExists as e: | ||
return e.message, 409 # Conflict | ||
|
||
@app.route('/<path:resource>', methods=["PUT"]) | ||
def put(resource): | ||
try: | ||
data = request.json | ||
resp = sunfish_core.replace_object(data) | ||
return resp, 200 | ||
except ResourceNotFound as e: | ||
return e.message, 404 | ||
|
||
@app.route('/<path:resource>', methods=["PATCH"]) | ||
def patch(resource): | ||
try: | ||
data = request.json | ||
resp = sunfish_core.patch_object(data) | ||
return resp, 200 | ||
except ResourceNotFound as e: | ||
return e.message, 404 | ||
|
||
@app.route('/<path:resource>', methods=["DELETE"]) | ||
def delete(resource): | ||
try: | ||
resp = sunfish_core.delete_object(resource) | ||
return resp, 200 | ||
except ResourceNotFound as e: | ||
return e.message, 404 | ||
except ActionNotAllowed as e: | ||
return e.message, 403 # forbidden | ||
except InvalidPath as e: | ||
return e.message, 400 | ||
|
||
# we run app debugging mode | ||
app.run(debug=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
flask |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"@odata.id": "/Users/erika/Documents/private_sunfish_library_reference/sunfish_library_reference/Resources/Systems", | ||
"@odata.type": "#SystemsCollection.SystemsCollection", | ||
"Members": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1" | ||
}, | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1234" | ||
} | ||
], | ||
"Members@odata.count": 2, | ||
"Name": "Systems Collection" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1", | ||
"@odata.type": "#ComputerSystem.1.00.0.ComputerSystem", | ||
"Id": "1", | ||
"Name": "Compute Node 1", | ||
"SystemType": "Physical", | ||
"Manufacturer": "Manufacturer Name", | ||
"Model": "Model Name", | ||
"SKU": "", | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
}, | ||
"IndicatorLED": "Off", | ||
"Power": "On", | ||
"Boot": { | ||
"BootSourceOverrideEnabled": "Once", | ||
"BootSourceOverrideTarget": "Pxe", | ||
"BootSourceOverrideSupported": [ | ||
"None", | ||
"Pxe", | ||
"Floppy", | ||
"Cd", | ||
"Usb", | ||
"Hdd", | ||
"BiosSetup", | ||
"Utilities", | ||
"Diags", | ||
"UefiTarget" | ||
], | ||
"UefiTargetBootSourceOverride": "uefi device path" | ||
}, | ||
"Processors": { | ||
"Count": 8, | ||
"Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
} | ||
}, | ||
"Memory": { | ||
"TotalSystemMemoryGB": 16, | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
} | ||
}, | ||
"FabricAdapters": [ | ||
{ "@odata.id": "/redfish/1/Systems/1/FabricAdapters" } | ||
], | ||
"Links": { | ||
"Chassis": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Chassis/1" | ||
} | ||
] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"@odata.id": "/redfish/v1/Systems/1234", | ||
"@odata.type": "#ComputerSystem.1.00.0.ComputerSystem", | ||
"Id": "1234", | ||
"Name": "Compute Node 1234", | ||
"SystemType": "Physical", | ||
"Manufacturer": "Manufacturer Name", | ||
"Model": "Model Name", | ||
"SKU": "", | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
}, | ||
"IndicatorLED": "Off", | ||
"Power": "On", | ||
"Boot": { | ||
"BootSourceOverrideEnabled": "Once", | ||
"BootSourceOverrideTarget": "Pxe", | ||
"BootSourceOverrideSupported": [ | ||
"None", | ||
"Pxe", | ||
"Floppy", | ||
"Cd", | ||
"Usb" | ||
], | ||
"UefiTargetBootSourceOverride": "uefi device path" | ||
}, | ||
"Processors": { | ||
"Count": 4, | ||
"Model": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series", | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
} | ||
}, | ||
"Memory": { | ||
"TotalSystemMemoryGB": 8, | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK", | ||
"HealthRollUp": "OK" | ||
} | ||
}, | ||
"FabricAdapters": [ | ||
{ "@odata.id": "/redfish/1/Systems/1234/FabricAdapters" } | ||
], | ||
"Links": { | ||
"Chassis": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Chassis/1" | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.