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:
avollkopf 2021-08-12 18:09:15 +02:00
parent 1d7cae39b7
commit d5ed315034
2 changed files with 14 additions and 10 deletions

View file

@ -1,5 +1,5 @@
import logging import logging
import os
import aiohttp import aiohttp
@ -18,4 +18,12 @@ class SystemController:
pass 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

View file

@ -1,7 +1,6 @@
from aiohttp import web from aiohttp import web
from cbpi.job.aiohttp import get_scheduler_from_app from cbpi.job.aiohttp import get_scheduler_from_app
import logging import logging
import os
from cbpi.api import request_mapping from cbpi.api import request_mapping
from cbpi.utils import json_dumps from cbpi.utils import json_dumps
from cbpi import __version__ from cbpi import __version__
@ -10,6 +9,7 @@ class SystemHttpEndpoints:
def __init__(self,cbpi): def __init__(self,cbpi):
self.cbpi = cbpi self.cbpi = cbpi
self.controller : SystemController = cbpi.system
self.cbpi.register(self, url_prefix="/system") self.cbpi.register(self, url_prefix="/system")
@request_mapping("/", method="GET", auth_required=False) @request_mapping("/", method="GET", auth_required=False)
@ -95,10 +95,8 @@ class SystemHttpEndpoints:
"200": "200":
description: successful operation description: successful operation
""" """
logging.info("RESTART") await self.controller.restart()
os.system('systemctl reboot') return web.Response(text="RESTART")
pass
return web.Response(text="NOT IMPLEMENTED")
@request_mapping("/shutdown", method="POST", name="ShutdownSerer", auth_required=False) @request_mapping("/shutdown", method="POST", name="ShutdownSerer", auth_required=False)
async def shutdown(self, request): async def shutdown(self, request):
@ -111,7 +109,5 @@ class SystemHttpEndpoints:
"200": "200":
description: successful operation description: successful operation
""" """
logging.info("SHUTDOWN") await self.controller.shutdown()
os.system('systemctl poweroff') return web.Response(text="SHUTDOWN")
pass
return web.Response(text="NOT IMPLEMENTED")