Merge pull request #1605 from mwhudson/explicit-install-media

do not let size: largest in storage autoinstall config match the inst…
This commit is contained in:
Michael Hudson-Doyle 2023-03-22 12:03:15 +13:00 committed by GitHub
commit 903299fb84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -345,6 +345,8 @@ A match spec supports the following keys:
* `ssd: yes|no`: matches a disk that is or is not an SSD (vs a rotating drive)
* `size: largest|smallest`: take the largest or smallest disk rather than an arbitrary one if there are multiple matches (support for `smallest` added in version 20.06.1)
A special sort of key is `install-media: yes`, which will take the disk the installer was loaded from (the `ssd` and `size` selectors will never return this disk). If installing to the install media, care obviously needs to be take to not overwrite the installer itself!
So for example, to match an arbitrary disk it is simply:
- type: disk

View File

@ -1185,6 +1185,12 @@ class FilesystemModel(object):
is_ssd = disk.info_for_display()['rotational'] == 'false'
return is_ssd == match['ssd']
def match_install_media(disk):
return disk in self._exclusions
if match.get('install-media', False):
matchers.append(match_install_media)
if 'serial' in match:
matchers.append(match_serial)
if 'model' in match:
@ -1209,6 +1215,8 @@ class FilesystemModel(object):
break
else:
candidates.append(candidate)
if 'size' in match or 'ssd' in match:
candidates = [c for c in candidates if c not in self._exclusions]
if match.get('size') == 'smallest':
candidates.sort(key=lambda d: d.size)
if match.get('size') == 'largest':