Skip to content

Commit

Permalink
add guided luks options
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhudson committed Feb 11, 2020
1 parent e2410a0 commit f77c4dc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
9 changes: 6 additions & 3 deletions subiquity/controllers/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,9 @@ def guided(self, method):
self.ui.set_body(v)
if self.answers['guided']:
index = self.answers['guided-index']
disk = self.model.all_disks()[index]
v.choose_disk(None, disk)
v.form.guided.value = True
v.form.guided_choice.disk.widget.index = index
v.form._emit('done')

def reset(self):
log.info("Resetting Filesystem model")
Expand Down Expand Up @@ -658,7 +659,7 @@ def guided_direct(self, disk):
}
self.partition_disk_handler(disk, None, result)

def guided_lvm(self, disk):
def guided_lvm(self, disk, lvm_options):
self.reformat(disk)
if DeviceAction.MAKE_BOOT in disk.supported_actions:
self.make_boot_disk(disk)
Expand All @@ -674,6 +675,8 @@ def guided_lvm(self, disk):
fstype=None,
))
spec = dict(name="ubuntu-vg", devices=set([part]))
if lvm_options['encrypt']:
spec['password'] = lvm_options['luks_options']['password']
# create volume group on partition
vg = self.create_volgroup(spec)
self.create_logical_volume(
Expand Down
38 changes: 37 additions & 1 deletion subiquity/ui/views/filesystem/guided.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Form,
NO_CAPTION,
NO_HELP,
PasswordField,
RadioButtonField,
SubForm,
SubFormField,
Expand All @@ -51,10 +52,39 @@
review and modify the results.""")


class LUKSOptionsForm(SubForm):

password = PasswordField(_("Passphrase:"))
confirm_password = PasswordField(_("Confirm passphrase:"))

def validate_password(self):
if len(self.password.value) < 1:
return _("Password must be set")

def validate_confirm_password(self):
if self.password.value != self.confirm_password.value:
return _("Passwords do not match")


class LVMOptionsForm(SubForm):

def __init__(self, parent):
super().__init__(parent)
connect_signal(self.encrypt.widget, 'change', self._toggle)
self.luks_options.enabled = self.encrypt.value

def _toggle(self, sender, val):
self.luks_options.enabled = val

encrypt = BooleanField(_("Encrypt the LVM group with LUKS"), help=NO_HELP)
luks_options = SubFormField(LUKSOptionsForm, "", help=NO_HELP)


class GuidedChoiceForm(SubForm):

disk = ChoiceField(caption=NO_CAPTION, help=NO_HELP, choices=["x"])
use_lvm = BooleanField(_("Set up this disk as an LVM group"), help=NO_HELP)
lvm_options = SubFormField(LVMOptionsForm, "", help=NO_HELP)

def __init__(self, parent):
super().__init__(parent)
Expand All @@ -70,6 +100,11 @@ def __init__(self, parent):
t0.bind(t)
self.disk.widget.options = options
self.disk.widget.index = 0
connect_signal(self.use_lvm.widget, 'change', self._toggle)
self.lvm_options.enabled = self.use_lvm.value

def _toggle(self, sender, val):
self.lvm_options.enabled = val


class GuidedForm(Form):
Expand Down Expand Up @@ -137,7 +172,8 @@ def done(self, sender):
if results['guided']:
disk = results['guided_choice']['disk']
if results['guided_choice']['use_lvm']:
self.controller.guided_lvm(disk)
self.controller.guided_lvm(
disk, results['guided_choice']['lvm_options'])
else:
self.controller.guided_direct(disk)
self.controller.manual()
Expand Down

0 comments on commit f77c4dc

Please sign in to comment.