contents = [] for d in bff.form.candidate_netdevs: box = CheckBox(d.name, on_state_change=self._state_change) self.box_to_device[box] = d contents.append((box, self.pile.options('pack'))) self.pile.contents[:] = contents def _state_change(self, sender, state): device = self.box_to_device[sender] if state: self.selected.add(device) else: self.selected.remove(device) MultiNetdevField = simple_field(MultiNetdevChooser) MultiNetdevField.takes_default_style = False class BondForm(Form): def __init__(self, initial, candidate_netdevs, all_netdev_names): self.candidate_netdevs = candidate_netdevs self.all_netdev_names = all_netdev_names super().__init__(initial) connect_signal(self.mode.widget, 'select', self._select_level) self._select_level(None, self.mode.value) name = StringField(_("Name:")) devices = MultiNetdevField(_("Devices: ")) mode = ChoiceField(_("Bond mode:"), choices=BondParameters.modes)
self.bff.in_error = True self.bff.show_extra(("info_error", _("/ is not permitted " "in the name of a RAID device"))) return False elif len(ch) == 1 and ch.isspace(): self.bff.in_error = True self.bff.show_extra(("info_error", _("Whitespace is not permitted in the " "name of a RAID device"))) return False else: return super().valid_char(ch) RaidnameField = simple_field(RaidnameEditor) class RaidForm(CompoundDiskForm): def __init__(self, model, possible_components, initial, raid_names): self.raid_names = raid_names super().__init__(model, possible_components, initial) self.size.enabled = False name = RaidnameField(_("Name:")) level = ChoiceField(_("RAID Level:"), choices=raidlevel_choices) devices = MultiDeviceField(_("Devices:")) size = ReadOnlyField(_("Size:")) def clean_name(self, val): if not val:
def __init__(self): self.valid_char_pat = r'[a-fA-F0-9]' self.error_invalid_char = _("The secret can only contain hexadecimal " "characters, i.e. 0-9, a-f, A-F.") super().__init__() def valid_char(self, ch): if len(ch) == 1 and not re.match(self.valid_char_pat, ch): self.bff.in_error = True self.bff.show_extra(("info_error", self.error_invalid_char)) return False else: return super().valid_char(ch) RackSecretField = simple_field(RackSecretEditor) class RackForm(Form): cancel_label = _("Back") url = URLField(_("Ubuntu MAAS Region API address:"), help=_( "e.g. \"http://192.168.1.1:5240/MAAS\". " "localhost or 127.0.0.1 are not useful values here.")) secret = RackSecretField( _("MAAS shared secret:"), help=_("The secret can be found in /var/lib/maas/secret " "on the region controller. "))
def __init__(self): self.valid_char_pat = r'[-a-z0-9_]' self.error_invalid_char = _("The only characters permitted in this " "field are a-z, 0-9, _ and -") super().__init__() def valid_char(self, ch): if len(ch) == 1 and not re.match(self.valid_char_pat, ch): self.bff.in_error = True self.bff.show_extra(("info_error", self.error_invalid_char)) return False else: return super().valid_char(ch) UsernameField = simple_field(UsernameEditor) PasswordField = simple_field(PasswordEditor) class IdentityForm(Form): def __init__(self, reserved_usernames, initial): self.reserved_usernames = reserved_usernames super().__init__(initial=initial) username = UsernameField( _("Pick a username:"******"The username does not need to match your Windows username")) password = PasswordField(_("Choose a password:"******"Confirm your password:"******"Show Advanced Options Next Page"))
class UsernameEditor(StringEditor, WantsToKnowFormField): def valid_char(self, ch): if len(ch) == 1 and not re.match('[a-z0-9_-]', ch): self.bff.in_error = True self.bff.show_extra(( "info_error", "The only characters permitted in this field are a-z, 0-9, _ and -" )) return False else: return super().valid_char(ch) RealnameField = simple_field(RealnameEditor) UsernameField = simple_field(UsernameEditor) PasswordField = simple_field(PasswordEditor) class SSHImport(WidgetWrap, WantsToKnowFormField): signals = ['change'] _helps = { None: _("You can import your SSH keys from Github, Launchpad or Ubuntu One." ), "gh": _("Enter your github username."), "lp":
self.valid_char_pat = r'[-a-zA-Z0-9_+.]' self.error_invalid_char = _("The only characters permitted in the " "name of a volume group are a-z, A-Z, " "0-9, +, _, . and -") super().__init__() def valid_char(self, ch): if len(ch) == 1 and not re.match(self.valid_char_pat, ch): self.bff.in_error = True self.bff.show_extra(("info_error", self.error_invalid_char)) return False else: return super().valid_char(ch) VGNameField = simple_field(VGNameEditor) class VolGroupForm(CompoundDiskForm): def __init__(self, model, possible_components, initial, vg_names, deleted_vg_names): self.vg_names = vg_names self.deleted_vg_names = deleted_vg_names super().__init__(model, possible_components, initial) connect_signal(self.encrypt.widget, 'change', self._change_encrypt) setup_password_validation(self, _("passphrases")) self._change_encrypt(None, self.encrypt.value) name = VGNameField(_("Name:")) devices = MultiDeviceField(_("Devices:")) size = ReadOnlyField(_("Size:"))
self.valid_char_pat = r'[-a-zA-Z0-9_+.]' self.error_invalid_char = _("The only characters permitted in the " "name of a logical volume are a-z, A-Z, " "0-9, +, _, . and -") super().__init__() def valid_char(self, ch): if len(ch) == 1 and not re.match(self.valid_char_pat, ch): self.bff.in_error = True self.bff.show_extra(("info_error", self.error_invalid_char)) return False else: return super().valid_char(ch) LVNameField = simple_field(LVNameEditor) class PartitionForm(Form): def __init__(self, model, max_size, initial, lvm_names, device): self.model = model self.device = device self.existing_fs_type = None if device: existing_fs = device.original_fs() if existing_fs: self.existing_fs_type = existing_fs.fstype initial_path = initial.get('mount') self.mountpoints = { m.path: m.device.volume for m in self.model.all_mounts() if m.path != initial_path