]> git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/raw/activate.py
import quincy beta 17.1.0
[ceph.git] / ceph / src / ceph-volume / ceph_volume / devices / raw / activate.py
1 from __future__ import print_function
2 import argparse
3 import logging
4 import os
5 from textwrap import dedent
6 from ceph_volume import process, conf, decorators, terminal
7 from ceph_volume.util import system
8 from ceph_volume.util import prepare as prepare_utils
9 from .list import direct_report
10
11
12 logger = logging.getLogger(__name__)
13
14 def activate_bluestore(meta, tmpfs, systemd):
15 # find the osd
16 osd_id = meta['osd_id']
17 osd_uuid = meta['osd_uuid']
18
19 # mount on tmpfs the osd directory
20 osd_path = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
21 if not system.path_is_mounted(osd_path):
22 # mkdir -p and mount as tmpfs
23 prepare_utils.create_osd_path(osd_id, tmpfs=tmpfs)
24
25 # XXX This needs to be removed once ceph-bluestore-tool can deal with
26 # symlinks that exist in the osd dir
27 for link_name in ['block', 'block.db', 'block.wal']:
28 link_path = os.path.join(osd_path, link_name)
29 if os.path.exists(link_path):
30 os.unlink(os.path.join(osd_path, link_name))
31
32 # Once symlinks are removed, the osd dir can be 'primed again. chown first,
33 # regardless of what currently exists so that ``prime-osd-dir`` can succeed
34 # even if permissions are somehow messed up
35 system.chown(osd_path)
36 prime_command = [
37 'ceph-bluestore-tool',
38 'prime-osd-dir',
39 '--path', osd_path,
40 '--no-mon-config',
41 '--dev', meta['device'],
42 ]
43 process.run(prime_command)
44
45 # always re-do the symlink regardless if it exists, so that the block,
46 # block.wal, and block.db devices that may have changed can be mapped
47 # correctly every time
48 prepare_utils.link_block(meta['device'], osd_id)
49
50 if 'device_db' in meta:
51 prepare_utils.link_db(meta['device_db'], osd_id, osd_uuid)
52
53 if 'device_wal' in meta:
54 prepare_utils.link_wal(meta['device_wal'], osd_id, osd_uuid)
55
56 system.chown(osd_path)
57 terminal.success("ceph-volume raw activate successful for osd ID: %s" % osd_id)
58
59
60 class Activate(object):
61
62 help = 'Discover and prepare a data directory for a (BlueStore) OSD on a raw device'
63
64 def __init__(self, argv):
65 self.argv = argv
66 self.args = None
67
68 @decorators.needs_root
69 def activate(self, devs, start_osd_id, start_osd_uuid,
70 tmpfs, systemd):
71 """
72 :param args: The parsed arguments coming from the CLI
73 """
74 assert devs or start_osd_id or start_osd_uuid
75 found = direct_report(devs)
76
77 activated_any = False
78 for osd_uuid, meta in found.items():
79 osd_id = meta['osd_id']
80 if start_osd_id is not None and str(osd_id) != str(start_osd_id):
81 continue
82 if start_osd_uuid is not None and osd_uuid != start_osd_uuid:
83 continue
84 logger.info('Activating osd.%s uuid %s cluster %s' % (
85 osd_id, osd_uuid, meta['ceph_fsid']))
86 activate_bluestore(meta,
87 tmpfs=tmpfs,
88 systemd=systemd)
89 activated_any = True
90
91 if not activated_any:
92 raise RuntimeError('did not find any matching OSD to activate')
93
94 def main(self):
95 sub_command_help = dedent("""
96 Activate (BlueStore) OSD on a raw block device(s) based on the
97 device label (normally the first block of the device).
98
99 ceph-volume raw activate [/dev/sdb2 ...]
100
101 or
102
103 ceph-volume raw activate --osd-id NUM --osd-uuid UUID
104
105 The device(s) associated with the OSD need to have been prepared
106 previously, so that all needed tags and metadata exist.
107 """)
108 parser = argparse.ArgumentParser(
109 prog='ceph-volume raw activate',
110 formatter_class=argparse.RawDescriptionHelpFormatter,
111 description=sub_command_help,
112 )
113 parser.add_argument(
114 '--device',
115 help='The device for the OSD to start'
116 )
117 parser.add_argument(
118 '--osd-id',
119 help='OSD ID to activate'
120 )
121 parser.add_argument(
122 '--osd-uuid',
123 help='OSD UUID to active'
124 )
125 parser.add_argument(
126 '--no-systemd',
127 dest='no_systemd',
128 action='store_true',
129 help='Skip creating and enabling systemd units and starting OSD services'
130 )
131 parser.add_argument(
132 '--block.db',
133 dest='block_db',
134 help='Path to bluestore block.db block device'
135 )
136 parser.add_argument(
137 '--block.wal',
138 dest='block_wal',
139 help='Path to bluestore block.wal block device'
140 )
141 parser.add_argument(
142 '--no-tmpfs',
143 action='store_true',
144 help='Do not use a tmpfs mount for OSD data dir'
145 )
146
147 if not self.argv:
148 print(sub_command_help)
149 return
150 args = parser.parse_args(self.argv)
151 self.args = args
152 if not args.no_systemd:
153 terminal.error('systemd support not yet implemented')
154 raise SystemExit(1)
155
156 devs = [args.device]
157 if args.block_wal:
158 devs.append(args.block_wal)
159 if args.block_db:
160 devs.append(args.block_db)
161
162 self.activate(devs=devs,
163 start_osd_id=args.osd_id,
164 start_osd_uuid=args.osd_uuid,
165 tmpfs=not args.no_tmpfs,
166 systemd=not self.args.no_systemd)