]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/util/prepare.py
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
10 from ceph_volume
import process
, conf
11 from ceph_volume
.util
import system
, constants
13 logger
= logging
.getLogger(__name__
)
17 stdout
, stderr
, returncode
= process
.call(
18 ['ceph-authtool', '--gen-print-key'],
21 raise RuntimeError('Unable to generate a new auth key')
22 return ' '.join(stdout
).strip()
25 def write_keyring(osd_id
, secret
, keyring_name
='keyring', name
=None):
27 Create a keyring file with the ``ceph-authtool`` utility. Constructs the
28 path over well-known conventions for the OSD, and allows any other custom
31 :param osd_id: The ID for the OSD to be used
32 :param secret: The key to be added as (as a string)
33 :param name: Defaults to 'osd.{ID}' but can be used to add other client
34 names, specifically for 'lockbox' type of keys
35 :param keyring_name: Alternative keyring name, for supporting other
36 types of keys like for lockbox
38 osd_keyring
= '/var/lib/ceph/osd/%s-%s/%s' % (conf
.cluster
, osd_id
, keyring_name
)
39 name
= name
or 'osd.%s' % str(osd_id
)
42 'ceph-authtool', osd_keyring
,
47 system
.chown(osd_keyring
)
50 def create_id(fsid
, json_secrets
, osd_id
=None):
52 :param fsid: The osd fsid to create, always required
53 :param json_secrets: a json-ready object with whatever secrets are wanted
54 to be passed to the monitor
55 :param osd_id: Reuse an existing ID from an OSD that's been destroyed, if the
56 id does not exist in the cluster a new ID will be created
58 bootstrap_keyring
= '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf
.cluster
61 '--cluster', conf
.cluster
,
62 '--name', 'client.bootstrap-osd',
63 '--keyring', bootstrap_keyring
,
69 stdout
, stderr
, returncode
= process
.call(
75 raise RuntimeError('Unable to create a new OSD id')
76 return ' '.join(stdout
).strip()
81 Checks to see if an osd ID exists or not. Returns True
82 if it does exist, False if it doesn't.
84 :param osd_id: The osd ID to check
88 bootstrap_keyring
= '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf
.cluster
89 stdout
, stderr
, returncode
= process
.call(
92 '--cluster', conf
.cluster
,
93 '--name', 'client.bootstrap-osd',
94 '--keyring', bootstrap_keyring
,
102 raise RuntimeError('Unable check if OSD id exists: %s' % osd_id
)
104 output
= json
.loads(''.join(stdout
).strip())
105 osds
= output
['nodes']
106 return any([str(osd
['id']) == str(osd_id
) for osd
in osds
])
109 def mount_tmpfs(path
):
118 def create_osd_path(osd_id
, tmpfs
=False):
119 path
= '/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
)
120 system
.mkdir_p('/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
))
125 def format_device(device
):
127 command
= ['mkfs', '-t', 'xfs']
129 # get the mkfs options if any for xfs,
130 # fallback to the default options defined in constants.mkfs
131 flags
= conf
.ceph
.get_list(
133 'osd_mkfs_options_xfs',
134 default
=constants
.mkfs
.get('xfs'),
139 if '-f' not in flags
:
140 flags
.insert(0, '-f')
142 command
.extend(flags
)
143 command
.append(device
)
147 def mount_osd(device
, osd_id
):
148 destination
= '/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
)
149 command
= ['mount', '-t', 'xfs', '-o']
150 flags
= conf
.ceph
.get_list(
152 'osd_mount_options_xfs',
153 default
=constants
.mount
.get('xfs'),
156 command
.extend(flags
)
157 command
.append(device
)
158 command
.append(destination
)
162 def _link_device(device
, device_type
, osd_id
):
164 Allow linking any device type in an OSD directory. ``device`` must the be
165 source, with an absolute path and ``device_type`` will be the destination
166 name, like 'journal', or 'block'
168 device_path
= '/var/lib/ceph/osd/%s-%s/%s' % (
173 command
= ['ln', '-s', device
, device_path
]
179 def link_journal(journal_device
, osd_id
):
180 _link_device(journal_device
, 'journal', osd_id
)
183 def link_block(block_device
, osd_id
):
184 _link_device(block_device
, 'block', osd_id
)
187 def link_wal(wal_device
, osd_id
):
188 _link_device(wal_device
, 'block.wal', osd_id
)
191 def link_db(db_device
, osd_id
):
192 _link_device(db_device
, 'block.db', osd_id
)
195 def get_monmap(osd_id
):
197 Before creating the OSD files, a monmap needs to be retrieved so that it
198 can be used to tell the monitor(s) about the new OSD. A call will look like::
200 ceph --cluster ceph --name client.bootstrap-osd \
201 --keyring /var/lib/ceph/bootstrap-osd/ceph.keyring \
202 mon getmap -o /var/lib/ceph/osd/ceph-0/activate.monmap
204 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
205 bootstrap_keyring
= '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf
.cluster
206 monmap_destination
= os
.path
.join(path
, 'activate.monmap')
210 '--cluster', conf
.cluster
,
211 '--name', 'client.bootstrap-osd',
212 '--keyring', bootstrap_keyring
,
213 'mon', 'getmap', '-o', monmap_destination
217 def osd_mkfs_bluestore(osd_id
, fsid
, keyring
=None, wal
=False, db
=False):
219 Create the files for the OSD to function. A normal call will look like:
221 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
222 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
223 --osd-data /var/lib/ceph/osd/ceph-0 \
224 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
225 --keyring /var/lib/ceph/osd/ceph-0/keyring \
226 --setuser ceph --setgroup ceph
228 In some cases it is required to use the keyring, when it is passed in as
229 a keywork argument it is used as part of the ceph-osd command
231 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
232 monmap
= os
.path
.join(path
, 'activate.monmap')
238 '--cluster', conf
.cluster
,
239 # undocumented flag, sets the `type` file to contain 'bluestore'
240 '--osd-objectstore', 'bluestore',
246 supplementary_command
= [
253 if keyring
is not None:
254 base_command
.extend(['--keyfile', '-'])
258 ['--bluestore-block-wal-path', wal
]
264 ['--bluestore-block-db-path', db
]
268 command
= base_command
+ supplementary_command
270 process
.call(command
, stdin
=keyring
, show_command
=True)
273 def osd_mkfs_filestore(osd_id
, fsid
):
275 Create the files for the OSD to function. A normal call will look like:
277 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
278 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
279 --osd-data /var/lib/ceph/osd/ceph-0 \
280 --osd-journal /var/lib/ceph/osd/ceph-0/journal \
281 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
282 --keyring /var/lib/ceph/osd/ceph-0/keyring \
283 --setuser ceph --setgroup ceph
286 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
287 monmap
= os
.path
.join(path
, 'activate.monmap')
288 journal
= os
.path
.join(path
, 'journal')
290 system
.chown(journal
)
295 '--cluster', conf
.cluster
,
296 # undocumented flag, sets the `type` file to contain 'filestore'
297 '--osd-objectstore', 'filestore',
302 '--osd-journal', journal
,