コード例 #1
0
    def createDevice(self, device):
        """ Schedule creation of a device.

            TODO: We could do some things here like assign the next
                  available raid minor if one isn't already set.
        """
        self.devicetree.addOperation(OperationCreateDevice(device))
        if device.format.type:
            self.devicetree.addOperation(OperationCreateFormat(device))
コード例 #2
0
ファイル: lvm_gui.py プロジェクト: jeremie1112/pisilinux
    def run(self):
        if self.dialog is None:
            return []

        while 1:
            rc = self.dialog.exec_()
            operations = []
            if not rc:
                if self.isNew:
                    if self.lvs.has_key(self.origrequest.name):
                        del self.lvs[self.origrequest.name]
                self.destroy()
                return []

            widget = self.dialog.content

            name =  str(widget.name.text())
            pvs = widget.selectedPhysicalVolumes
            msg = sanityCheckVolumeGroupName(name)
            if msg:
                self.intf.messageWindow(_("Invalid Volume Group Name"),
                                        msg, type="warning")
                continue

            origname = self.origrequest.name
            if origname != name:
                if name in [vg.name for vg in self.storage.vgs]:
                    self.intf.messageWindow(_("Name in use"),
                                            _("The volume group name \"%s\" is "
                                              "already in use. Please pick another.")
                                              % (name,), type="warning")
                    continue

            peSize = widget.physicalExtends.itemData(widget.physicalExtends.currentIndex()).toInt()[0] / 1024.0

            origlvs = self.origrequest.lvs
            if not self.origrequest.exists:
                ctx.logger.debug("non-existing vg -- setting up lvs, pvs, name, peSize")
                for lv in self.origrequest.lvs:
                    self.origrequest._removeLogicalVolume(lv)

                for pv in self.origrequest.pvs:
                    if pv not in self.pvs:
                        self.origrequest._removePhysicalVolume(pv)

                for pv in self.pvs:
                    if pv not in self.origrequest.pvs:
                        self.origrequest._addPhysicalVolume(pv)

                self.origrequest.name = name
                self.origrequest.peSize = peSize

                if self.isNew:
                    operations = [OperationCreateDevice(self.origrequest)]

            for lv in origlvs:
                ctx.logger.debug("old lv %s..." % lv.lvname)
                if not lv.exists or lv.lvname not in self.lvs or \
                   (not self.lvs[lv.lvname]['exists'] and lv.exists):
                    ctx.logger.debug("removing lv %s" % lv.lvname)
                    if lv.format.type:
                        operations.append(OperationDestroyFormat(lv))

                    if lv in self.origrequest.lvs:
                        self.origrequest._removeLogicalVolume(lv)

                    operations.append(OperationDestroyDevice(lv))

            # schedule creation of all new lvs, their formats, luks devices, &c
            tempvg = widget.tmpVolumeGroup
            for lv in tempvg.lvs:
                ctx.logger.debug("new lv %s" % lv)
                if not lv.exists:
                    ctx.logger.debug("creating lv %s" % lv.lvname)
                    logicalvolume = LogicalVolume(lv.lvname, self.origrequest, size=lv.size)
                    operations.append(OperationCreateDevice(logicalvolume))

                    # create the format
                    mountpoint = getattr(lv.format, "mountpoint", None)
                    format = formats.getFormat(lv.format.type,
                                               mountpoint=mountpoint,
                                               device=logicalvolume.path)
                    operations.append(OperationCreateFormat(logicalvolume, format))
                else:
                    ctx.logger.debug("lv %s already exists" % lv.lvname)
                    origlv = widget.getLogicalVolumeByName(lv.lvname)
                    if lv.resizable and lv.targetSize != origlv.size:
                        operations.append(OperationResizeDevice(origlv, lv.targetSize))

                    if lv.format.exists:
                        ctx.logger.debug("format already exists")
                        usedev = origlv
                        format = lv.format
                        if format == usedev.originalFormat:
                            cancel = []
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="create",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            cancel.extend(self.parent.storage.devicetree.findOperations(type="destroy",
                                                                                        object="format",
                                                                                        devid=origlv.id))
                            for operation in cancel:
                                self.storage.devicetree.cancelOperation(operation)

                        if hasattr(format, "mountpoint"):
                            usedev.format.mountpoint = format.mountpoint

                        if format.migratable and format.migrate and \
                           not usedev.format.migrate:
                            usedev.format.migrate = format.migrate
                            operations.append(OperationMigrateFormat(usedev))

                        if format.resizable and lv.format.resizable and \
                                lv.targetSize != format.targetSize and \
                                lv.targetSize != lv.currentSize and \
                                usedev.format.exists:
                            ctx.logger.debug("resizing format on %s to %d" % (usedev.lvname, lv.targetSize))
                            operations.append(OperationResizeFormat(usedev, lv.targetSize))
                    elif lv.format.type:
                        ctx.logger.debug("new format: %s" % lv.format.type)
                        if origlv.format.type:
                            operations.append(OperationDestroyFormat(origlv))

                        mountpoint = getattr(lv.format, "mountpoint", None)
                        format = formats.getFormat(lv.format.type,
                                                   mountpoint=mountpoint,
                                                   device=origlv.path)
                        operations.append(OperationCreateFormat(origlv, format))
                    else:
                        ctx.logger.debug("no format!")
            break

        return operations
コード例 #3
0
 def formatDevice(self, device, format):
     """ Schedule formatting of a device. """
     self.devicetree.addOperation(OperationDestroyFormat(device))
     self.devicetree.addOperation(OperationCreateFormat(device, format))
コード例 #4
0
ファイル: raid_gui.py プロジェクト: ayhanyalcinsoy/yali
    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