mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-09 17:07:43 +01:00
integrated system_controller into http_system endpoint
moved restart and shutdown procedure to system_controller -> works currently only under linux with systemctl
This commit is contained in:
parent
1d7cae39b7
commit
d5ed315034
2 changed files with 14 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
|
||||
import os
|
||||
|
||||
import aiohttp
|
||||
|
||||
|
@ -18,4 +18,12 @@ class SystemController:
|
|||
pass
|
||||
|
||||
|
||||
async def restart(self):
|
||||
logging.info("RESTART")
|
||||
os.system('systemctl reboot')
|
||||
pass
|
||||
|
||||
async def shutdown(self):
|
||||
logging.info("SHUTDOWN")
|
||||
os.system('systemctl poweroff')
|
||||
pass
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
from aiohttp import web
|
||||
from cbpi.job.aiohttp import get_scheduler_from_app
|
||||
import logging
|
||||
import os
|
||||
from cbpi.api import request_mapping
|
||||
from cbpi.utils import json_dumps
|
||||
from cbpi import __version__
|
||||
|
@ -10,6 +9,7 @@ class SystemHttpEndpoints:
|
|||
|
||||
def __init__(self,cbpi):
|
||||
self.cbpi = cbpi
|
||||
self.controller : SystemController = cbpi.system
|
||||
self.cbpi.register(self, url_prefix="/system")
|
||||
|
||||
@request_mapping("/", method="GET", auth_required=False)
|
||||
|
@ -95,10 +95,8 @@ class SystemHttpEndpoints:
|
|||
"200":
|
||||
description: successful operation
|
||||
"""
|
||||
logging.info("RESTART")
|
||||
os.system('systemctl reboot')
|
||||
pass
|
||||
return web.Response(text="NOT IMPLEMENTED")
|
||||
await self.controller.restart()
|
||||
return web.Response(text="RESTART")
|
||||
|
||||
@request_mapping("/shutdown", method="POST", name="ShutdownSerer", auth_required=False)
|
||||
async def shutdown(self, request):
|
||||
|
@ -111,7 +109,5 @@ class SystemHttpEndpoints:
|
|||
"200":
|
||||
description: successful operation
|
||||
"""
|
||||
logging.info("SHUTDOWN")
|
||||
os.system('systemctl poweroff')
|
||||
pass
|
||||
return web.Response(text="NOT IMPLEMENTED")
|
||||
await self.controller.shutdown()
|
||||
return web.Response(text="SHUTDOWN")
|
||||
|
|
Loading…
Reference in a new issue