2 These utilities for prepare provide all the pieces needed to prepare a device
3 but also a compounded ("single call") helper to do them in order. Some plugins
4 may want to change some part of the process, while others might want to consume
9 from ceph_volume import process, conf
10 from ceph_volume.util import system, constants
12 logger = logging.getLogger(__name__)
16 stdout, stderr, returncode = process.call(['ceph-authtool', '--gen-print-key'])
18 raise RuntimeError('Unable to generate a new auth key')
19 return ' '.join(stdout).strip()
22 def write_keyring(osd_id, secret):
23 # FIXME this only works for cephx, but there will be other types of secrets
25 osd_keyring = '/var/lib/ceph/osd/%s-%s/keyring' % (conf.cluster, osd_id)
28 'ceph-authtool', osd_keyring,
30 '--name', 'osd.%s' % str(osd_id),
33 system.chown(osd_keyring)
34 # TODO: do the restorecon dance on the osd_keyring path
37 def create_id(fsid, json_secrets):
39 :param fsid: The osd fsid to create, always required
40 :param json_secrets: a json-ready object with whatever secrets are wanted
41 to be passed to the monitor
43 bootstrap_keyring = '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf.cluster
44 stdout, stderr, returncode = process.call(
47 '--cluster', conf.cluster,
48 '--name', 'client.bootstrap-osd',
49 '--keyring', bootstrap_keyring,
56 raise RuntimeError('Unable to create a new OSD id')
57 return ' '.join(stdout).strip()
60 def mount_tmpfs(path):
69 def create_osd_path(osd_id, tmpfs=False):
70 path = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
71 system.mkdir_p('/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id))
76 def format_device(device):
78 command = ['mkfs', '-t', 'xfs']
80 # get the mkfs options if any for xfs,
81 # fallback to the default options defined in constants.mkfs
82 flags = conf.ceph.get_list(
84 'osd_mkfs_options_xfs',
85 default=constants.mkfs.get('xfs'),
94 command.append(device)
98 def mount_osd(device, osd_id):
99 destination = '/var/lib/ceph/osd/%s-%s' % (conf.cluster, osd_id)
100 command = ['mount', '-t', 'xfs', '-o']
101 flags = conf.ceph.get_list(
103 'osd_mount_options_xfs',
104 default=constants.mount.get('xfs'),
107 command.append(flags)
108 command.append(device)
109 command.append(destination)
113 def _link_device(device, device_type, osd_id):
115 Allow linking any device type in an OSD directory. ``device`` must the be
116 source, with an absolute path and ``device_type`` will be the destination
117 name, like 'journal', or 'block'
119 device_path = '/var/lib/ceph/osd/%s-%s/%s' % (
124 command = ['ln', '-s', device, device_path]
130 def link_journal(journal_device, osd_id):
131 _link_device(journal_device, 'journal', osd_id)
134 def link_block(block_device, osd_id):
135 _link_device(block_device, 'block', osd_id)
138 def link_wal(wal_device, osd_id):
139 _link_device(wal_device, 'block.wal', osd_id)
142 def link_db(db_device, osd_id):
143 _link_device(db_device, 'block.db', osd_id)
146 def get_monmap(osd_id):
148 Before creating the OSD files, a monmap needs to be retrieved so that it
149 can be used to tell the monitor(s) about the new OSD. A call will look like::
151 ceph --cluster ceph --name client.bootstrap-osd \
152 --keyring /var/lib/ceph/bootstrap-osd/ceph.keyring \
153 mon getmap -o /var/lib/ceph/osd/ceph-0/activate.monmap
155 path = '/var/lib/ceph/osd/%s-%s/' % (conf.cluster, osd_id)
156 bootstrap_keyring = '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf.cluster
157 monmap_destination = os.path.join(path, 'activate.monmap')
161 '--cluster', conf.cluster,
162 '--name', 'client.bootstrap-osd',
163 '--keyring', bootstrap_keyring,
164 'mon', 'getmap', '-o', monmap_destination
168 def osd_mkfs_bluestore(osd_id, fsid, keyring=None, wal=False, db=False):
170 Create the files for the OSD to function. A normal call will look like:
172 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
173 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
174 --osd-data /var/lib/ceph/osd/ceph-0 \
175 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
176 --keyring /var/lib/ceph/osd/ceph-0/keyring \
177 --setuser ceph --setgroup ceph
179 In some cases it is required to use the keyring, when it is passed in as
180 a keywork argument it is used as part of the ceph-osd command
182 path = '/var/lib/ceph/osd/%s-%s/' % (conf.cluster, osd_id)
183 monmap = os.path.join(path, 'activate.monmap')
189 '--cluster', conf.cluster,
190 # undocumented flag, sets the `type` file to contain 'bluestore'
191 '--osd-objectstore', 'bluestore',
197 supplementary_command = [
204 if keyring is not None:
205 base_command.extend(['--key', keyring])
209 ['--bluestore-block-wal-path', wal]
215 ['--bluestore-block-db-path', db]
219 command = base_command + supplementary_command
221 process.run(command, obfuscate='--key')
224 def osd_mkfs_filestore(osd_id, fsid):
226 Create the files for the OSD to function. A normal call will look like:
228 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
229 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
230 --osd-data /var/lib/ceph/osd/ceph-0 \
231 --osd-journal /var/lib/ceph/osd/ceph-0/journal \
232 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
233 --keyring /var/lib/ceph/osd/ceph-0/keyring \
234 --setuser ceph --setgroup ceph
237 path = '/var/lib/ceph/osd/%s-%s/' % (conf.cluster, osd_id)
238 monmap = os.path.join(path, 'activate.monmap')
239 journal = os.path.join(path, 'journal')
241 system.chown(journal)
246 '--cluster', conf.cluster,
247 # undocumented flag, sets the `type` file to contain 'filestore'
248 '--osd-objectstore', 'filestore',
253 '--osd-journal', journal,