diff --git a/subiquity/common/apidef.py b/subiquity/common/apidef.py index 5ec2ffb7..bb476174 100644 --- a/subiquity/common/apidef.py +++ b/subiquity/common/apidef.py @@ -39,6 +39,7 @@ from subiquity.common.types import ( ModifyPartitionV2, RefreshStatus, ShutdownMode, + DriversResponse, SnapInfo, SnapListResponse, SnapSelection, @@ -294,8 +295,8 @@ class API: -> StorageResponseV2: ... class drivers: - def GET(wait: bool = False) -> Optional[bool]: ... - def POST(install: bool): ... + def GET(wait: bool = False) -> DriversResponse: ... + def POST(install: bool) -> None: ... class snaplist: def GET(wait: bool = False) -> SnapListResponse: ... diff --git a/subiquity/common/types.py b/subiquity/common/types.py index ffc5ceed..9f2a870a 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -369,6 +369,17 @@ class SnapInfo: channels: List[ChannelSnapInfo] = attr.Factory(list) +@attr.s(auto_attribs=True) +class DriversResponse: + """ Response to GET request to drivers. + :install: tells whether third-party drivers will be installed (if any is + available). + :has_drivers: tells if any third-party driver is available. It will bet set + to None until we figure out what drivers are available. """ + install: bool + has_drivers: Optional[bool] + + @attr.s(auto_attribs=True) class SnapSelection: name: str diff --git a/subiquity/server/controllers/drivers.py b/subiquity/server/controllers/drivers.py index 7b64e37d..b8d439de 100644 --- a/subiquity/server/controllers/drivers.py +++ b/subiquity/server/controllers/drivers.py @@ -20,6 +20,7 @@ from typing import Optional from subiquitycore.context import with_context from subiquity.common.apidef import API +from subiquity.common.types import DriversResponse from subiquity.server.controller import SubiquityController from subiquity.server.curtin import run_curtin_command from subiquity.server.types import InstallerChannels @@ -42,7 +43,7 @@ class DriversController(SubiquityController): } autoinstall_default = {"install": False} - has_drivers = None + has_drivers: Optional[bool] = None def make_autoinstall(self): return { @@ -86,11 +87,12 @@ class DriversController(SubiquityController): if not self.has_drivers: await self.configured() - async def GET(self, wait: bool = False) -> Optional[bool]: + async def GET(self, wait: bool = False) -> DriversResponse: if wait: await self._drivers_task - return self.has_drivers + return DriversResponse(install=self.model.do_install, + has_drivers=self.has_drivers) - async def POST(self, install: bool): + async def POST(self, install: bool) -> None: self.model.do_install = install await self.configured()