]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/devices/raw/prepare.py
1 from __future__
import print_function
5 from textwrap
import dedent
6 from ceph_volume
.util
import prepare
as prepare_utils
7 from ceph_volume
.util
import encryption
as encryption_utils
8 from ceph_volume
.util
import disk
9 from ceph_volume
.util
import system
10 from ceph_volume
import decorators
, terminal
11 from ceph_volume
.devices
.lvm
.common
import rollback_osd
12 from .common
import create_parser
14 logger
= logging
.getLogger(__name__
)
16 def prepare_dmcrypt(key
, device
, device_type
, fsid
):
18 Helper for devices that are encrypted. The operations needed for
19 block, db, wal, devices are all the same
23 kname
= disk
.lsblk(device
)['KNAME']
24 mapping
= 'ceph-{}-{}-{}-dmcrypt'.format(fsid
, kname
, device_type
)
25 return encryption_utils
.prepare_dmcrypt(key
, device
, mapping
)
27 def prepare_bluestore(block
, wal
, db
, secrets
, osd_id
, fsid
, tmpfs
):
29 :param block: The name of the logical volume for the bluestore data
30 :param wal: a regular/plain disk or logical volume, to be used for block.wal
31 :param db: a regular/plain disk or logical volume, to be used for block.db
32 :param secrets: A dict with the secrets needed to create the osd (e.g. cephx)
33 :param id_: The OSD id
34 :param fsid: The OSD fsid, also known as the OSD UUID
36 cephx_secret
= secrets
.get('cephx_secret', prepare_utils
.create_key())
38 if secrets
.get('dmcrypt_key'):
39 key
= secrets
['dmcrypt_key']
40 block
= prepare_dmcrypt(key
, block
, 'block', fsid
)
41 wal
= prepare_dmcrypt(key
, wal
, 'wal', fsid
)
42 db
= prepare_dmcrypt(key
, db
, 'db', fsid
)
44 # create the directory
45 prepare_utils
.create_osd_path(osd_id
, tmpfs
=tmpfs
)
47 prepare_utils
.link_block(block
, osd_id
)
48 # get the latest monmap
49 prepare_utils
.get_monmap(osd_id
)
50 # write the OSD keyring if it doesn't exist already
51 prepare_utils
.write_keyring(osd_id
, cephx_secret
)
52 # prepare the osd filesystem
53 prepare_utils
.osd_mkfs_bluestore(
61 class Prepare(object):
63 help = 'Format a raw device and associate it with a (BlueStore) OSD'
65 def __init__(self
, argv
):
69 def safe_prepare(self
, args
=None):
71 An intermediate step between `main()` and `prepare()` so that we can
72 capture the `self.osd_id` in case we need to rollback
74 :param args: Injected args, usually from `raw create` which compounds
75 both `prepare` and `create`
82 logger
.exception('raw prepare was unable to complete')
83 logger
.info('will rollback OSD ID creation')
84 rollback_osd(self
.args
, self
.osd_id
)
86 dmcrypt_log
= 'dmcrypt' if args
.dmcrypt
else 'clear'
87 terminal
.success("ceph-volume raw {} prepare successful for: {}".format(dmcrypt_log
, self
.args
.data
))
90 @decorators.needs_root
92 secrets
= {'cephx_secret': prepare_utils
.create_key()}
93 encrypted
= 1 if self
.args
.dmcrypt
else 0
94 cephx_lockbox_secret
= '' if not encrypted
else prepare_utils
.create_key()
97 secrets
['dmcrypt_key'] = os
.getenv('CEPH_VOLUME_DMCRYPT_SECRET')
98 secrets
['cephx_lockbox_secret'] = cephx_lockbox_secret
# dummy value to make `ceph osd new` not complaining
100 osd_fsid
= system
.generate_uuid()
101 crush_device_class
= self
.args
.crush_device_class
102 if crush_device_class
:
103 secrets
['crush_device_class'] = crush_device_class
104 tmpfs
= not self
.args
.no_tmpfs
107 if self
.args
.block_wal
:
108 wal
= self
.args
.block_wal
109 if self
.args
.block_db
:
110 db
= self
.args
.block_db
112 # reuse a given ID if it exists, otherwise create a new ID
113 self
.osd_id
= prepare_utils
.create_id(
116 osd_id
=self
.args
.osd_id
)
129 sub_command_help
= dedent("""
130 Prepare an OSD by assigning an ID and FSID, registering them with the
131 cluster with an ID and FSID, formatting the volume.
133 Once the OSD is ready, an ad-hoc systemd unit will be enabled so that
134 it can later get activated and the OSD daemon can get started.
136 ceph-volume raw prepare --bluestore --data {device}
138 DB and WAL devices are supported.
140 ceph-volume raw prepare --bluestore --data {device} --block.db {device} --block.wal {device}
143 parser
= create_parser(
144 prog
='ceph-volume raw prepare',
145 description
=sub_command_help
,
148 print(sub_command_help
)
150 self
.args
= parser
.parse_args(self
.argv
)
151 if not self
.args
.bluestore
:
152 terminal
.error('must specify --bluestore (currently the only supported backend)')
154 if self
.args
.dmcrypt
and not os
.getenv('CEPH_VOLUME_DMCRYPT_SECRET'):
155 terminal
.error('encryption was requested (--dmcrypt) but environment variable ' \
156 'CEPH_VOLUME_DMCRYPT_SECRET is not set, you must set ' \
157 'this variable to provide a dmcrypt secret.')
160 self
.safe_prepare(self
.args
)