Esempio n. 1
0
    def raidLevelChanged(self, index):
        raidlevel = int(self.raidLevels.currentText())
        availraidparts = self.parent.storage.unusedRaidMembers(array=self.origrequest)
        maxspares = raid.get_raid_max_spares(raidlevel, numparts)

        if maxspares > 0 and not raid.isRaid(raid.RAID0, raidlevel):
           value = self.spareSpin.value()
           if value > maxspares:
               value = maxspares

           self.spareSpin.setRange(0, maxspares)
           self.spareSpin.setValue(value)
        else:
            self.spareSpin.setValue(0)
            self.spareSpin.setEnabled(False)
Esempio n. 2
0
    def raidLevelChanged(self, index):
        raidlevel = int(self.raidLevels.itemData(index))
        availraidparts = self.parent.storage.unusedRaidMembers(
            array=self.origrequest)
        maxspares = raid.get_raid_max_spares(raidlevel, len(availraidparts))

        if maxspares > 0 and not raid.isRaid(raid.RAID0, raidlevel):
            value = self.spareSpin.value()
            if value > maxspares:
                value = maxspares

            self.spareSpin.setRange(0, maxspares)
            self.spareSpin.setValue(value)
        else:
            self.spareSpin.setValue(0)
            self.spareSpin.setEnabled(False)
Esempio n. 3
0
    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            raidmembers = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content
            for index in range(widget.raidMembers.count()):
                if widget.raidMembers.item(index).checkState() == Qt.Checked:
                    raidmembers.append(widget.raidMembers.item(index).partition)

            # The user has to select some devices to be part of the array.
            if not raidmembers:
                continue

            mountpoint = str(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"),
                                            msg,
                                            customIcon="error")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint,),
                                            customIcon="error")
                    continue

            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                raidminor = widget.raidMinors.itemData(widget.raidMinors.currentIndex()).toInt()[0]
                raidlevel = widget.raidMinors.itemData(widget.raidLevels.currentIndex()).toInt()[0]

                if not raid.isRaid(raid.RAID0, raidlevel):
                    spares = widget.spareSpin.value()
                else:
                    spares = 0

                format = formats.getFormat(formatType, mountpoint=mountpoint)
                members = len(raidmembers) - spares

                try:
                    request = self.storage.newRaidArray(minor=raidminor,
                                                        level=raidlevel,
                                                        format=format,
                                                        parents=raidmembers,
                                                        totalDevices=len(raidmembers),
                                                        memberDevices=members)
                except ValueError, e:
                    self.intf.messageWindow(_("Error"), str(e),
                                            customIcon="error")
                    continue

                if not self.isNew:
                    # This may be handled in devicetree.registerAction,
                    # but not in case when we change minor and thus
                    # device name/path (at least with current md)
                    operations.append(OperationDestroyDevice(self.origrequest))

                operations.append(OperationCreateDevice(request))
                operations.append(OperationCreateFormat(request))

            else:
                format = None
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType, mountpoint=mountpoint, device=self.origrequest.path)
                    operations.append(OperationCreateFormat(self.origrequest, format))
                else:
                    cancel = []
                    cancel.extend(self.storage.devicetree.findOperations(type="destroy",
                                                                         object="format",
                                                                         devid=self.origrequest.id))
                    cancel.extend(self.storage.devicetree.findOperations(type="create",
                                                                         object="format",
                                                                         devid=self.origrequest.id))
                    for operation in cancel:
                        devicetree.removeOperation(operation)

                    self.origrequest.format = self.origrequest.originalFormat

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(self.origrequest))

                if self.origrequest.format.exists and not format and \
                   self.storage.formatByDefault(self.origrequest):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break
Esempio n. 4
0
    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            raidmembers = []

            if not rc:
                self.destroy()
                return []

            widget = self.dialog.content

            mountpoint = unicode(widget.mountpointMenu.currentText())
            active = widget.mountpointMenu.isEnabled()
            if active and mountpoint:
                msg = sanityCheckMountPoint(mountpoint)
                if msg:
                    self.intf.messageWindow(_("Mount Point Error"),
                                            msg,
                                            type="error")
                    continue

                used = False
                for (mp, dev) in self.storage.mountpoints.iteritems():
                    if mp == mountpoint and \
                       dev.id != self.origrequest.id and \
                       not (self.origrequest.format.type == "luks" and
                            self.origrequest in dev.parents):
                        used = True
                        break

                if used:
                    self.intf.messageWindow(_("Mount point in use"),
                                            _("The mount point \"%s\" is in "
                                              "use. Please pick another.") %
                                            (mountpoint, ),
                                            type="warning")
                    continue

            for index in range(widget.raidMembers.count()):
                if widget.raidMembers.item(index).checkState() == Qt.Checked:
                    raidmembers.append(
                        widget.raidMembers.item(index).partition)

            # The user has to select some devices to be part of the array.
            if not raidmembers:
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))
                self.intf.messageWindow(
                    _("Invalid Raid Members"),
                    _("A RAID%(level)d set requires at least %(min_member)d member"
                      ) % {
                          "level": raidlevel,
                          "min_member": raid.get_raid_min_members(raidlevel)
                      },
                    type="warning")
                continue

            if not self.origrequest.exists:
                formatType = str(widget.filesystemMenu.currentText())
                raidminor = int(
                    widget.raidMinors.itemData(
                        widget.raidMinors.currentIndex()))
                raidlevel = int(
                    widget.raidLevels.itemData(
                        widget.raidLevels.currentIndex()))

                if not raid.isRaid(raid.RAID0, raidlevel):
                    spares = widget.spareSpin.value()
                else:
                    spares = 0

                format = formats.getFormat(formatType, mountpoint=mountpoint)
                members = len(raidmembers) - spares

                try:
                    request = self.storage.newRaidArray(
                        minor=raidminor,
                        level=raidlevel,
                        format=format,
                        parents=raidmembers,
                        totalDevices=len(raidmembers),
                        memberDevices=members)
                except ValueError, msg:
                    self.intf.messageWindow(_("Invalid Raid Members"),
                                            unicode(msg),
                                            type="warning")
                    continue

                if not self.isNew:
                    # This may be handled in devicetree.registerAction,
                    # but not in case when we change minor and thus
                    # device name/path (at least with current md)
                    operations.append(OperationDestroyDevice(self.origrequest))

                operations.append(OperationCreateDevice(request))
                operations.append(OperationCreateFormat(request))

            else:
                format = None
                if widget.formatRadio.isChecked():
                    formatType = str(widget.formatCombo.currentText())
                    format = formats.getFormat(formatType,
                                               mountpoint=mountpoint,
                                               device=self.origrequest.path)
                    operations.append(
                        OperationCreateFormat(self.origrequest, format))
                else:
                    cancel = []
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="destroy",
                            object="format",
                            devid=self.origrequest.id))
                    cancel.extend(
                        self.storage.devicetree.findOperations(
                            type="create",
                            object="format",
                            devid=self.origrequest.id))
                    for operation in cancel:
                        self.storage.devicetree.removeOperation(operation)

                    self.origrequest.format = self.origrequest.originalFormat

                if self.origrequest.format.mountable:
                    self.origrequest.format.mountpoint = mountpoint

                if widget.migrateRadio.isChecked():
                    operations.append(OperationMigrateFormat(self.origrequest))

                if self.origrequest.format.exists and not format and \
                   self.storage.formatByDefault(self.origrequest):
                    if not queryNoFormatPreExisting(self.intf):
                        continue

            # everything ok, fall out of loop
            break