Fix parsing pre-mounted disk configuration from configuration file (#2221)
This commit is contained in:
parent
f6106324eb
commit
30a374a65b
|
|
@ -42,12 +42,20 @@ class DiskLayoutType(Enum):
|
||||||
class DiskLayoutConfiguration:
|
class DiskLayoutConfiguration:
|
||||||
config_type: DiskLayoutType
|
config_type: DiskLayoutType
|
||||||
device_modifications: List[DeviceModification] = field(default_factory=list)
|
device_modifications: List[DeviceModification] = field(default_factory=list)
|
||||||
|
# used for pre-mounted config
|
||||||
|
mountpoint: Optional[Path] = None
|
||||||
|
|
||||||
def json(self) -> Dict[str, Any]:
|
def json(self) -> Dict[str, Any]:
|
||||||
return {
|
if self.config_type == DiskLayoutType.Pre_mount:
|
||||||
'config_type': self.config_type.value,
|
return {
|
||||||
'device_modifications': [mod.json() for mod in self.device_modifications]
|
'config_type': self.config_type.value,
|
||||||
}
|
'mountpoint': str(self.mountpoint)
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
return {
|
||||||
|
'config_type': self.config_type.value,
|
||||||
|
'device_modifications': [mod.json() for mod in self.device_modifications]
|
||||||
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_arg(cls, disk_config: Dict[str, List[Dict[str, Any]]]) -> Optional[DiskLayoutConfiguration]:
|
def parse_arg(cls, disk_config: Dict[str, List[Dict[str, Any]]]) -> Optional[DiskLayoutConfiguration]:
|
||||||
|
|
@ -64,6 +72,21 @@ class DiskLayoutConfiguration:
|
||||||
device_modifications=device_modifications
|
device_modifications=device_modifications
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if config_type == DiskLayoutType.Pre_mount.value:
|
||||||
|
if not (mountpoint := disk_config.get('mountpoint')):
|
||||||
|
raise ValueError('Must set a mountpoint when layout type is pre-mount')
|
||||||
|
|
||||||
|
path = Path(str(mountpoint))
|
||||||
|
|
||||||
|
mods = device_handler.detect_pre_mounted_mods(path)
|
||||||
|
device_modifications.extend(mods)
|
||||||
|
|
||||||
|
storage['MOUNT_POINT'] = path
|
||||||
|
|
||||||
|
config.mountpoint = path
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
for entry in disk_config.get('device_modifications', []):
|
for entry in disk_config.get('device_modifications', []):
|
||||||
device_path = Path(entry.get('device', None)) if entry.get('device', None) else None
|
device_path = Path(entry.get('device', None)) if entry.get('device', None) else None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,8 @@ def select_disk_config(
|
||||||
|
|
||||||
return disk.DiskLayoutConfiguration(
|
return disk.DiskLayoutConfiguration(
|
||||||
config_type=disk.DiskLayoutType.Pre_mount,
|
config_type=disk.DiskLayoutType.Pre_mount,
|
||||||
device_modifications=mods
|
device_modifications=mods,
|
||||||
|
mountpoint=path
|
||||||
)
|
)
|
||||||
|
|
||||||
preset_devices = [mod.device for mod in preset.device_modifications] if preset else []
|
preset_devices = [mod.device for mod in preset.device_modifications] if preset else []
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue