From db49d40f9421cbd766f640fb4702fc6f920ffd08 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Tue, 2 Mar 2021 11:04:40 +1300 Subject: [PATCH] move implementations of guided options into server code --- subiquity/common/filesystem.py | 58 -------------------- subiquity/server/controllers/filesystem.py | 61 ++++++++++++++++++++++ 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/subiquity/common/filesystem.py b/subiquity/common/filesystem.py index 45446800..3ad410c5 100644 --- a/subiquity/common/filesystem.py +++ b/subiquity/common/filesystem.py @@ -18,7 +18,6 @@ import logging from subiquity.common.types import Bootloader from subiquity.models.filesystem import ( align_up, - dehumanize_size, DeviceAction, Partition, ) @@ -373,60 +372,3 @@ class FilesystemManipulator: largest_part.size -= ( part_size - new_boot_disk.free_for_partitions) self._create_boot_partition(new_boot_disk) - - def guided_direct(self, disk): - self.reformat(disk) - result = { - "size": disk.free_for_partitions, - "fstype": "ext4", - "mount": "/", - } - self.partition_disk_handler(disk, None, result) - - def guided_lvm(self, disk, lvm_options=None): - self.reformat(disk) - if DeviceAction.TOGGLE_BOOT in disk.supported_actions: - self.add_boot_disk(disk) - self.create_partition( - device=disk, spec=dict( - size=dehumanize_size('1G'), - fstype="ext4", - mount='/boot' - )) - part = self.create_partition( - device=disk, spec=dict( - size=disk.free_for_partitions, - fstype=None, - )) - vg_name = 'ubuntu-vg' - i = 0 - while self.model._one(type='lvm_volgroup', name=vg_name) is not None: - i += 1 - vg_name = 'ubuntu-vg-{}'.format(i) - spec = dict(name=vg_name, devices=set([part])) - if lvm_options and lvm_options['encrypt']: - spec['password'] = lvm_options['luks_options']['password'] - vg = self.create_volgroup(spec) - # There's no point using LVM and unconditionally filling the - # VG with a single LV, but we should use more of a smaller - # disk to avoid the user running into out of space errors - # earlier than they probably expect to. - if vg.size < 10 * (2 << 30): - # Use all of a small (<10G) disk. - lv_size = vg.size - elif vg.size < 20 * (2 << 30): - # Use 10G of a smallish (<20G) disk. - lv_size = 10 * (2 << 30) - elif vg.size < 200 * (2 << 30): - # Use half of a larger (<200G) disk. - lv_size = vg.size // 2 - else: - # Use at most 100G of a large disk. - lv_size = 100 * (2 << 30) - self.create_logical_volume( - vg=vg, spec=dict( - size=lv_size, - name="ubuntu-lv", - fstype="ext4", - mount="/", - )) diff --git a/subiquity/server/controllers/filesystem.py b/subiquity/server/controllers/filesystem.py index 6b79f401..a7b61f07 100644 --- a/subiquity/server/controllers/filesystem.py +++ b/subiquity/server/controllers/filesystem.py @@ -44,6 +44,10 @@ from subiquity.common.types import ( ProbeStatus, StorageResponse, ) +from subiquity.models.filesystem import ( + dehumanize_size, + DeviceAction, + ) from subiquity.server.controller import ( SubiquityController, ) @@ -109,6 +113,63 @@ class FilesystemController(SubiquityController, FilesystemManipulator): "autoinstall config did not create needed bootloader " "partition") + def guided_direct(self, disk): + self.reformat(disk) + result = { + "size": disk.free_for_partitions, + "fstype": "ext4", + "mount": "/", + } + self.partition_disk_handler(disk, None, result) + + def guided_lvm(self, disk, lvm_options=None): + self.reformat(disk) + if DeviceAction.TOGGLE_BOOT in disk.supported_actions: + self.add_boot_disk(disk) + self.create_partition( + device=disk, spec=dict( + size=dehumanize_size('1G'), + fstype="ext4", + mount='/boot' + )) + part = self.create_partition( + device=disk, spec=dict( + size=disk.free_for_partitions, + fstype=None, + )) + vg_name = 'ubuntu-vg' + i = 0 + while self.model._one(type='lvm_volgroup', name=vg_name) is not None: + i += 1 + vg_name = 'ubuntu-vg-{}'.format(i) + spec = dict(name=vg_name, devices=set([part])) + if lvm_options and lvm_options['encrypt']: + spec['password'] = lvm_options['luks_options']['password'] + vg = self.create_volgroup(spec) + # There's no point using LVM and unconditionally filling the + # VG with a single LV, but we should use more of a smaller + # disk to avoid the user running into out of space errors + # earlier than they probably expect to. + if vg.size < 10 * (2 << 30): + # Use all of a small (<10G) disk. + lv_size = vg.size + elif vg.size < 20 * (2 << 30): + # Use 10G of a smallish (<20G) disk. + lv_size = 10 * (2 << 30) + elif vg.size < 200 * (2 << 30): + # Use half of a larger (<200G) disk. + lv_size = vg.size // 2 + else: + # Use at most 100G of a large disk. + lv_size = 100 * (2 << 30) + self.create_logical_volume( + vg=vg, spec=dict( + size=lv_size, + name="ubuntu-lv", + fstype="ext4", + mount="/", + )) + async def _probe_response(self, wait, resp_cls): if self._probe_task.task is None or not self._probe_task.task.done(): if wait: