]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume util.prepare add a helper to get journal sizes from ceph.conf
authorAlfredo Deza <adeza@redhat.com>
Thu, 9 Aug 2018 18:24:45 +0000 (14:24 -0400)
committerAndrew Schoen <aschoen@redhat.com>
Tue, 28 Aug 2018 20:32:27 +0000 (15:32 -0500)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 4c0b4df1df2db85209c13ff66ae7a67524856c2d)

src/ceph-volume/ceph_volume/util/prepare.py

index 3ea86ad23bd062b55ce40b5490a16367cced6eee..687a5892bda9cc06783ec6335c41b42ec31e6b32 100644 (file)
@@ -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