]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/lvm/deactivate.py
add stop-gap to fix compat with CPUs not supporting SSE 4.1
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / lvm / deactivate.py
1 import argparse
2 import logging
3 import sys
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
8
9 logger = logging.getLogger(__name__)
10
11
12 def deactivate_osd(osd_id=None, osd_uuid=None):
13
14 lvs = []
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)
18 else:
19 lvs = get_lvs_by_tag('ceph.osd_id={}'.format(osd_id))
20
21 data_lv = next(lv for lv in lvs if lv.tags['ceph.type'] in ['data', 'block'])
22
23 conf.cluster = data_lv.tags['ceph.cluster_name']
24 logger.debug('Found cluster name {}'.format(conf.cluster))
25
26 tmpfs_path = '/var/lib/ceph/osd/{}-{}'.format(conf.cluster, osd_id)
27 system.unmount_tmpfs(tmpfs_path)
28
29 for lv in lvs:
30 if lv.tags.get('ceph.encrypted', '0') == '1':
31 encryption.dmcrypt_close(lv.lv_uuid)
32
33
34 class Deactivate(object):
35
36 help = 'Deactivate OSDs'
37
38 def deactivate(self, args=None):
39 if args:
40 self.args = args
41 try:
42 deactivate_osd(self.args.osd_id, self.args.osd_uuid)
43 except StopIteration:
44 logger.error(('No data or block LV found for OSD'
45 '{}').format(self.args.osd_id))
46 sys.exit(1)
47
48 def __init__(self, argv):
49 self.argv = argv
50
51 def main(self):
52 sub_command_help = dedent("""
53 Deactivate unmounts and OSDs tmpfs and closes any crypt devices.
54
55 ceph-volume lvm deactivate {ID} {FSID}
56
57 """)
58 parser = argparse.ArgumentParser(
59 prog='ceph-volume lvm deactivate',
60 formatter_class=argparse.RawDescriptionHelpFormatter,
61 description=sub_command_help,
62 )
63
64 parser.add_argument(
65 'osd_id',
66 nargs='?',
67 help='The ID of the OSD'
68 )
69 parser.add_argument(
70 'osd_uuid',
71 nargs='?',
72 help='The UUID of the OSD, similar to a SHA1, takes precedence over osd_id'
73 )
74 # parser.add_argument(
75 # '--all',
76 # action='store_true',
77 # help='Deactivate all OSD volumes found in the system',
78 # )
79 if len(self.argv) == 0:
80 print(sub_command_help)
81 return
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'))
88 self.deactivate(args)