Пример #1
0
 def deleteAllLogicalPartitions(self, part):
     """Add delete specs for all logical partitions in part."""
     for partition in partedUtils.get_logical_partitions(part.disk):
         partName = partedUtils.get_partition_name(partition)
         request = self.getRequestByDeviceName(partName)
         self.removeRequest(request)
         if request.preexist:
             drive = partedUtils.get_partition_drive(partition)
             delete = partRequests.DeleteSpec(drive, partition.geom.start,
                                              partition.geom.end)
             self.addDelete(delete)
Пример #2
0
def doEditPartitionByRequest(intf, requestlist, part):
    """Edit a partition from the request list.

    intf is the interface
    requestlist is the list of requests
    partition is either the part object or the uniqueID if not a part
    """

    if part == None:
        intf.messageWindow(_("Unable To Edit"),
                           _("You must select a partition to edit"),
                           custom_icon="error")

        return (None, None)

    if type(part) == type("RAID"):

        # see if device is in our partition requests, remove
        request = requestlist.getRequestByID(int(part))

        if request:
            state = isNotChangable(request, requestlist)
            if state is not None:
                intf.messageWindow(_("Unable To Edit"),
                                   _("You cannot edit this partition:\n\n") +
                                   state,
                                   custom_icon="error")
                return (None, None)

        if request.type == REQUEST_RAID:
            return ("RAID", request)
        elif request.type == REQUEST_VG:
            return ("LVMVG", request)
        elif request.type == REQUEST_LV:
            return ("LVMLV", request)
        else:
            return (None, None)
    elif part.type & parted.PARTITION_FREESPACE:
        request = partRequests.PartitionSpec(
            fsset.fileSystemTypeGetDefault(),
            start=partedUtils.start_sector_to_cyl(part.geom.dev,
                                                  part.geom.start),
            end=partedUtils.end_sector_to_cyl(part.geom.dev, part.geom.end),
            drive=[partedUtils.get_partition_drive(part)])

        return ("NEW", request)
    elif part.type & parted.PARTITION_EXTENDED:
        return (None, None)

    ret = requestlist.containsImmutablePart(part)
    if ret:
        intf.messageWindow(_("Unable To Edit"),
                           _("You cannot edit this "
                             "partition, as it is an extended partition "
                             "which contains %s") % (ret),
                           custom_icon="error")
        return 0

    name = partedUtils.get_partition_name(part)
    request = requestlist.getRequestByDeviceName(name)
    if request:
        state = isNotChangable(request, requestlist)
        if state is not None:
            intf.messageWindow(_("Unable To Edit"),
                               _("You cannot edit this partition:\n\n") +
                               state,
                               custom_icon="error")
            return (None, None)

        return ("PARTITION", request)
    else:  # shouldn't ever happen
        raise ValueError, ("Trying to edit non-existent partition %s" %
                           (partedUtils.get_partition_name(part)))
