4 from textwrap
import dedent
5 from ceph_volume
import conf
6 from ceph_volume
.util
import encryption
, system
7 from ceph_volume
.api
.lvm
import get_lvs_by_tag
9 logger
= logging
.getLogger(__name__
)
12 def deactivate_osd(osd_id
=None, osd_uuid
=None):
15 if osd_uuid
is not None:
16 lvs
= get_lvs_by_tag('ceph.osd_fsid={}'.format(osd_uuid
))
17 osd_id
= next(lv
.tags
['ceph.osd_id'] for lv
in lvs
)
19 lvs
= get_lvs_by_tag('ceph.osd_id={}'.format(osd_id
))
21 data_lv
= next(lv
for lv
in lvs
if lv
.tags
['ceph.type'] in ['data', 'block'])
23 conf
.cluster
= data_lv
.tags
['ceph.cluster_name']
24 logger
.debug('Found cluster name {}'.format(conf
.cluster
))
26 tmpfs_path
= '/var/lib/ceph/osd/{}-{}'.format(conf
.cluster
, osd_id
)
27 system
.unmount_tmpfs(tmpfs_path
)
30 if lv
.tags
.get('ceph.encrypted', '0') == '1':
31 encryption
.dmcrypt_close(lv
.lv_uuid
)
34 class Deactivate(object):
36 help = 'Deactivate OSDs'
38 def deactivate(self
, args
=None):
42 deactivate_osd(self
.args
.osd_id
, self
.args
.osd_uuid
)
44 logger
.error(('No data or block LV found for OSD'
45 '{}').format(self
.args
.osd_id
))
48 def __init__(self
, argv
):
52 sub_command_help
= dedent("""
53 Deactivate unmounts and OSDs tmpfs and closes any crypt devices.
55 ceph-volume lvm deactivate {ID} {FSID}
58 parser
= argparse
.ArgumentParser(
59 prog
='ceph-volume lvm deactivate',
60 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
61 description
=sub_command_help
,
67 help='The ID of the OSD'
72 help='The UUID of the OSD, similar to a SHA1, takes precedence over osd_id'
74 # parser.add_argument(
76 # action='store_true',
77 # help='Deactivate all OSD volumes found in the system',
79 if len(self
.argv
) == 0:
80 print(sub_command_help
)
82 args
= parser
.parse_args(self
.argv
)
83 # Default to bluestore here since defaulting it in add_argument may
84 # cause both to be True
85 if not args
.osd_id
and not args
.osd_uuid
:
86 raise ValueError(('Can not identify OSD, pass either all or'
87 'osd_id or osd_uuid'))