]>
git.proxmox.com Git - ceph.git/blob - ceph/src/ceph-volume/ceph_volume/util/prepare.py
eefa0adc2041526ee1358c50762ae5146e295c77
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 create_path(osd_id
):
61 system
.mkdir_p('/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
))
64 def format_device(device
):
66 command
= ['sudo', 'mkfs', '-t', 'xfs']
68 # get the mkfs options if any for xfs,
69 # fallback to the default options defined in constants.mkfs
70 flags
= conf
.ceph
.get_list(
72 'osd_mkfs_options_xfs',
73 default
=constants
.mkfs
.get('xfs'),
82 command
.append(device
)
86 def mount_osd(device
, osd_id
):
87 destination
= '/var/lib/ceph/osd/%s-%s' % (conf
.cluster
, osd_id
)
88 command
= ['sudo', 'mount', '-t', 'xfs', '-o']
89 flags
= conf
.ceph
.get_list(
91 'osd_mount_options_xfs',
92 default
=constants
.mount
.get('xfs'),
96 command
.append(device
)
97 command
.append(destination
)
101 def link_journal(journal_device
, osd_id
):
102 journal_path
= '/var/lib/ceph/osd/%s-%s/journal' % (
106 command
= ['sudo', 'ln', '-s', journal_device
, journal_path
]
110 def get_monmap(osd_id
):
112 Before creating the OSD files, a monmap needs to be retrieved so that it
113 can be used to tell the monitor(s) about the new OSD. A call will look like::
115 ceph --cluster ceph --name client.bootstrap-osd \
116 --keyring /var/lib/ceph/bootstrap-osd/ceph.keyring \
117 mon getmap -o /var/lib/ceph/osd/ceph-0/activate.monmap
119 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
120 bootstrap_keyring
= '/var/lib/ceph/bootstrap-osd/%s.keyring' % conf
.cluster
121 monmap_destination
= os
.path
.join(path
, 'activate.monmap')
126 '--cluster', conf
.cluster
,
127 '--name', 'client.bootstrap-osd',
128 '--keyring', bootstrap_keyring
,
129 'mon', 'getmap', '-o', monmap_destination
133 def osd_mkfs(osd_id
, fsid
):
135 Create the files for the OSD to function. A normal call will look like:
137 ceph-osd --cluster ceph --mkfs --mkkey -i 0 \
138 --monmap /var/lib/ceph/osd/ceph-0/activate.monmap \
139 --osd-data /var/lib/ceph/osd/ceph-0 \
140 --osd-journal /var/lib/ceph/osd/ceph-0/journal \
141 --osd-uuid 8d208665-89ae-4733-8888-5d3bfbeeec6c \
142 --keyring /var/lib/ceph/osd/ceph-0/keyring \
143 --setuser ceph --setgroup ceph
146 path
= '/var/lib/ceph/osd/%s-%s/' % (conf
.cluster
, osd_id
)
147 monmap
= os
.path
.join(path
, 'activate.monmap')
148 journal
= os
.path
.join(path
, 'journal')
150 system
.chown(journal
)
156 '--cluster', conf
.cluster
,
161 '--osd-journal', journal
,