Пример #3
0
def doDeletePartitionByRequest(intf,
                               requestlist,
                               partition,
                               confirm=1,
                               quiet=0):
    """Delete a partition from the request list.

    intf is the interface
    requestlist is the list of requests
    partition is either the part object or the uniqueID if not a part
    """

    if partition == None:
        intf.messageWindow(_("Unable To Delete"),
                           _("You must first select a partition to delete."),
                           custom_icon="error")
        return 0

    if type(partition) == type("RAID"):
        device = partition
    elif partition.type & parted.PARTITION_FREESPACE:
        intf.messageWindow(_("Unable To Delete"),
                           _("You cannot delete free space."),
                           custom_icon="error")
        return 0
    elif partition.type & parted.PARTITION_PROTECTED:
        # LDL formatted DASDs always have one partition, you'd have to reformat the
        # DASD in CDL mode to get rid of it
        intf.messageWindow(
            _("Unable To Delete"),
            _("You cannot delete a partition of a LDL formatted DASD."),
            custom_icon="error")
        return 0
    else:
        device = partedUtils.get_partition_name(partition)

    ret = requestlist.containsImmutablePart(partition)
    if ret:
        if not quiet:
            intf.messageWindow(_("Unable To Delete"),
                               _("You cannot delete this "
                                 "partition, as it is an extended partition "
                                 "which contains %s") % (ret),
                               custom_icon="error")
        return 0

    # see if device is in our partition requests, remove
    if type(partition) == type("RAID"):
        request = requestlist.getRequestByID(device)
    else:
        request = requestlist.getRequestByDeviceName(device)

    if request:
        state = isNotChangable(request, requestlist)
        if state is not None:
            if not quiet:
                intf.messageWindow(_("Unable To Delete"),
                                   _("You cannot delete this partition:\n\n") +
                                   state,
                                   custom_icon="error")
            return (None, None)

        if confirm and not confirmDeleteRequest(intf, request):
            return 0

        if request.getPreExisting():
            if isinstance(request, partRequests.PartitionSpec):
                # get the drive
                drive = partedUtils.get_partition_drive(partition)

                if partition.type & parted.PARTITION_EXTENDED:
                    requestlist.deleteAllLogicalPartitions(partition)

                delete = partRequests.DeleteSpec(drive, partition.geom.start,
                                                 partition.geom.end)
                requestlist.addDelete(delete)
            elif isinstance(request, partRequests.LogicalVolumeRequestSpec):
                vgreq = requestlist.getRequestByID(request.volumeGroup)
                delete = partRequests.DeleteLogicalVolumeSpec(
                    request.logicalVolumeName, vgreq.volumeGroupName)
                requestlist.addDelete(delete)
            elif isinstance(request, partRequests.VolumeGroupRequestSpec):
                delete = partRequests.DeleteVolumeGroupSpec(
                    request.volumeGroupName)
                requestlist.addDelete(delete)
            # FIXME: do we need to do anything with preexisting raids?

    # now remove the request
        requestlist.deleteDependentRequests(request)
        requestlist.removeRequest(request)
    else:  # is this a extended partition we made?
        if partition.type & parted.PARTITION_EXTENDED:
            requestlist.deleteAllLogicalPartitions(partition)
        else:
            raise ValueError, "Deleting a non-existent partition"

    del partition
    return 1
