1 from __future__
import print_function
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
12 logger
= logging
.getLogger(__name__
)
14 def activate_bluestore(meta
, tmpfs
, systemd
):
16 osd_id
= meta
['osd_id']
17 osd_uuid
= meta
['osd_uuid']
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
)
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
))
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
)
37 'ceph-bluestore-tool',
41 '--dev', meta
['device'],
43 process
.run(prime_command
)
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
)
50 if 'device_db' in meta
:
51 prepare_utils
.link_db(meta
['device_db'], osd_id
, osd_uuid
)
53 if 'device_wal' in meta
:
54 prepare_utils
.link_wal(meta
['device_wal'], osd_id
, osd_uuid
)
56 system
.chown(osd_path
)
57 terminal
.success("ceph-volume raw activate successful for osd ID: %s" % osd_id
)
60 class Activate(object):
62 help = 'Discover and prepare a data directory for a (BlueStore) OSD on a raw device'
64 def __init__(self
, argv
):
68 @decorators.needs_root
69 def activate(self
, devs
, start_osd_id
, start_osd_uuid
,
72 :param args: The parsed arguments coming from the CLI
74 assert devs
or start_osd_id
or start_osd_uuid
75 found
= direct_report(devs
)
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
):
82 if start_osd_uuid
is not None and osd_uuid
!= start_osd_uuid
:
84 logger
.info('Activating osd.%s uuid %s cluster %s' % (
85 osd_id
, osd_uuid
, meta
['ceph_fsid']))
86 activate_bluestore(meta
,
92 raise RuntimeError('did not find any matching OSD to activate')
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).
99 ceph-volume raw activate [/dev/sdb2 ...]
103 ceph-volume raw activate --osd-id NUM --osd-uuid UUID
105 The device(s) associated with the OSD need to have been prepared
106 previously, so that all needed tags and metadata exist.
108 parser
= argparse
.ArgumentParser(
109 prog
='ceph-volume raw activate',
110 formatter_class
=argparse
.RawDescriptionHelpFormatter
,
111 description
=sub_command_help
,
115 help='The device for the OSD to start'
119 help='OSD ID to activate'
123 help='OSD UUID to active'
129 help='Skip creating and enabling systemd units and starting OSD services'
134 help='Path to bluestore block.db block device'
139 help='Path to bluestore block.wal block device'
144 help='Do not use a tmpfs mount for OSD data dir'
148 print(sub_command_help
)
150 args
= parser
.parse_args(self
.argv
)
152 if not args
.no_systemd
:
153 terminal
.error('systemd support not yet implemented')
158 devs
.append(args
.block_wal
)
160 devs
.append(args
.block_db
)
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
)