Skip to content

Commit 4c077c3

Browse files
committed
WIP: swagger yaml defination
Using openapi 3.0 specification to define the restAPI for beaker backend. skeleton api with some dummy methods to allow for testing the test framework. Once this is fleshed out we can start migrating the model code over and then create the actual rest methods.
1 parent ef0bc9c commit 4c077c3

30 files changed

+1252
-0
lines changed

API/requirements.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
attrs==23.1.0
2+
blinker==1.6.3
3+
certifi==2023.7.22
4+
charset-normalizer==3.3.0
5+
click==8.1.7
6+
clickclick==20.10.2
7+
connexion==3.0.5
8+
Flask==2.2.2
9+
flask-marshmallow==0.14.0
10+
Flask-SQLAlchemy==3.0.3
11+
greenlet==3.0.0
12+
idna==3.4
13+
inflection==0.5.1
14+
itsdangerous==2.1.2
15+
Jinja2==3.1.2
16+
jsonschema==4.19.1
17+
jsonschema-specifications==2023.7.1
18+
MarkupSafe==2.1.3
19+
marshmallow==3.20.1
20+
marshmallow-sqlalchemy==0.29.0
21+
packaging==23.2
22+
PyYAML==6.0.1
23+
referencing==0.30.2
24+
requests==2.31.0
25+
rpds-py==0.10.3
26+
six==1.16.0
27+
SQLAlchemy==2.0.22
28+
swagger-ui-bundle==0.0.9
29+
typing_extensions==4.8.0
30+
urllib3==2.0.6
31+
Werkzeug==2.2.2

API/setup.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[metadata]
2+
name = bkr.api
3+
4+
[options]
5+
package_dir=
6+
=src
7+
packages = find:
8+
zip_safe = False
9+
python_requires = >= 3
10+
[options.packages.find]
11+
where = src
12+
exclude =
13+
tests*
14+
.gitignore

API/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from setuptools import setup
2+
setup()

API/src/bkr/api/__init__.py

Whitespace-only changes.

API/src/bkr/api/arches.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import abort
2+
3+
ARCHES = {}
4+
5+
def post(arch):
6+
if arch and arch not in ARCHES:
7+
ARCHES[arch] = {
8+
"arch": arch,
9+
}
10+
return ARCHES[arch], 201
11+
else:
12+
abort(
13+
406,
14+
f"{arch} already exists",
15+
)
16+
17+
def search(offset=0, limit=None):
18+
start = 0
19+
end = len(ARCHES.values())
20+
if offset and limit:
21+
start = offset * limit
22+
end = start + limit
23+
return list(ARCHES.values())[start:end]

API/src/bkr/api/health.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def search():
2+
return {'msg': 'ok'}, 200
3+

API/src/bkr/api/lab_controllers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from flask import abort
2+
3+
LABCONTROLLERS = {}
4+
5+
def post(lab_controller):
6+
fqdn = lab_controller.get("fqdn")
7+
user_name = lab_controller.get("user_name", "")
8+
email_address = lab_controller.get("email_address", "")
9+
password = lab_controller.get("password", "")
10+
11+
if fqdn and fqdn not in LABCONTROLLERS:
12+
LABCONTROLLERS[fqdn] = {
13+
"fqdn": fqdn,
14+
"user_name": user_name,
15+
"email_address": email_address,
16+
"password": password,
17+
}
18+
return LABCONTROLLERS[fqdn], 201
19+
else:
20+
abort(
21+
406,
22+
f"Lab Controller with fqdn {fqdn} already exists",
23+
)
24+
25+
def search(offset=0, limit=None):
26+
start = 0
27+
end = len(LABCONTROLLERS.values())
28+
if offset and limit:
29+
start = offset * limit
30+
end = start + limit
31+
return list(LABCONTROLLERS.values())[start:end]
32+
33+
def get(lab_controller):
34+
pass
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from flask import abort
2+
from bkr.api.lab_controllers import LABCONTROLLERS
3+
from bkr.api.arches import ARCHES
4+
#from bkr.model import System
5+
6+
SYSTEMS = {}
7+
8+
def post(system):
9+
fqdn = system.get("fqdn")
10+
owner = system.get("owner")
11+
status = system.get("status", "unavailable")
12+
status_reason = system.get("status_reason", "")
13+
arches = system.get("arches", [])
14+
power = system.get("power", {})
15+
location = system.get("location", "")
16+
lender = system.get("lender", "")
17+
vender = system.get("vender", "")
18+
model = system.get("model", "")
19+
serial = system.get("serial", "")
20+
lab_controller = system.get("lab_controller", "")
21+
22+
if lab_controller and lab_controller not in LABCONTROLLERS:
23+
abort(
24+
406,
25+
f"Lab Controller {lab_controller} doesn't exist",
26+
)
27+
28+
for arch in arches:
29+
if arch not in ARCHES:
30+
abort(
31+
406,
32+
f"{arch} doesn't exist, create it first.",
33+
)
34+
35+
if fqdn and fqdn not in SYSTEMS:
36+
SYSTEMS[fqdn] = {
37+
"fqdn": fqdn,
38+
"owner": owner,
39+
"status": status,
40+
"status_reason": status_reason,
41+
"arches": arches,
42+
"power": power,
43+
"location": location,
44+
"lender": lender,
45+
"vender": vender,
46+
"model": model,
47+
"serial": serial,
48+
"lab_controller": lab_controller,
49+
}
50+
return SYSTEMS[fqdn], 201
51+
else:
52+
abort(
53+
406,
54+
f"System with fqdn {fqdn} already exists",
55+
)
56+
57+
def search(offset=0, limit=None):
58+
start = 0
59+
end = len(SYSTEMS.values())
60+
if offset and limit:
61+
start = offset * limit
62+
end = start + limit
63+
return list(SYSTEMS.values())[start:end]
64+
65+
def get(fqdn):
66+
if fqdn in SYSTEMS:
67+
return SYSTEMS[fqdn]
68+
else:
69+
abort(
70+
404,
71+
f"System with fqdn {fqdn} not found",
72+
)
73+
74+
def put(fqdn):
75+
pass
76+
77+
def delete(fqdn):
78+
pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def search():
2+
pass
3+
4+
def post():
5+
pass
6+
7+
def get():
8+
pass
9+
10+
def delete():
11+
pass
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def search():
2+
pass
3+
4+
def post():
5+
pass
6+
7+
def get():
8+
pass
9+
10+
def delete():
11+
pass

0 commit comments

Comments
 (0)