[PATCH 2/3] Move implicit partition creation into a separate function

Vratislav Podzimek vpodzime at redhat.com
Wed Sep 17 07:14:17 UTC 2014


This way it may be used by other functions.

Related: rhbz#978266
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
 blivet/partitioning.py | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/blivet/partitioning.py b/blivet/partitioning.py
index dd60bf4..9e45c1a 100644
--- a/blivet/partitioning.py
+++ b/blivet/partitioning.py
@@ -69,6 +69,31 @@ def _getCandidateDisks(storage):
 
     return disks
 
+def _createImplicitPartition(storage, size=None, grow=True):
+    if storage.encryptedAutoPart:
+        fmt_type = "luks"
+        fmt_args = {"passphrase": storage.encryptionPassphrase,
+                    "cipher": storage.encryptionCipher,
+                    "escrow_cert": storage.autoPartEscrowCert,
+                    "add_backup_passphrase": storage.autoPartAddBackupPassphrase}
+    else:
+        if storage.autoPartType in (AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP):
+            fmt_type = "lvmpv"
+        else:
+            fmt_type = "btrfs"
+        fmt_args = {}
+
+    extra = {}
+    if size:
+        extra["size"] = size
+
+    part = storage.newPartition(fmt_type=fmt_type,
+                                fmt_args=fmt_args,
+                                grow=grow,
+                                **extra)
+    storage.createDevice(part)
+    return part
+
 def _scheduleImplicitPartitions(storage, disks):
     """ Schedule creation of a lvm/btrfs member partitions for autopart.
 
@@ -90,24 +115,7 @@ def _scheduleImplicitPartitions(storage, disks):
         return devs
 
     for disk in disks:
-        if storage.encryptedAutoPart:
-            fmt_type = "luks"
-            fmt_args = {"passphrase": storage.encryptionPassphrase,
-                        "cipher": storage.encryptionCipher,
-                        "escrow_cert": storage.autoPartEscrowCert,
-                        "add_backup_passphrase": storage.autoPartAddBackupPassphrase}
-        else:
-            if storage.autoPartType in (AUTOPART_TYPE_LVM, AUTOPART_TYPE_LVM_THINP):
-                fmt_type = "lvmpv"
-            else:
-                fmt_type = "btrfs"
-            fmt_args = {}
-        part = storage.newPartition(fmt_type=fmt_type,
-                                                fmt_args=fmt_args,
-                                                grow=True,
-                                                parents=[disk])
-        storage.createDevice(part)
-        devs.append(part)
+        devs.append(_createImplicitPartition(storage))
 
     return devs
 
-- 
1.9.3



More information about the anaconda-patches mailing list