Пример #4
0
    def setFromDisk(self, diskset):
        """Clear the delete list and set self.requests to reflect disk."""
        self.deletes = []
        self.requests = []
        diskset.refreshDevices()
        labels = diskset.getLabels()
        drives = diskset.disks.keys()
        drives.sort()
        for drive in drives:
            disk = diskset.disks[drive]
            part = disk.next_partition()
            while part:
                if part.type & parted.PARTITION_METADATA:
                    part = disk.next_partition(part)
                    continue

                format = None
                if part.type & parted.PARTITION_FREESPACE:
                    ptype = None
                elif part.type & parted.PARTITION_EXTENDED:
                    ptype = None
                elif part.get_flag(parted.PARTITION_RAID) == 1:
                    ptype = fsset.fileSystemTypeGet("software RAID")
                elif part.get_flag(parted.PARTITION_LVM) == 1:
                    ptype = fsset.fileSystemTypeGet("physical volume (LVM)")
                else:
                    ptype = partedUtils.get_partition_file_system_type(part)

                    # FIXME: we don't handle ptype being None very well, so
                    # just say it's foreign.  Should probably fix None
                    # handling instead some day.
                    if ptype is None:
                        ptype = fsset.fileSystemTypeGet("foreign")

                start = part.geom.start
                end = part.geom.end
                size = partedUtils.getPartSizeMB(part)
                drive = partedUtils.get_partition_drive(part)

                spec = partRequests.PreexistingPartitionSpec(ptype,
                                                             size=size,
                                                             start=start,
                                                             end=end,
                                                             drive=drive,
                                                             format=format)
                spec.device = fsset.PartedPartitionDevice(part).getDevice()

                # set label if makes sense
                if ptype and ptype.isMountable() and \
                   (ptype.getName() == "ext2" or ptype.getName() == "ext3"):
                    if spec.device in labels.keys():
                        if labels[spec.device] and len(
                                labels[spec.device]) > 0:
                            spec.fslabel = labels[spec.device]

                self.addRequest(spec)
                part = disk.next_partition(part)

        # now we need to read in all pre-existing RAID stuff
        diskset.startAllRaid()
        mdList = diskset.mdList
        for raidDev in mdList:
            (theDev, devices, level, numActive) = raidDev

            level = "RAID%s" % (level, )
            try:
                chunk = isys.getRaidChunkFromDevice(theDev)
            except Exception, e:
                log("couldn't get chunksize of %s: %s" % (theDev, e))
                chunk = None

            # is minor always mdN ?
            minor = int(theDev[2:])
            raidvols = []
            for dev in devices:
                req = self.getRequestByDeviceName(dev)
                if not req:
                    log("RAID device %s using non-existent partition %s" %
                        (theDev, dev))
                    continue
                raidvols.append(req.uniqueID)

            fs = partedUtils.sniffFilesystemType(theDev)
            if fs is None:
                fsystem = fsset.fileSystemTypeGet("foreign")
            else:
                fsystem = fsset.fileSystemTypeGet(fs)

            mnt = None
            format = 0

            spares = len(devices) - numActive
            spec = partRequests.RaidRequestSpec(fsystem,
                                                format=format,
                                                raidlevel=level,
                                                raidmembers=raidvols,
                                                raidminor=minor,
                                                raidspares=spares,
                                                mountpoint=mnt,
                                                preexist=1,
                                                chunksize=chunk)
            spec.size = spec.getActualSize(self, diskset)
            self.addRequest(spec)
Пример #5
0
def doEditPartitionByRequest(intf, requestlist, part):
    """Edit a partition from the request list.

    intf is the interface
    requestlist is the list of requests
    partition is either the part object or the uniqueID if not a part
    """
    
    if part == None:
        intf.messageWindow(_("Unable To Edit"),
                           _("You must select a partition to edit"), custom_icon="error")

        return (None, None)

    if type(part) == type("RAID"):

	# see if device is in our partition requests, remove
        request = requestlist.getRequestByID(int(part))
	    
	if request:
	    state = isNotChangable(request, requestlist)
	    if state is not None:
		intf.messageWindow(_("Unable To Edit"), _("You cannot edit this partition:\n\n") + state,
				   custom_icon="error")
		return (None, None)

	if request.type == REQUEST_RAID:
	    return ("RAID", request)
	elif request.type == REQUEST_VG:
	    return ("LVMVG", request)
	elif request.type == REQUEST_LV:
	    return ("LVMLV", request)
	else:
	    return (None, None)
    elif part.type & parted.PARTITION_FREESPACE:
        request = partRequests.PartitionSpec(fsset.fileSystemTypeGetDefault(),
            start = partedUtils.start_sector_to_cyl(part.geom.dev,
                                                    part.geom.start),
            end = partedUtils.end_sector_to_cyl(part.geom.dev,
                                                part.geom.end),
            drive = [ partedUtils.get_partition_drive(part) ])

        return ("NEW", request)
    elif part.type & parted.PARTITION_EXTENDED:
        return (None, None)
    
    ret = requestlist.containsImmutablePart(part)
    if ret:
        intf.messageWindow(_("Unable To Edit"),
                           _("You cannot edit this "
                             "partition, as it is an extended partition "
                             "which contains %s") %(ret), custom_icon="error")
        return 0

    name = partedUtils.get_partition_name(part)
    request = requestlist.getRequestByDeviceName(name)
    if request:
	state = isNotChangable(request, requestlist)
	if state is not None:
	    intf.messageWindow(_("Unable To Edit"),
			       _("You cannot edit this partition:\n\n") + state, custom_icon="error")
	    return (None, None)
	
        return ("PARTITION", request)
    else: # shouldn't ever happen
        raise ValueError, ("Trying to edit non-existent partition %s"
                           % (partedUtils.get_partition_name(part)))
