From 968941a12a8fd59fbaf97687ea5de45979a3cd80 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 22 Feb 2013 12:11:45 +0100 Subject: [PATCH 08/13] Allow passing size=None to device factories for unbounded growth. 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