-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
145 lines (101 loc) · 4.33 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from flask import Flask, jsonify, make_response, request, send_file
from functools import wraps
from typing import Any, Callable
import os.path
app = Flask(__name__)
model_name = "r820"
def authorization(func: Callable[..., Any]) -> Callable[..., Any]:
@wraps(func)
def wrapper(*args: Any, **kwargs: Any) -> Any:
authorization = request.headers.get("Authorization")
if not authorization:
return make_response(jsonify({"message": "Unauthorized"}), 401)
if authorization != "Basic cm9vdDpjYWx2aW4=":
return make_response(jsonify({"message": "Still unauthorized"}), 401)
return func(*args, **kwargs)
return wrapper
@app.route("/redfish/v1")
def ServiceRoot():
if not os.path.exists(f"static/{model_name}/ServiceRoot.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(
f"static/{model_name}/ServiceRoot.json", mimetype="application/json"
)
@app.route("/redfish/v1/Chassis")
@authorization
def ChassisCollection():
if not os.path.exists(f"static/{model_name}/ChassisCollection.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/ChassisCollection.json")
@app.route("/redfish/v1/Managers")
@authorization
def ManagerCollection():
if not os.path.exists(f"static/{model_name}/ManagerCollection.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/ManagerCollection.json")
@app.route("/redfish/v1/Managers/<string:manager>")
@authorization
def Manager(manager):
if not os.path.exists(f"static/{model_name}/Managers/{manager}.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/Managers/{manager}.json")
@app.route("/redfish/v1/Systems")
@authorization
def ComputerSystemCollection():
if not os.path.exists(f"static/{model_name}/ComputerSystemCollection.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/ComputerSystemCollection.json")
@app.route("/redfish/v1/Systems/<string:system>")
@authorization
def ComputerSystem(system):
if not os.path.exists(f"static/{model_name}/Systems/{system}.json"):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/Systems/{system}.json")
@app.route("/redfish/v1/Systems/<string:system>/Storage")
@authorization
def StorageCollection(system):
if not os.path.exists(
f"static/{model_name}/Systems/{system}/StorageCollection.json"
):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/Systems/{system}/StorageCollection.json")
@app.route("/redfish/v1/Systems/<string:system>/Storage/<string:storage>")
@authorization
def Storage(system, storage):
if not os.path.exists(
f"static/{model_name}/Systems/{system}/Storage/{storage}.json"
):
return jsonify({"Error": "File not found"}), 404
return send_file(f"static/{model_name}/Systems/{system}/Storage/{storage}.json")
@app.route("/redfish/v1/Systems/<string:system>/Storage/Drives/<string:drive>")
@authorization
def StorageDrive(system, drive):
if not os.path.exists(
f"static/{model_name}/Systems/{system}/Storage/Drives/{drive}.json"
):
return jsonify({"Error": "File not found"}), 404
return send_file(
f"static/{model_name}/Systems/{system}/Storage/Drives/{drive}.json"
)
@app.route("/redfish/v1/Systems/<string:system>/Storage/<string:controller>/Volumes")
@authorization
def VolumeCollection(system, controller):
if not os.path.exists(
f"static/{model_name}/Systems/{system}/Storage/{controller}/VolumeCollection.json"
):
return jsonify({"Error": "File not found"}), 404
return send_file(
f"static/{model_name}/Systems/{system}/Storage/{controller}/VolumeCollection.json"
)
@app.route("/redfish/v1/Systems/<string:system>/Storage/Volumes/<string:volume>")
@authorization
def StorageVolume(system, volume):
if not os.path.exists(
f"static/{model_name}/Systems/{system}/Storage/Volumes/{volume}.json"
):
return jsonify({"Error": "File not found"}), 404
return send_file(
f"static/{model_name}/Systems/{system}/Storage/Volumes/{volume}.json"
)
if __name__ == "__main__":
app.run()