[PATCH 3/5] Change signature of DiskLabel.addPartition to be more useful.
David Lehman
dlehman at redhat.com
Thu Oct 9 21:53:55 UTC 2014
The new method accepts start sector, end sector, and partition type.
The previous method required you to pass in a parted.Partition instance.
It did not simply add that parted.Partition instance. Instead, it created
a new parted.Partition instance based on the one passed in and added that
to the parted.Disk.
---
blivet/devices/partition.py | 9 +++++++--
blivet/formats/disklabel.py | 42 ++++++++++++++++++++----------------------
2 files changed, 27 insertions(+), 24 deletions(-)
diff --git a/blivet/devices/partition.py b/blivet/devices/partition.py
index 7aa6f8c..6ad107a 100644
--- a/blivet/devices/partition.py
+++ b/blivet/devices/partition.py
@@ -528,7 +528,9 @@ class PartitionDevice(StorageDevice):
def _create(self):
""" Create the device. """
log_method_call(self, self.name, status=self.status)
- self.disk.format.addPartition(self.partedPartition)
+ self.disk.format.addPartition(self.partedPartition.geometry.start,
+ self.partedPartition.geometry.end,
+ self.partedPartition.type)
self._wipe()
try:
@@ -621,7 +623,10 @@ class PartitionDevice(StorageDevice):
try:
self.disk.originalFormat.commit()
except errors.DiskLabelCommitError:
- self.disk.originalFormat.addPartition(self.partedPartition)
+ self.disk.originalFormat.addPartition(
+ self.partedPartition.geometry.start,
+ self.partedPartition.geometry.end,
+ self.partedPartition.type)
self.partedPartition = self.disk.originalFormat.partedDisk.getPartitionByPath(self.path)
raise
diff --git a/blivet/formats/disklabel.py b/blivet/formats/disklabel.py
index e80b1e4..d4d7ae7 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -285,28 +285,32 @@ class DiskLabel(DeviceFormat):
else:
self.updateOrigPartedDisk()
- def addPartition(self, partition, constraint=None):
+ def addPartition(self, start, end, ptype=None):
""" Add a partition to the disklabel.
- :param partition: partition from which to get geom, type (required)
- :type partition: parted.Partition.
- :keyword constraint: constraint to use
- :type constraint: parted.Constraint.
+ :param int start: start sector
+ :param int end: end sector
+ :param ptype: partition type or None
+ :type ptype: int (parted partition type constant) or NoneType
- .. note::
-
- This does not add the :class:`parted.Partition` instance you
- pass in. The geometry and type are taken from that instance and
- used to create a new :class:`parted.Partition` to add to the
- disklabel.
+ Partition type will default to either PARTITION_NORMAL or
+ PARTITION_LOGICAL, depending on whether the start sector is within
+ an extended partition.
"""
- geometry = partition.geometry
- if not constraint:
- constraint = parted.Constraint(exactGeom=geometry)
+ if ptype is None:
+ extended = self.extendedPartition
+ if extended and extended.geometry.contains(start):
+ ptype = parted.PARTITION_LOGICAL
+ else:
+ ptype = parted.PARTITION_NORMAL
+ geometry = parted.Geometry(device=self.partedDevice,
+ start=start, end=end)
new_partition = parted.Partition(disk=self.partedDisk,
- type=partition.type,
+ type=ptype,
geometry=geometry)
+
+ constraint = parted.Constraint(exactGeom=geometry)
self.partedDisk.addPartition(partition=new_partition,
constraint=constraint)
@@ -314,13 +318,7 @@ class DiskLabel(DeviceFormat):
""" Remove a partition from the disklabel.
:param partition: the partition to remove
- :type partition: parted.Partition.
-
- .. note::
-
- Unlike :meth:`addPartition`, the actual partition instance
- passed is what will be removed from the disklabel.
-
+ :type partition: :class:`parted.Partition`
"""
self.partedDisk.removePartition(partition)
--
1.9.3
More information about the anaconda-patches
mailing list