From: Alfredo Deza Date: Thu, 9 Aug 2018 18:24:45 +0000 (-0400) Subject: ceph-volume util.prepare add a helper to get journal sizes from ceph.conf X-Git-Tag: v14.0.1~520^2~3^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4c0b4df1df2db85209c13ff66ae7a67524856c2d;p=ceph.git ceph-volume util.prepare add a helper to get journal sizes from ceph.conf Signed-off-by: Alfredo Deza --- diff --git a/src/ceph-volume/ceph_volume/util/prepare.py b/src/ceph-volume/ceph_volume/util/prepare.py index dbd2a079d795..964ca78f3785 100644 --- a/src/ceph-volume/ceph_volume/util/prepare.py +++ b/src/ceph-volume/ceph_volume/util/prepare.py @@ -7,10 +7,11 @@ the single-call helper import os import logging import json -from ceph_volume import process, conf, __release__ -from ceph_volume.util import system, constants +from ceph_volume import process, conf, __release__, terminal +from ceph_volume.util import system, constants, str_to_int, disk logger = logging.getLogger(__name__) +mlogger = terminal.MultiLogger(__name__) def create_key(): @@ -47,6 +48,28 @@ def write_keyring(osd_id, secret, keyring_name='keyring', name=None): system.chown(osd_keyring) +def get_journal_size(lv_format=True): + """ + Helper to retrieve the size (defined in megabytes in ceph.conf) to create + the journal logical volume, it "translates" the string into a float value, + then converts that into gigabytes, and finally (optionally) it formats it + back as a string so that it can be used for creating the LV. + + :param lv_format: Return a string to be used for ``lv_create``. A 5 GB size + would result in '5G', otherwise it will return a ``Size`` object. + """ + conf_journal_size = conf.ceph.get_safe('osd', 'osd_journal_size', '5120') + logger.debug('osd_journal_size set to %s' % conf_journal_size) + journal_size = disk.Size(mb=str_to_int(conf_journal_size)) + + if journal_size < disk.Size(gb=2): + mlogger.error('Refusing to continue with configured size for journal') + raise RuntimeError('journal sizes must be larger than 2GB, detected: %s' % journal_size) + if lv_format: + return '%sG' % journal_size.gb.as_int() + return journal_size + + def create_id(fsid, json_secrets, osd_id=None): """ :param fsid: The osd fsid to create, always required