storage/v2: refactor partition format/mount attrs
Cleanup some duplicated logic.
This commit is contained in:
parent
21c731f7ec
commit
4ec569fb74
|
@ -275,13 +275,6 @@ def _for_client_disk(disk, *, min_size=0):
|
||||||
|
|
||||||
@for_client.register(Partition)
|
@for_client.register(Partition)
|
||||||
def _for_client_partition(partition, *, min_size=0):
|
def _for_client_partition(partition, *, min_size=0):
|
||||||
format = ''
|
|
||||||
mount = ''
|
|
||||||
if partition._fs:
|
|
||||||
format = partition._fs.fstype
|
|
||||||
if partition._fs._mount:
|
|
||||||
mount = partition._fs._mount.path
|
|
||||||
|
|
||||||
return types.Partition(
|
return types.Partition(
|
||||||
size=partition.size,
|
size=partition.size,
|
||||||
number=partition._number,
|
number=partition._number,
|
||||||
|
@ -290,5 +283,5 @@ def _for_client_partition(partition, *, min_size=0):
|
||||||
grub_device=partition.grub_device,
|
grub_device=partition.grub_device,
|
||||||
boot=partition.boot,
|
boot=partition.boot,
|
||||||
annotations=annotations(partition) + usage_labels(partition),
|
annotations=annotations(partition) + usage_labels(partition),
|
||||||
mount=mount,
|
mount=partition.mount,
|
||||||
format=format)
|
format=partition.format)
|
||||||
|
|
|
@ -454,6 +454,18 @@ class _Formattable(ABC):
|
||||||
else:
|
else:
|
||||||
return cd
|
return cd
|
||||||
|
|
||||||
|
@property
|
||||||
|
def format(self):
|
||||||
|
if not self._fs:
|
||||||
|
return None
|
||||||
|
return self._fs.fstype
|
||||||
|
|
||||||
|
@property
|
||||||
|
def mount(self):
|
||||||
|
if not self._fs or not self._fs._mount:
|
||||||
|
return None
|
||||||
|
return self._fs._mount.path
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def ok_for_raid(self):
|
def ok_for_raid(self):
|
||||||
|
|
|
@ -374,15 +374,9 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
|
||||||
if data.partition.boot is not None \
|
if data.partition.boot is not None \
|
||||||
and data.partition.boot != partition.boot:
|
and data.partition.boot != partition.boot:
|
||||||
raise ValueError('edit_partition does not support changing boot')
|
raise ValueError('edit_partition does not support changing boot')
|
||||||
existing_format = ''
|
|
||||||
existing_mount = ''
|
|
||||||
if partition._fs:
|
|
||||||
existing_format = partition._fs.fstype
|
|
||||||
if partition._fs._mount:
|
|
||||||
existing_mount = partition._fs._mount.path
|
|
||||||
spec = {
|
spec = {
|
||||||
'fstype': data.partition.format or existing_format,
|
'fstype': data.partition.format or partition.format,
|
||||||
'mount': data.partition.mount or existing_mount,
|
'mount': data.partition.mount or partition.mount,
|
||||||
}
|
}
|
||||||
self.partition_disk_handler(disk, partition, spec)
|
self.partition_disk_handler(disk, partition, spec)
|
||||||
return await self.v2_GET()
|
return await self.v2_GET()
|
||||||
|
|
Loading…
Reference in New Issue