From 54298e5632f4a9cc19bd8fec0dd0fe420a3a7452 Mon Sep 17 00:00:00 2001
From: David Lehman <dlehman@redhat.com>
Date: Thu, 17 Apr 2014 12:40:12 -0500
Subject: [PATCH 02/12] Change signature of DiskLabel.addPartition to be more
 useful.

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.py           |  9 +++++++--
 blivet/formats/disklabel.py | 35 +++++++++++------------------------
 2 files changed, 18 insertions(+), 26 deletions(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index 05f9f92..e6de03d 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -1702,7 +1702,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:
@@ -1795,7 +1797,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 9dc0b5d..06e486a 100644
--- a/blivet/formats/disklabel.py
+++ b/blivet/formats/disklabel.py
@@ -285,28 +285,21 @@ class DiskLabel(DeviceFormat):
         else:
             self.updateOrigPartedDisk()
 
-    def addPartition(self, partition, constraint=None):
+    def addPartition(self, start, end, ptype):
         """ 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.
-
-            .. 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.
+            :param int start: start sector
+            :param int end: end sector
+            :param ptype: partition type
+            :type ptype: int (parted partition type constant)
         """
-        geometry = partition.geometry
-        if not constraint:
-            constraint = parted.Constraint(exactGeom=geometry)
-
+        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 +307,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

