]>
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
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
):
70 def create_osd_path(osd_id
, tmpfs
=False):
71 path
= '/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
)
72 system
.mkdir_p('/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
))
77 def format_device(device
):
79 command
= ['sudo', 'mkfs', '-t', 'xfs']
81 # get the mkfs options if any for xfs,
82 # fallback to the default options defined in constants.mkfs
83 flags
= conf
.ceph
.get_list(
85 'osd_mkfs_options_xfs',
86 default
=constants
.mkfs
.get('xfs'),
95 command
.append(device
)
99 def mount_osd(device
, osd_id
):
100 destination
= '/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
)
101 command
= ['sudo', 'mount', '-t', 'xfs', '-o']
102 flags
= conf
.ceph
.get_list(
104 'osd_mount_options_xfs',
105 default
=constants
.mount
.get('xfs'),
108 command
.append(flags
)
109 command
.append(device
)
110 command
.append(destination
)
114 def _link_device(device
, device_type
, osd_id
):
116 Allow linking any device type in an OSD directory. ``device`` must the be
117 source, with an absolute path and ``device_type`` will be the destination
118 name, like 'journal', or 'block'
120 device_path
= '/var/lib/ceph/osd/%s-%s/%s' % (
125 command
= ['sudo', 'ln', '-s', device
, device_path
]
131 def link_journal(journal_device
, osd_id
):
132 _link_device(journal_device
, 'journal', osd_id
)
135 def link_block(block_device
, osd_id
):
136 _link_device(block_device
, 'block', osd_id
)
139 def link_wal(wal_device
, osd_id
):
140 _link_device(wal_device
, 'block.wal', osd_id
)
143 def link_db(db_device
, osd_id
):
144 _link_device(db_device
, 'block.db', osd_id
)
147 def get_monmap(osd_id
):
149 Before creating the OSD files, a monmap needs to be retrieved so that it
150 can be used to tell the monitor(s) about the new OSD. A call will look like::
152 ceph --cluster ceph --name client.bootstrap-osd \
153 --keyring /var/lib/ceph/bootstrap-osd/ceph.keyring \
154 mon getmap -o /var/lib/ceph/osd/ceph-0/activate.monmap
156 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
157 bootstrap_keyring
= '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf
.cluster
158 monmap_destination
= os
.path
.join(path
, 'activate.monmap')
163 '--cluster', conf
.cluster
,
164 '--name', 'client.bootstrap-osd',
165 '--keyring', bootstrap_keyring
,
166 'mon', 'getmap', '-o', monmap_destination
170 def osd_mkfs_bluestore(osd_id
, fsid
, keyring
=None, wal
=False, db
=False):
172 Create the files for the OSD to function. A normal call will look like:
174 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
175 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
176 --osd-data /var/lib/ceph/osd/ceph-0 \
177 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
178 --keyring /var/lib/ceph/osd/ceph-0/keyring \
179 --setuser ceph --setgroup ceph
181 In some cases it is required to use the keyring, when it is passed in as
182 a keywork argument it is used as part of the ceph-osd command
184 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
185 monmap
= os
.path
.join(path
, 'activate.monmap')
192 '--cluster', conf
.cluster
,
193 # undocumented flag, sets the `type` file to contain 'bluestore'
194 '--osd-objectstore', 'bluestore',
200 supplementary_command
= [
207 if keyring
is not None:
208 base_command
.extend(['--key', keyring
])
212 ['--bluestore-block-wal-path', wal
]
218 ['--bluestore-block-db-path', db
]
222 command
= base_command
+ supplementary_command
224 process
.run(command
, obfuscate
='--key')
227 def osd_mkfs_filestore(osd_id
, fsid
):
229 Create the files for the OSD to function. A normal call will look like:
231 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
232 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
233 --osd-data /var/lib/ceph/osd/ceph-0 \
234 --osd-journal /var/lib/ceph/osd/ceph-0/journal \
235 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
236 --keyring /var/lib/ceph/osd/ceph-0/keyring \
237 --setuser ceph --setgroup ceph
240 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
241 monmap
= os
.path
.join(path
, 'activate.monmap')
242 journal
= os
.path
.join(path
, 'journal')
244 system
.chown(journal
)
250 '--cluster', conf
.cluster
,
251 # undocumented flag, sets the `type` file to contain 'filestore'
252 '--osd-objectstore', 'filestore',
257 '--osd-journal', journal
,