]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume: adds the --destroy flag to ceph-volume lvm zap
authorAndrew Schoen <aschoen@redhat.com>
Wed, 17 Jan 2018 21:11:19 +0000 (15:11 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Thu, 18 Jan 2018 17:12:30 +0000 (11:12 -0600)
If you use the --destroy flag and are zapping a raw device
or parition then zap will destroy any vgs or lvs it finds on that
device.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
src/ceph-volume/ceph_volume/devices/lvm/zap.py

index 4b19efebab46cd683db1d12bd6c48bf1def948a7..537c0cddda27083aeaa2ba847a0435935d916b1b 100644 (file)
@@ -59,6 +59,17 @@ class Zap(object):
         logger.info("Zapping: %s", path)
         terminal.write("Zapping: %s" % path)
 
+        if args.destroy and not lv:
+            # check if there was a pv created with the
+            # name of device
+            pv = api.PVolumes().get(pv_name=device)
+            if pv:
+                logger.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device)
+                vg_name = pv.vg_name
+                logger.info("Destroying volume group %s because --destroy was given", vg_name)
+                terminal.write("Destroying volume group %s because --destroy was given" % vg_name)
+                api.remove_vg(vg_name)
+
         wipefs(path)
         zap_data(path)
 
@@ -70,9 +81,10 @@ class Zap(object):
 
     def main(self):
         sub_command_help = dedent("""
-        Zaps the given logical volume or partition. If given a path to a logical
-        volume it must be in the format of vg/lv. Any filesystems present
-        on the given lv or partition will be removed and all data will be purged.
+        Zaps the given logical volume, raw device or partition for reuse by ceph-volume.
+        If given a path to a logical volume it must be in the format of vg/lv. Any
+        filesystems present on the given device/lv/partition will be removed and
+        all data will be purged.
 
         However, the lv or partition will be kept intact.
 
@@ -86,6 +98,20 @@ class Zap(object):
 
               ceph-volume lvm zap /dev/sdc1
 
+        If the --destroy flag is given and you are zapping a raw device or partition
+        then all vgs and lvs that exist on that raw device or parition will be destroyed.
+
+        This is especially useful if you've give that raw device or partition to the
+        ceph-volume lvm create or ceph-volume lvm prepare commands previously and now want to
+        reuse that device.
+
+        For example:
+
+          ceph-volume lvm zap /dev/sda --destroy
+
+        If the --destroy flag is given and you are zapping an lv then the lv is still
+        kept intact for reuse.
+
         """)
         parser = argparse.ArgumentParser(
             prog='ceph-volume lvm zap',
@@ -97,7 +123,13 @@ class Zap(object):
             'device',
             metavar='DEVICE',
             nargs='?',
-            help='Path to an lv (as vg/lv) or to a partition like /dev/sda1'
+            help='Path to an lv (as vg/lv), partition (as /dev/sda1) or device (as /dev/sda)'
+        )
+        parser.add_argument(
+            '--destroy',
+            action='store_true',
+            default=False,
+            help='Destroy all volume groups and logical volumes if you are zapping a raw device or partition',
         )
         if len(self.argv) == 0:
             print(sub_command_help)