return [VolumeGroup(**vg) for vg in vgs if vg['vg_name'] and vg['vg_name'].startswith(name_prefix)]
+def scan():
+ """
+ Scan the system for lvs and vgs. Sometimes
+ the cache can become stale when an lv or vg
+ is deleted. This will rescan the system
+ and ensure that `lvs` and `vgs` return
+ the actual state of the system.
+ """
+ process.run(['lvscan', '--cache'])
+ process.run(['vgscan', '--cache'])
+
+
#################################
#
# Code for LVM Logical Volumes
mlogger.info('Removing LV because --destroy was given: %s',
device.abspath)
api.remove_lv(device.abspath)
+
+ # scan the system for lvs and vgs after deleting.
+ # this avoids and issue where stale lvm cache can
+ # show deleted lvs and vgs as available.
+ api.scan()
elif lv:
# just remove all lvm metadata, leaving the LV around
lv.clear_tags()