Relax constraints on what can be deleted slightly

Allow a compound device (i.e. VG or raid) to be deleted if none of its
partitions are mounted or part of another device.

This makes it a lot easier to remove existing devices that probing for
existing partitions / compound devices can find.
This commit is contained in:
Michael Hudson-Doyle 2019-04-01 20:46:46 +13:00
parent 4794a68306
commit f29ee64f76
1 changed files with 29 additions and 19 deletions

View File

@ -356,6 +356,35 @@ class _Device(_Formattable, ABC):
return True
return False
@property
def _can_DELETE(self):
mounted_partitions = 0
for p in self._partitions:
if p.fs() and p.fs().mount():
mounted_partitions += 1
elif p.constructed_device():
cd = p.constructed_device()
return _(
"Cannot delete {selflabel} as partition {partnum} is part "
"of the {cdtype} {cdname}.").format(
selflabel=self.label,
partnum=p._number,
cdtype=cd.desc(),
cdname=cd.label,
)
if mounted_partitions > 1:
return _(
"Cannot delete {selflabel} because it has {count} mounted "
"partitions.").format(
selflabel=self.label,
count=mounted_partitions)
elif mounted_partitions == 1:
return _(
"Cannot delete {selflabel} because it has 1 mounted partition."
).format(selflabel=self.label)
else:
return _generic_can_DELETE(self)
@attr.s(cmp=False)
class Disk(_Device):
@ -574,15 +603,6 @@ class Raid(_Device):
self._constructed_device is None)
_can_REMOVE = property(_generic_can_REMOVE)
@property
def _can_DELETE(self):
if len(self._partitions) > 0:
return _(
"Cannot delete {selflabel} because it has partitions.").format(
selflabel=self.label)
else:
return _generic_can_DELETE(self)
@property
def ok_for_raid(self):
if self._fs is not None:
@ -647,16 +667,6 @@ class LVM_VolGroup(_Device):
_can_CREATE_LV = Disk._can_PARTITION
@property
def _can_DELETE(self):
if len(self._partitions) > 0:
return _(
"Cannot delete {selflabel} because it has logical "
"volumes.").format(
selflabel=self.label)
else:
return _generic_can_DELETE(self)
ok_for_raid = False
ok_for_lvm_vg = False