From 587b45be09edfc28809d94e489dd7c0c591d9408 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 6 Mar 2015 12:33:26 -0600 Subject: [PATCH 09/19] Split canceling of actions by disk into a new method. --- blivet/devicetree.py | 53 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/blivet/devicetree.py b/blivet/devicetree.py index f5a2f2d..2b97e0d 100644 --- a/blivet/devicetree.py +++ b/blivet/devicetree.py @@ -365,6 +365,47 @@ class DeviceTree(object): return dependents + def getDiskActions(self, disks): + """ Return a list of actions related to the specified disk. + + :keyword disk: list of disks + :type disk: list of :class:`~.devices.StorageDevices` + :returns: list of related actions + :rtype: list of :class:`~.deviceaction.DeviceAction` + + This includes all actions on the specified disks, plus all actions + on disks that are in any way connected to the specified disk via + container devices. + """ + related_disks = set() + for action in self.actions: + if any(action.device.dependsOn(d) for d in disks): + related_disks.update(action.device.disks) + + # now related_disks could be a superset of disks, so go through and + # build a list of actions related to any disk in related_disks + # Note that this list preserves the ordering of the action list. + related_actions = [a for a in self.actions + if set(a.device.disks).intersection(related_disks)] + return related_actions + + def cancelDiskActions(self, disks): + """ Cancel all actions related to the specified disk. + + :keyword disk: list of disks + :type disk: list of :class:`~.devices.StorageDevices` + + This includes actions related directly and indirectly (via container + membership, for example). + """ + actions = self.getDiskActions(disks) + for action in reversed(actions): + self.cancelAction(action) + + def cancelAllActions(self): + for action in reversed(list(self.actions)): + self.cancelAction(action) + def hide(self, device): """ Hide the specified device. @@ -408,17 +449,7 @@ class DeviceTree(object): if device.isDisk: # Cancel all actions on this disk and any disk related by way of an # aggregate/container device (eg: lvm volume group). - disks = [device] - related_actions = [a for a in self.actions - if a.device.dependsOn(device)] - for related_device in (a.device for a in related_actions): - disks.extend(related_device.disks) - - disks = set(disks) - cancel = [a for a in self.actions - if set(a.device.disks).intersection(disks)] - for action in reversed(cancel): - self.cancelAction(action) + self.cancelDiskActions([device]) for d in self.getChildren(device): self.hide(d) -- 1.9.3