handle a disk match in a layout
This commit is contained in:
parent
c20264bcd7
commit
30030ef3eb
|
@ -156,12 +156,13 @@ class FilesystemController(SubiquityController):
|
|||
break
|
||||
log.debug("self.ai_data = %s", self.ai_data)
|
||||
if 'layout' in self.ai_data:
|
||||
layout = self.ai_data['layout']
|
||||
with self.context.child("applying_autoinstall"):
|
||||
meth = getattr(
|
||||
self, "guided_" + self.ai_data['layout']['name'])
|
||||
disks = self.model.all_disks()
|
||||
disks.sort(key=lambda x: x.size)
|
||||
meth(disks[-1])
|
||||
meth = getattr(self, "guided_" + layout['name'])
|
||||
disk = self.model.disk_for_match(
|
||||
self.model.all_disks(),
|
||||
layout.get("match", {'size': 'largest'}))
|
||||
meth(disk)
|
||||
elif 'config' in self.ai_data:
|
||||
with self.context.child("applying_autoinstall"):
|
||||
self.model.apply_autoinstall_config(self.ai_data['config'])
|
||||
|
|
|
@ -1301,17 +1301,7 @@ class FilesystemModel(object):
|
|||
|
||||
return matchers
|
||||
|
||||
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:
|
||||
match = action.pop('match', {})
|
||||
def disk_for_match(self, disks, match):
|
||||
matchers = self._make_matchers(match)
|
||||
candidates = []
|
||||
for candidate in disks:
|
||||
|
@ -1323,8 +1313,22 @@ class FilesystemModel(object):
|
|||
if match.get('size') == 'largest':
|
||||
candidates.sort(key=lambda d: d.size, reverse=True)
|
||||
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:
|
||||
match = action.pop('match', {})
|
||||
disk = self.disk_for_match(disks, match)
|
||||
if disk is None:
|
||||
action['match'] = match
|
||||
if disk is None:
|
||||
raise Exception("{} matched no disk".format(action))
|
||||
|
|
Loading…
Reference in New Issue