示例#1
0
class RaidForm(CompoundDiskForm):
    def __init__(self, model, possible_components, initial, raid_names):
        self.raid_names = raid_names
        super().__init__(model, possible_components, initial)

    name = RaidnameField(_("Name:"))
    level = ChoiceField(_("RAID Level:"), choices=raidlevel_choices)
    devices = MultiDeviceField(_("Devices:"))
    size = ReadOnlyField(_("Size:"))

    def clean_name(self, val):
        if not val:
            raise ValueError("The name cannot be empty")
        if not re.match('md[0-9]+', val):
            val = 'md/' + val
        return val

    def validate_name(self):
        if self.name.value in self.raid_names:
            return _("There is already a RAID named '{}'").format(
                self.name.value)
        if self.name.value in ('/dev/md/.', '/dev/md/..'):
            return _(". and .. are not valid names for RAID devices")

    def validate_devices(self):
        log.debug('validate_devices %s %s', len(self.devices.value),
                  self.level.value)
        active_device_count = len(self.devices.widget.active_devices)
        if active_device_count < self.level.value.min_devices:
            return _(
                'RAID Level "{}" requires at least {} active devices').format(
                    self.level.value.name, self.level.value.min_devices)
        return super().validate_devices()
示例#2
0
class VolGroupForm(CompoundDiskForm):
    def __init__(self, model, possible_components, initial, vg_names):
        self.vg_names = vg_names
        super().__init__(model, possible_components, initial)

    name = VGNameField(_("Name:"))
    devices = MultiDeviceField(_("Devices:"))
    size = ReadOnlyField(_("Size:"))

    def validate_devices(self):
        if len(self.devices.value) < 1:
            return _("Select at least one device to be part of the volume "
                     "group.")

    def validate_name(self):
        v = self.name.value
        if not v:
            return _("The name of a volume group cannot be empty")
        if v.startswith('-'):
            return _("The name of a volume group cannot start with a hyphen")
        if v in ('.', '..', 'md') or os.path.exists('/dev/' + v):
            return _("{} is not a valid name for a volume group").format(v)
        if v in self.vg_names:
            return _("There is already a volume group named '{}'").format(
                self.name.value)
示例#3
0
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:"))
    encrypt = BooleanField(_("Create encrypted volume"))
    password = PasswordField(_("Passphrase:"))
    confirm_password = PasswordField(_("Confirm passphrase:"))

    def _change_encrypt(self, sender, new_value):
        self.password.enabled = new_value
        self.confirm_password.enabled = new_value
        if not new_value:
            self.password.validate()
            self.confirm_password.validate()

    def validate_devices(self):
        if len(self.devices.value) < 1:
            return _("Select at least one device to be part of the volume "
                     "group.")

    def validate_name(self):
        v = self.name.value
        if not v:
            return _("The name of a volume group cannot be empty")
        if v.startswith('-'):
            return _("The name of a volume group cannot start with a hyphen")
        if v in self.vg_names:
            return _("There is already a volume group named '{name}'").format(
                name=self.name.value)
        if v in ('.', '..', 'md') or os.path.exists('/dev/' + v):
            if v not in self.deleted_vg_names:
                return _("{name} is not a valid name for a volume "
                         "group").format(name=v)

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

    def validate_confirm_password(self):
        if self.encrypt.value and \
          self.password.value != self.confirm_password.value:
            return _("Passphrases do not match")
示例#4
0
class VolGroupForm(CompoundDiskForm):

    def __init__(self, model, possible_components, initial, vg_names):
        self.vg_names = vg_names
        super().__init__(model, possible_components, initial)

    name = StringField(_("Name:"))
    devices = MultiDeviceField(_("Devices:"))
    size = ReadOnlyField(_("Size:"))

    def validate_devices(self):
        if len(self.devices.value) < 1:
            return _("Select at least one device to be part of the volume "
                     "group.")

    def validate_name(self):
        if self.name.value in self.vg_names:
            return _("There is already a volume group named '{}'").format(
                self.name.value)