From 5553793f43ba78c6289d13315af263748fb6ee83 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 11 Apr 2024 09:39:41 +0200 Subject: [PATCH] mirror: allow to query or set if archive/mirror is used during install The /mirror GET and POST endpoints now include a boolean field named "use_during_installation". * if set to True, the mirror information will be used during installation to fetch packages online. * if set to False, we will only fetch packages from the pool. In either case, the mirror information will still be used to build the etc/apt/ directory in the target system. Currently, the way use_during_installation is implemented is coupled with the force_offline property of the network model. This means that Ubuntu Pro and other stuff will be disabled too if we're skipping the use of the archive. NOTE: the default value for "use_during_installation" in the POST endpoint is `null` ; which means that we should not change the current value of force_offline. Signed-off-by: Olivier Gayot --- subiquity/common/types.py | 4 ++++ subiquity/server/controllers/mirror.py | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/subiquity/common/types.py b/subiquity/common/types.py index 4c5ae938..5155a0e1 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -879,6 +879,7 @@ class MirrorPost: elected: Optional[str] = None candidates: Optional[List[str]] = None staged: Optional[str] = None + use_during_installation: Optional[bool] = None class MirrorPostResponse(enum.Enum): @@ -892,6 +893,9 @@ class MirrorGet: elected: Optional[str] candidates: List[str] staged: Optional[str] + # Tells whether the mirror will be used during the installation. + # When it is False, we will only fetch packages from the pool. + use_during_installation: bool class MirrorSelectionFallback(enum.Enum): diff --git a/subiquity/server/controllers/mirror.py b/subiquity/server/controllers/mirror.py index 3f85f1da..ac3a9560 100644 --- a/subiquity/server/controllers/mirror.py +++ b/subiquity/server/controllers/mirror.py @@ -368,7 +368,11 @@ class MirrorController(SubiquityController): # Skip the country-mirrors if they have not been resolved yet. candidates = [c.uri for c in compatibles if c.uri is not None] return MirrorGet( - relevant=relevant, elected=elected, candidates=candidates, staged=staged + relevant=relevant, + elected=elected, + candidates=candidates, + staged=staged, + use_during_installation=not self.app.base_model.network.force_offline, ) async def POST(self, data: Optional[MirrorPost]) -> MirrorPostResponse: @@ -420,6 +424,10 @@ class MirrorController(SubiquityController): ensure_elected_in_candidates() await self.configured() + + if data.use_during_installation is not None: + self.app.base_model.network.force_offline = not data.use_during_installation + return MirrorPostResponse.OK async def disable_components_GET(self) -> List[str]: