diff options
Diffstat (limited to 'storage/devices.py')
-rw-r--r-- | storage/devices.py | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/storage/devices.py b/storage/devices.py index 3439e8663..2d6a2942b 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -235,7 +235,7 @@ class Device(object): """ new = self.__class__.__new__(self.__class__) memo[id(self)] = new - shallow_copy_attrs = ('partedDisk', '_partedDevice', + shallow_copy_attrs = ('_partedDisk', '_partedDevice', '_partedPartition', '_origPartedDisk', '_raidSet') for (attr, value) in self.__dict__.items(): @@ -722,22 +722,39 @@ class DiskDevice(StorageDevice): StorageDevice.__init__(self, device, format=format, size=size, major=major, minor=minor, exists=True, sysfsPath=sysfsPath, parents=parents) + self._partedDisk = None + self._initlabel = initlabel + self._initcb = initcb - self.partedDisk = None + # We save the actual state of the disk here. Before the first + # modification (addPartition or removePartition) to the partition + # table we reset self.partedPartition to this state so we can + # perform the modifications one at a time. + if self.partedDisk: + self._origPartedDisk = self.partedDisk.duplicate() + else: + self._origPartedDisk = None + + + @property + def partedDisk(self): + if self._partedDisk: + return self._partedDisk log.debug("looking up parted Device: %s" % self.path) if self.partedDevice: log.debug("creating parted Disk: %s" % self.path) - if initlabel: - self.partedDisk = self.freshPartedDisk() + if self._initlabel: + self._partedDisk = self.freshPartedDisk() else: try: - self.partedDisk = parted.Disk(device=self.partedDevice) + self._partedDisk = parted.Disk(device=self.partedDevice) except _ped.DiskLabelException: # if we have a cb function use it. else an error. - if initcb is not None and initcb(): - self.partedDisk = parted.freshDisk(device=self.partedDevice, \ + if self._initcb is not None and self._initcb(): + self._partedDisk = parted.freshDisk( \ + device=self.partedDevice, \ ty = platform.getPlatform(None).diskType) else: raise DeviceUserDeniedFormatError("User prefered to not format.") @@ -745,21 +762,15 @@ class DiskDevice(StorageDevice): # When the device has no partition table but it has a FS, it # will be created with label type loop. Treat the same as if # the device had no label (cause it really doesn't). - if self.partedDisk.type == "loop": - if initcb is not None and initcb(): - self.partedDisk = parted.freshDisk(device=self.partedDevice, \ + if self._partedDisk.type == "loop": + if self._initcb is not None and self._initcb(): + self._partedDisk = parted.freshDisk( \ + device=self.partedDevice, \ ty = platform.getPlatform(None).diskType) else: raise DeviceUserDeniedFormatError("User prefered to not format.") - # We save the actual state of the disk here. Before the first - # modification (addPartition or removePartition) to the partition - # table we reset self.partedPartition to this state so we can - # perform the modifications one at a time. - if self.partedDisk: - self._origPartedDisk = self.partedDisk.duplicate() - else: - self._origPartedDisk = None + return self._partedDisk def __str__(self): s = StorageDevice.__str__(self) @@ -795,7 +806,7 @@ class DiskDevice(StorageDevice): def resetPartedDisk(self): """ Reset parted.Disk to reflect the actual layout of the disk. """ log_method_call(self, self.name) - self.partedDisk = self._origPartedDisk + self._partedDisk = self._origPartedDisk def removePartition(self, device): log_method_call(self, self.name, part=device.name) |