From 501cafaf97b424626b073d07c5027cdd59fe8e3d Mon Sep 17 00:00:00 2001 From: Eugene Konstantinov Date: Fri, 30 Dec 2022 23:05:57 +0300 Subject: [PATCH] Extended get_asic() method --- api/api.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/api/api.py b/api/api.py index ed693b0..5820220 100644 --- a/api/api.py +++ b/api/api.py @@ -80,13 +80,43 @@ async def get_asic(asic_id: int): 'password': host.password, 'type': host.type, 'power': host.power, - 'phase': host.phase + 'phase': host.phase, + 'power_group': host.power_group } @app.post("/update_asic") async def update_asic(request: Request): - return await request.json() + with orm.db_session: + data = await request.json() + host = Hosts.get(id=data['id']) + + # Creating new entry + if not host: + asic = Hosts( + ip=data['ip'], + port=data['port'], + user=data['user'], + password=data['password'], + type=data['type'], + power=data['power'], + phase=data['phase'], + power_group=data['power_group'], + online='false' + ) + return {'success': 'true', 'status': 'created'} + # Updating existing entry + else: + host.ip = data['ip'] + host.port = data['port'] + host.user = data['user'] + host.password = data['password'] + host.type = data['type'] + host.power = data['power'] + host.phase = data['phase'] + host.power_group = data['power_group'] + + return {'success': 'true', 'status': 'updated'} @app.get("/asic_status")