def containsImmutablePart(self, part): """Returns whether the partition contains parts we can't delete.""" if not part or (type(part) == type("RAID")) or (type(part) == type(1)): return None if not part.type & parted.PARTITION_EXTENDED: return None disk = part.disk while part: if not part.is_active(): part = disk.next_partition(part) continue device = partedUtils.get_partition_name(part) request = self.getRequestByDeviceName(device) if request: if request.getProtected(): return _("the partition in use by the installer.") if self.isRaidMember(request): return _("a partition which is a member of a RAID array.") if self.isLVMVolumeGroupMember(request): return _( "a partition which is a member of a LVM Volume Group.") part = disk.next_partition(part) return None
def getAvailRaidPartitions(self, request, diskset): """Return a list of tuples of RAID partitions which can be used. Return value is (part, size, used) where used is 0 if not, 1 if so, 2 if used for *this* request. """ rc = [] drives = diskset.disks.keys() raiddevs = self.getRaidDevices() drives.sort() for drive in drives: disk = diskset.disks[drive] for part in partedUtils.get_raid_partitions(disk): partname = partedUtils.get_partition_name(part) used = 0 for raid in raiddevs: if raid.raidmembers: for raidmem in raid.raidmembers: tmpreq = self.getRequestByID(raidmem) if (partname == tmpreq.device): if raid.uniqueID == request.uniqueID: used = 2 else: used = 1 break if used: break size = partedUtils.getPartSizeMB(part) if not used: rc.append((partname, size, 0)) elif used == 2: rc.append((partname, size, 1)) return rc
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)
def getRequestsByDevice(self, diskset, device): """Find and return the requests on a given device (like 'hda').""" if device is None: return None drives = diskset.disks.keys() if device not in drives: return None rc = [] disk = diskset.disks[device] part = disk.next_partition() while part: dev = partedUtils.get_partition_name(part) request = self.getRequestByDeviceName(dev) if request: rc.append(request) part = disk.next_partition(part) if len(rc) > 0: return rc else: return None
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)))
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
def editOther(self, oldDevice, oldLabel, isDefault, isRoot = 0): dialog = gtk.Dialog(_("Image"), self.parent) dialog.add_button('gtk-cancel', 2) dialog.add_button('gtk-ok', 1) dialog.set_position(gtk.WIN_POS_CENTER) gui.addFrame(dialog) dialog.vbox.pack_start(gui.WrappingLabel( _("Enter a label to be displayed in the boot loader menu. The " "device (or hard drive and partition number) is the device " "from which it boots."))) spacer = gtk.Label("") spacer.set_size_request(10, 1) dialog.vbox.pack_start(spacer, False) table = gtk.Table(2, 5) table.set_row_spacings(5) table.set_col_spacings(5) label = gui.MnemonicLabel(_("_Label")) table.attach(label, 0, 1, 1, 2, gtk.FILL, 0, 10) labelEntry = gtk.Entry(32) label.set_mnemonic_widget(labelEntry) table.attach(labelEntry, 1, 2, 1, 2, gtk.FILL, 0, 10) if oldLabel: labelEntry.set_text(oldLabel) label = gui.MnemonicLabel(_("_Device")) table.attach(label, 0, 1, 2, 3, gtk.FILL, 0, 10) if not isRoot: # XXX should potentially abstract this out into a function pedparts = [] parts = [] disks = self.diskset.disks for drive in disks.keys(): pedparts.extend(partedUtils.get_all_partitions(disks[drive])) for part in pedparts: parts.append(partedUtils.get_partition_name(part)) del pedparts parts.sort() deviceCombo = datacombo.DataComboBox() defindex = 0 i = 0 for part in parts: deviceCombo.append("/dev/%s" %(part,), part) if oldDevice and oldDevice == part: defindex = i i = i + 1 deviceCombo.set_active(defindex) table.attach(deviceCombo, 1, 2, 2, 3, gtk.FILL, 0, 10) label.set_mnemonic_widget(deviceCombo) else: table.attach(gtk.Label(oldDevice), 1, 2, 2, 3, gtk.FILL, 0, 10) default = gtk.CheckButton(_("Default Boot _Target")) table.attach(default, 0, 2, 3, 4, gtk.FILL, 0, 10) if isDefault != 0: default.set_active(True) if self.numentries == 1 and oldDevice != None: default.set_sensitive(False) else: default.set_sensitive(True) dialog.vbox.pack_start(table) dialog.show_all() while 1: rc = dialog.run() # cancel if rc == 2: break label = labelEntry.get_text() if not isRoot: dev = deviceCombo.get_active_value() else: dev = oldDevice if not label: self.intf.messageWindow(_("Error"), _("You must specify a label for the " "entry"), type="warning") continue foundBad = 0 for char in self.illegalChars: if char in label: self.intf.messageWindow(_("Error"), _("Boot label contains illegal " "characters"), type="warning") foundBad = 1 break if foundBad: continue # verify that the label hasn't been used foundBad = 0 for key in self.imagelist.keys(): if dev == key: continue if self.blname == "GRUB": thisLabel = self.imagelist[key][1] else: thisLabel = self.imagelist[key][0] # if the label is the same as it used to be, they must # have changed the device which is fine if thisLabel == oldLabel: continue if thisLabel == label: self.intf.messageWindow(_("Duplicate Label"), _("This label is already in " "use for another boot entry."), type="warning") foundBad = 1 break if foundBad: continue # XXX need to do some sort of validation of the device? # they could be duplicating a device, which we don't handle if dev in self.imagelist.keys() and (not oldDevice or dev != oldDevice): self.intf.messageWindow(_("Duplicate Device"), _("This device is already being " "used for another boot entry."), type="warning") continue # if we're editing a previous, get what the old info was for # labels. otherwise, make it something safe for grub and the # device name for lilo for lack of any better ideas if oldDevice: (oldshort, oldlong, oldisroot) = self.imagelist[oldDevice] else: (oldshort, oldlong, oldisroot) = (dev, label, None) # if we're editing and the device has changed, delete the old if oldDevice and dev != oldDevice: del self.imagelist[oldDevice] # go ahead and add it if self.blname == "GRUB": self.imagelist[dev] = (oldshort, label, isRoot) else: self.imagelist[dev] = (label, oldlong, isRoot) if default.get_active(): self.defaultDev = dev # refill the os list store self.fillOSList() break dialog.destroy()
def scanForRaid(drives): """Scans for raid devices on drives. drives is a list of device names. Returns a list of (mdMinor, devices, level, totalDisks) tuples. """ raidSets = {} raidDevices = {} for d in drives: parts = [] isys.makeDevInode(d, "/tmp/" + d) try: dev = parted.PedDevice.get("/tmp/" + d) disk = parted.PedDisk.new(dev) raidParts = partedUtils.get_raid_partitions(disk) for part in raidParts: parts.append(partedUtils.get_partition_name(part)) except: pass os.remove("/tmp/" + d) for dev in parts: try: (major, minor, raidSet, level, nrDisks, totalDisks, mdMinor) =\ isys.raidsb(dev) except ValueError: # bad magic, this can't be part of our raid set log("reading raid sb failed for %s",dev) continue if raidSets.has_key(raidSet): (knownLevel, knownDisks, knownMinor, knownDevices) = \ raidSets[raidSet] if knownLevel != level or knownDisks != totalDisks or \ knownMinor != mdMinor: # Raise hell log("raid set inconsistency for md%d: " "all drives in this raid set do not " "agree on raid parameters. Skipping raid device", mdMinor) continue knownDevices.append(dev) raidSets[raidSet] = (knownLevel, knownDisks, knownMinor, knownDevices) else: raidSets[raidSet] = (level, totalDisks, mdMinor, [dev,]) if raidDevices.has_key(mdMinor): if (raidDevices[mdMinor] != raidSet): log("raid set inconsistency for md%d: " "found members of multiple raid sets " "that claim to be md%d. Using only the first " "array found.", mdMinor, mdMinor) continue else: raidDevices[mdMinor] = raidSet raidList = [] for key in raidSets.keys(): (level, totalDisks, mdMinor, devices) = raidSets[key] if len(devices) < totalDisks: log("missing components of raid device md%d. The " "raid device needs %d drive(s) and only %d (was/were) found. " "This raid device will not be started.", mdMinor, totalDisks, len(devices)) continue raidList.append((mdMinor, devices, level, totalDisks)) return raidList
def getAvailLVMPartitions(self, request, diskset): """Return a list of tuples of PV partitions which can be used. Return value is (part, size, used) where used is 0 if not, 1 if so, 2 if used for *this* request. """ rc = [] drives = diskset.disks.keys() drives.sort() volgroups = self.getLVMVGRequests() for drive in drives: disk = diskset.disks[drive] for part in partedUtils.get_lvm_partitions(disk): partname = partedUtils.get_partition_name(part) partrequest = self.getRequestByDeviceName(partname) used = 0 for volgroup in volgroups: if volgroup.physicalVolumes: if partrequest.uniqueID in volgroup.physicalVolumes: if (request and request.uniqueID and volgroup.uniqueID == request.uniqueID): used = 2 else: used = 1 if used: break size = partedUtils.getPartSizeMB(part) if used == 0: rc.append((partrequest.uniqueID, size, 0)) elif used == 2: rc.append((partrequest.uniqueID, size, 1)) # now find available RAID devices raiddev = self.getRaidRequests() if raiddev: raidcounter = 0 for dev in raiddev: used = 0 if dev.fstype is None: continue if dev.fstype.getName() != "physical volume (LVM)": continue for volgroup in volgroups: if volgroup.physicalVolumes: if dev.uniqueID in volgroup.physicalVolumes: if (request and request.uniqueID and volgroup.uniqueID == request.uniqueID): used = 2 else: used = 1 if used: break size = dev.getActualSize(self, diskset) if used == 0: rc.append((dev.uniqueID, size, 0)) elif used == 2: rc.append((dev.uniqueID, size, 1)) raidcounter = raidcounter + 1 return rc
def bootloaderSetupChoices(anaconda): if anaconda.dir == DISPATCH_BACK: return # FIXME: this is a hack... if flags.livecd: return if anaconda.id.ksdata: anaconda.id.bootloader.updateDriveList(anaconda.id.ksdata.bootloader["driveorder"]) else: anaconda.id.bootloader.updateDriveList() # iSeries bootloader on upgrades if iutil.getPPCMachine() == "iSeries" and not anaconda.id.bootloader.device: drives = anaconda.id.diskset.disks.keys() drives.sort() bootPart = None for drive in drives: disk = anaconda.id.diskset.disks[drive] part = disk.next_partition() while part: if part.is_active() and part.native_type == 0x41: bootPart = partedUtils.get_partition_name(part) break part = disk.next_partition(part) if bootPart: break if bootPart: anaconda.id.bootloader.setDevice(bootPart) dev = Device() dev.device = bootPart anaconda.id.fsset.add(FileSystemSetEntry(dev, None, fileSystemTypeGet("PPC PReP Boot"))) choices = anaconda.id.fsset.bootloaderChoices(anaconda.id.diskset, anaconda.id.bootloader) if not choices and iutil.getPPCMachine() != "iSeries": anaconda.dispatch.skipStep("instbootloader") else: anaconda.dispatch.skipStep("instbootloader", skip = 0) anaconda.id.bootloader.images.setup(anaconda.id.diskset, anaconda.id.fsset) if anaconda.id.bootloader.defaultDevice != None and choices: keys = choices.keys() # there are only two possible things that can be in the keys # mbr and boot. boot is ALWAYS present. so if the dev isn't # listed, it was mbr and we should nicely fall back to boot if anaconda.id.bootloader.defaultDevice not in keys: log.warning("MBR not suitable as boot device; installing to partition") anaconda.id.bootloader.defaultDevice = "boot" anaconda.id.bootloader.setDevice(choices[anaconda.id.bootloader.defaultDevice][0]) elif choices and iutil.isMactel() and choices.has_key("boot"): # haccckkkk anaconda.id.bootloader.setDevice(choices["boot"][0]) elif choices and choices.has_key("mbr") and not \ (choices.has_key("boot") and choices["boot"][1] == N_("RAID Device")): anaconda.id.bootloader.setDevice(choices["mbr"][0]) elif choices and choices.has_key("boot"): anaconda.id.bootloader.setDevice(choices["boot"][0]) bootDev = anaconda.id.fsset.getEntryByMountPoint("/") if not bootDev: bootDev = anaconda.id.fsset.getEntryByMountPoint("/boot") part = partedUtils.get_partition_by_name(anaconda.id.diskset.disks, bootDev.device.getDevice()) if part and partedUtils.end_sector_to_cyl(part.geom.dev, part.geom.end) >= 1024: anaconda.id.bootloader.above1024 = 1
def scanForRaid(drives): """Scans for raid devices on drives. drives is a list of device names. Returns a list of (mdMinor, devices, level, totalDisks) tuples. """ raidSets = {} raidDevices = {} encryptedDevices = partitions.Partitions.encryptedDevices for d in drives: parts = [] isys.makeDevInode(d, "/tmp/" + d) try: dev = parted.PedDevice.get("/tmp/" + d) disk = parted.PedDisk.new(dev) raidParts = partedUtils.get_raid_partitions(disk) for part in raidParts: # if the part is encrypted, add the mapped dev instead pname = partedUtils.get_partition_name(part) cryptoDev = encryptedDevices.get(pname) if cryptoDev and not cryptoDev.openDevice(): dev = cryptoDev.getDevice() else: dev = pname parts.append(dev) except: pass os.remove("/tmp/" + d) for dev in parts: try: (major, minor, raidSet, level, nrDisks, totalDisks, mdMinor) =\ isys.raidsb(dev) except ValueError: # bad magic, this can't be part of our raid set log.error("reading raid sb failed for %s",dev) continue if raidSets.has_key(raidSet): (knownLevel, knownDisks, knownMinor, knownDevices) = \ raidSets[raidSet] if knownLevel != level or knownDisks != totalDisks or \ knownMinor != mdMinor: # Raise hell log.error("raid set inconsistency for md%d: " "all drives in this raid set do not " "agree on raid parameters. Skipping raid device", mdMinor) continue knownDevices.append(dev) raidSets[raidSet] = (knownLevel, knownDisks, knownMinor, knownDevices) else: raidSets[raidSet] = (level, totalDisks, mdMinor, [dev,]) if raidDevices.has_key(mdMinor): if (raidDevices[mdMinor] != raidSet): log.error("raid set inconsistency for md%d: " "found members of multiple raid sets " "that claim to be md%d. Using only the first " "array found.", mdMinor, mdMinor) continue else: raidDevices[mdMinor] = raidSet raidList = [] for key in raidSets.keys(): (level, totalDisks, mdMinor, devices) = raidSets[key] if len(devices) < totalDisks: log.warning("missing components of raid device md%d. The " "raid device needs %d drive(s) and only %d (was/were) " "found. This raid device will not be started.", mdMinor, totalDisks, len(devices)) continue raidList.append((mdMinor, devices, level, totalDisks)) return raidList
def bootloaderSetupChoices(anaconda): if anaconda.dir == DISPATCH_BACK: return # FIXME: this is a hack... if flags.livecd: return if anaconda.id.ksdata: anaconda.id.bootloader.updateDriveList( anaconda.id.ksdata.bootloader["driveorder"]) else: anaconda.id.bootloader.updateDriveList() # iSeries bootloader on upgrades if iutil.getPPCMachine( ) == "iSeries" and not anaconda.id.bootloader.device: drives = anaconda.id.diskset.disks.keys() drives.sort() bootPart = None for drive in drives: disk = anaconda.id.diskset.disks[drive] part = disk.next_partition() while part: if part.is_active() and part.native_type == 0x41: bootPart = partedUtils.get_partition_name(part) break part = disk.next_partition(part) if bootPart: break if bootPart: anaconda.id.bootloader.setDevice(bootPart) dev = Device() dev.device = bootPart anaconda.id.fsset.add( FileSystemSetEntry(dev, None, fileSystemTypeGet("PPC PReP Boot"))) choices = anaconda.id.fsset.bootloaderChoices(anaconda.id.diskset, anaconda.id.bootloader) if not choices and iutil.getPPCMachine() != "iSeries": anaconda.dispatch.skipStep("instbootloader") else: anaconda.dispatch.skipStep("instbootloader", skip=0) anaconda.id.bootloader.images.setup(anaconda.id.diskset, anaconda.id.fsset) if anaconda.id.bootloader.defaultDevice != None and choices: keys = choices.keys() # there are only two possible things that can be in the keys # mbr and boot. boot is ALWAYS present. so if the dev isn't # listed, it was mbr and we should nicely fall back to boot if anaconda.id.bootloader.defaultDevice not in keys: log.warning( "MBR not suitable as boot device; installing to partition") anaconda.id.bootloader.defaultDevice = "boot" anaconda.id.bootloader.setDevice( choices[anaconda.id.bootloader.defaultDevice][0]) elif choices and iutil.isMactel() and choices.has_key("boot"): # haccckkkk anaconda.id.bootloader.setDevice(choices["boot"][0]) elif choices and choices.has_key("mbr") and not \ (choices.has_key("boot") and choices["boot"][1] == N_("RAID Device")): anaconda.id.bootloader.setDevice(choices["mbr"][0]) elif choices and choices.has_key("boot"): anaconda.id.bootloader.setDevice(choices["boot"][0]) bootDev = anaconda.id.fsset.getEntryByMountPoint("/") if not bootDev: bootDev = anaconda.id.fsset.getEntryByMountPoint("/boot") part = partedUtils.get_partition_by_name(anaconda.id.diskset.disks, bootDev.device.getDevice()) if part and partedUtils.end_sector_to_cyl(part.geom.dev, part.geom.end) >= 1024: anaconda.id.bootloader.above1024 = 1
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)))
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