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 <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2024-04-11 09:39:41 +02:00
parent 6db2ff8113
commit 5553793f43
2 changed files with 13 additions and 1 deletions

View File

@ -879,6 +879,7 @@ class MirrorPost:
elected: Optional[str] = None elected: Optional[str] = None
candidates: Optional[List[str]] = None candidates: Optional[List[str]] = None
staged: Optional[str] = None staged: Optional[str] = None
use_during_installation: Optional[bool] = None
class MirrorPostResponse(enum.Enum): class MirrorPostResponse(enum.Enum):
@ -892,6 +893,9 @@ class MirrorGet:
elected: Optional[str] elected: Optional[str]
candidates: List[str] candidates: List[str]
staged: Optional[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): class MirrorSelectionFallback(enum.Enum):

View File

@ -368,7 +368,11 @@ class MirrorController(SubiquityController):
# Skip the country-mirrors if they have not been resolved yet. # Skip the country-mirrors if they have not been resolved yet.
candidates = [c.uri for c in compatibles if c.uri is not None] candidates = [c.uri for c in compatibles if c.uri is not None]
return MirrorGet( 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: async def POST(self, data: Optional[MirrorPost]) -> MirrorPostResponse:
@ -420,6 +424,10 @@ class MirrorController(SubiquityController):
ensure_elected_in_candidates() ensure_elected_in_candidates()
await self.configured() 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 return MirrorPostResponse.OK
async def disable_components_GET(self) -> List[str]: async def disable_components_GET(self) -> List[str]: