[PATCH 1/7] Add encryption support to the device factory classes.

David Lehman dlehman at redhat.com
Thu Oct 4 14:59:15 UTC 2012


---
 pyanaconda/storage/__init__.py |   24 ++++++++++++++++++++++--
 1 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/pyanaconda/storage/__init__.py b/pyanaconda/storage/__init__.py
index 4cfbc80..0a7a8e5 100644
--- a/pyanaconda/storage/__init__.py
+++ b/pyanaconda/storage/__init__.py
@@ -1865,7 +1865,7 @@ class Storage(object):
         # set up new members as needed to accommodate the device
         new_members = []
         for disk in add_disks:
-            if factory.encrypted:
+            if factory.encrypted and factory.encrypt_members:
                 luks_format = factory.member_format
                 member_format = "luks"
             else:
@@ -1879,7 +1879,7 @@ class Storage(object):
                 continue
 
             self.createDevice(member)
-            if factory.encrypted:
+            if factory.encrypted and factory.encrypt_members:
                 fmt = getFormat(luks_format)
                 member = LUKSDevice("luks-%s" % member.name,
                                     parents=[member], format=fmt)
@@ -2104,6 +2104,14 @@ class Storage(object):
                 raise(e)
         elif factory.new_device_attr:
             log.debug("creating new device")
+            if factory.encrypted and factory.encrypt_leaves:
+                luks_fmt_type = fstype
+                luks_fmt_args = fmt_args
+                luks_mountpoint = mountpoint
+                fstype = "luks"
+                mountpoint = None
+                fmt_args = {}
+
             try:
                 device = factory.new_device(parents=parents,
                                             size=size,
@@ -2154,6 +2162,14 @@ class Storage(object):
                 self.__cleanUpMemberDevices(members)
                 raise
 
+            if factory.encrypted and factory.encrypt_leaves:
+                fmt = getFormat(luks_fmt_type,
+                                mountpoint=luks_mountpoint,
+                                **luks_fmt_args)
+                luks_device = LUKSDevice("luks-" + device.name,
+                                         parents=[device], format=fmt)
+                self.createDevice(luks_device)
+
     def copy(self):
         new = copy.deepcopy(self)
         # go through and re-get partedPartitions from the disks since they
@@ -3126,6 +3142,8 @@ class DeviceFactory(object):
     new_container_attr = None   # name of Storage method to create a container
     new_device_attr = None      # name of Storage method to create a device
     container_list_attr = None  # name of Storage attribute to list containers
+    encrypt_members = False
+    encrypt_leaves = True
 
     def __init__(self, storage, size, disks, raid_level, encrypted):
         self.storage = storage          # the Storage instance
@@ -3219,6 +3237,8 @@ class BTRFSFactory(DeviceFactory):
     new_container_attr = "newBTRFS"
     new_device_attr = "newBTRFSSubVolume"
     container_list_attr = "btrfsVolumes"
+    encrypt_members = True
+    encrypt_leaves = False
 
     def __init__(self, storage, size, disks, raid_level, encrypted):
         super(BTRFSFactory, self).__init__(storage, size, disks, raid_level,
-- 
1.7.7.6



More information about the anaconda-patches mailing list