Пример #6
0
def doDeletePartitionByRequest(intf, requestlist, partition,
                               confirm=1, quiet=0):
    """Delete a partition from the request list.

    intf is the interface
    requestlist is the list of requests
    partition is either the part object or the uniqueID if not a part
    """
    
    if partition == None:
        intf.messageWindow(_("Unable To Delete"),
                           _("You must first select a partition to delete."),
			   custom_icon="error")
        return 0

    if type(partition) == type("RAID"):
        device = partition
    elif partition.type & parted.PARTITION_FREESPACE:
        intf.messageWindow(_("Unable To Delete"),
                           _("You cannot delete free space."),
			   custom_icon="error")
        return 0
    elif partition.type & parted.PARTITION_PROTECTED:
        # LDL formatted DASDs always have one partition, you'd have to reformat the
        # DASD in CDL mode to get rid of it
        intf.messageWindow(_("Unable To Delete"),
                           _("You cannot delete a partition of a LDL formatted DASD."),
			   custom_icon="error")
        return 0
    else:
        device = partedUtils.get_partition_name(partition)

    ret = requestlist.containsImmutablePart(partition)
    if ret:
        if not quiet:
            intf.messageWindow(_("Unable To Delete"),
                               _("You cannot delete this "
                                 "partition, as it is an extended partition "
                                 "which contains %s") %(ret),
			       custom_icon="error")
        return 0

    # see if device is in our partition requests, remove
    if type(partition) == type("RAID"):
	request = requestlist.getRequestByID(device)
    else:
	request = requestlist.getRequestByDeviceName(device)
	    
    if request:
	state = isNotChangable(request, requestlist)

        # If the partition is protected, we also can't delete it so specify a
        # reason why.
        if state is None and request.getProtected():
            state = _("This partition is holding the data for the hard "
                      "drive install.")

        if state:
            if not quiet:
                intf.messageWindow(_("Unable To Delete"),
				   _("You cannot delete this partition:\n\n") + state,
				   custom_icon="error")
	    return (None, None)

        if confirm and not confirmDeleteRequest(intf, request):
            return 0

        if request.getPreExisting():
            if isinstance(request, partRequests.PartitionSpec):
                # get the drive
                drive = partedUtils.get_partition_drive(partition)

                if partition.type & parted.PARTITION_EXTENDED:
                    requestlist.deleteAllLogicalPartitions(partition)

                delete = partRequests.DeleteSpec(drive, partition.geom.start,
                                                 partition.geom.end)
                requestlist.addDelete(delete)
            elif isinstance(request, partRequests.LogicalVolumeRequestSpec):
                vgreq = requestlist.getRequestByID(request.volumeGroup)
                delete = partRequests.DeleteLogicalVolumeSpec(request.logicalVolumeName,
                                                              vgreq.volumeGroupName)
                requestlist.addDelete(delete)
            elif isinstance(request, partRequests.VolumeGroupRequestSpec):
                delete = partRequests.DeleteVolumeGroupSpec(request.volumeGroupName)
                requestlist.addDelete(delete)
            # FIXME: do we need to do anything with preexisting raids?

        # now remove the request
        requestlist.deleteDependentRequests(request)
        requestlist.removeRequest(request)
    else: # is this a extended partition we made?
        if partition.type & parted.PARTITION_EXTENDED:
            requestlist.deleteAllLogicalPartitions(partition)
        else:
            #raise ValueError, "Deleting a non-existent partition"
            return 0

    del partition
    return 1