[PATCH 08/13] Allow passing size=None to device factories for unbounded growth.

David Lehman dlehman at redhat.com
Fri Mar 1 22:13:26 UTC 2013


Related: rhbz#906906
Related: rhbz#906908
---
 blivet/devicefactory.py | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py
index 3982570..466fec3 100644
--- a/blivet/devicefactory.py
+++ b/blivet/devicefactory.py
@@ -150,6 +150,18 @@ class DeviceFactory(object):
 
         return size
 
+    def handle_no_size(self, device=None, container=None):
+        """ Set device size so that it grows to the largest size possible. """
+        if self.size is not None:
+            return
+
+        free_info = self.storage.getFreeSpace(disks=self.disks)
+        free = sum(d[0] for d in free_info.values())
+        self.size = int(free.convertTo(spec="mb"))
+
+        if device:
+            self.size += device.size
+
     @property
     def device_size(self):
         """ The total disk space required for this device. """
@@ -451,6 +463,9 @@ class DeviceFactory(object):
 
         container = self.get_container(device=device, name=container_name)
 
+        # handle special size value of None, which means to grow unbounded
+        self.handle_no_size(device=device, container=container)
+
         # TODO: striping, mirroring, &c
         # TODO: non-partition members (pv-on-md)
 
@@ -753,6 +768,20 @@ class LVMFactory(DeviceFactory):
     encrypt_members = True
     encrypt_leaves = False
 
+    def handle_no_size(self, device=None, container=None):
+        """ Set device size so that it grows to the largest size possible. """
+        if self.size is not None:
+            return
+
+        if container and container.exists:
+            self.size = container.freeSpace
+
+            if device:
+                self.size += device.size
+        else:
+            super(LVMFactory, self).handle_no_size(device=device,
+                                                   container=container)
+
     @property
     def device_size(self):
         size_func_kwargs = {}
-- 
1.8.1



More information about the anaconda-patches mailing list