handle a disk match in a layout

This commit is contained in:
Michael Hudson-Doyle 2020-04-07 21:23:03 +12:00
parent c20264bcd7
commit 30030ef3eb
2 changed files with 23 additions and 18 deletions

View File

@ -156,12 +156,13 @@ class FilesystemController(SubiquityController):
break break
log.debug("self.ai_data = %s", self.ai_data) log.debug("self.ai_data = %s", self.ai_data)
if 'layout' in self.ai_data: if 'layout' in self.ai_data:
layout = self.ai_data['layout']
with self.context.child("applying_autoinstall"): with self.context.child("applying_autoinstall"):
meth = getattr( meth = getattr(self, "guided_" + layout['name'])
self, "guided_" + self.ai_data['layout']['name']) disk = self.model.disk_for_match(
disks = self.model.all_disks() self.model.all_disks(),
disks.sort(key=lambda x: x.size) layout.get("match", {'size': 'largest'}))
meth(disks[-1]) meth(disk)
elif 'config' in self.ai_data: elif 'config' in self.ai_data:
with self.context.child("applying_autoinstall"): with self.context.child("applying_autoinstall"):
self.model.apply_autoinstall_config(self.ai_data['config']) self.model.apply_autoinstall_config(self.ai_data['config'])

View File

@ -1301,17 +1301,7 @@ class FilesystemModel(object):
return matchers return matchers
def apply_autoinstall_config(self, ai_config): def disk_for_match(self, disks, match):
disks = self.all_disks()
for action in ai_config:
if action['type'] == 'disk':
disk = None
if 'serial' in action:
disk = self._one(type='disk', serial=action['serial'])
elif 'path' in action:
disk = self._one(type='disk', path=action['path'])
else:
match = action.pop('match', {})
matchers = self._make_matchers(match) matchers = self._make_matchers(match)
candidates = [] candidates = []
for candidate in disks: for candidate in disks:
@ -1323,8 +1313,22 @@ class FilesystemModel(object):
if match.get('size') == 'largest': if match.get('size') == 'largest':
candidates.sort(key=lambda d: d.size, reverse=True) candidates.sort(key=lambda d: d.size, reverse=True)
if candidates: if candidates:
disk = candidates[0] return candidates[0]
return None
def apply_autoinstall_config(self, ai_config):
disks = self.all_disks()
for action in ai_config:
if action['type'] == 'disk':
disk = None
if 'serial' in action:
disk = self._one(type='disk', serial=action['serial'])
elif 'path' in action:
disk = self._one(type='disk', path=action['path'])
else: else:
match = action.pop('match', {})
disk = self.disk_for_match(disks, match)
if disk is None:
action['match'] = match action['match'] = match
if disk is None: if disk is None:
raise Exception("{} matched no disk".format(action)) raise Exception("{} matched no disk".format(action))