4 from textwrap
import dedent
6 from ceph_volume
import decorators
, terminal
, process
7 from ceph_volume
.api
import lvm
as api
8 from ceph_volume
.util
import system
10 logger
= logging
.getLogger(__name__
)
11 mlogger
= terminal
.MultiLogger(__name__
)
16 Removes the filesystem from an lv or partition.
27 Clears all data from the given path. Path should be
28 an absolute path to an lv or partition.
30 10M of data is written to the path to make sure that
31 there is no trace left of any previous Filesystem.
36 'of={path}'.format(path
=path
),
44 help = 'Removes all data and filesystems from a logical volume or partition.'
46 def __init__(self
, argv
):
49 @decorators.needs_root
52 lv
= api
.get_lv_from_argument(device
)
54 # we are zapping a logical volume
57 # we are zapping a partition
58 #TODO: ensure device is a partition
61 mlogger
.info("Zapping: %s", path
)
63 # check if there was a pv created with the
65 pv
= api
.get_pv(pv_name
=device
)
68 lv
= api
.get_lv(vg_name
=vg_name
)
71 osd_path
= "/var/lib/ceph/osd/{}-{}".format(lv
.tags
['ceph.cluster_name'], lv
.tags
['ceph.osd_id'])
72 if system
.path_is_mounted(osd_path
):
73 mlogger
.info("Unmounting %s", osd_path
)
74 system
.unmount(osd_path
)
76 if args
.destroy
and pv
:
77 logger
.info("Found a physical volume created from %s, will destroy all it's vgs and lvs", device
)
79 mlogger
.info("Destroying volume group %s because --destroy was given", vg_name
)
80 api
.remove_vg(vg_name
)
81 mlogger
.info("Destroying physical volume %s because --destroy was given", device
)
83 elif args
.destroy
and not pv
:
84 mlogger
.info("Skipping --destroy because no associated physical volumes are found for %s", device
)
90 # remove all lvm metadata
93 terminal
.success("Zapping successful for: %s" % path
)
96 sub_command_help
= dedent("""
97 Zaps the given logical volume, raw device or partition for reuse by ceph-volume.
98 If given a path to a logical volume it must be in the format of vg/lv. Any
99 filesystems present on the given device, vg/lv, or partition will be removed and
100 all data will be purged.
102 If the logical volume, raw device or partition is being used for any ceph related
103 mount points they will be unmounted.
105 However, the lv or partition will be kept intact.
107 Example calls for supported scenarios:
109 Zapping a logical volume:
111 ceph-volume lvm zap {vg name/lv name}
115 ceph-volume lvm zap /dev/sdc1
117 If the --destroy flag is given and you are zapping a raw device or partition
118 then all vgs and lvs that exist on that raw device or partition will be destroyed.
120 This is especially useful if a raw device or partition was used by ceph-volume lvm create
121 or ceph-volume lvm prepare commands previously and now you want to reuse that device.
125 ceph-volume lvm zap /dev/sda --destroy
127 If the --destroy flag is given and you are zapping an lv then the lv is still
128 kept intact for reuse.
131 parser
= argparse
.ArgumentParser(
132 prog
='ceph-volume lvm zap',
133 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
134 description
=sub_command_help
,
141 help='Path to an lv (as vg/lv), partition (as /dev/sda1) or device (as /dev/sda)'
147 help='Destroy all volume groups and logical volumes if you are zapping a raw device or partition',
149 if len(self
.argv
) == 0:
150 print(sub_command_help
)
152 args
= parser
.parse_args(self
.argv
)