]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/ceph-volume/ceph_volume/devices/lvm/zap.py
update sources to 12.2.10
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / zap.py
index 90c5447c0e1e8959d5c27e21ef2a4777eac8da67..8e0e3a3c5e974af2b24fcf636268f8a18d620783 100644 (file)
@@ -100,15 +100,27 @@ class Zap(object):
                 for vg_name in vgs:
                     mlogger.info("Destroying volume group %s because --destroy was given", vg_name)
                     api.remove_vg(vg_name)
-                mlogger.info("Destroying physical volume %s because --destroy was given", device)
-                api.remove_pv(device)
+                if not lv:
+                    mlogger.info("Destroying physical volume %s because --destroy was given", device)
+                    api.remove_pv(device)
 
             wipefs(path)
             zap_data(path)
 
             if lv and not pvs:
-                # remove all lvm metadata
-                lv.clear_tags()
+                if args.destroy:
+                    lvs = api.Volumes()
+                    lvs.filter(vg_name=lv.vg_name)
+                    if len(lvs) <= 1:
+                        mlogger.info('Only 1 LV left in VG, will proceed to destroy volume group %s', lv.vg_name)
+                        api.remove_vg(lv.vg_name)
+                    else:
+                        mlogger.info('More than 1 LV left in VG, will proceed to destroy LV only')
+                        mlogger.info('Removing LV because --destroy was given: %s', lv)
+                        api.remove_lv(lv)
+                else:
+                    # just remove all lvm metadata, leaving the LV around
+                    lv.clear_tags()
 
         terminal.success("Zapping successful for: %s" % ", ".join(args.devices))