]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: split-off config work on bootstrap
authorJoao Eduardo Luis <joao@suse.com>
Thu, 31 Dec 2020 01:44:44 +0000 (01:44 +0000)
committerJoao Eduardo Luis <joao@suse.com>
Wed, 20 Jan 2021 14:20:46 +0000 (13:20 -0100)
Signed-off-by: Joao Eduardo Luis <joao@suse.com>
src/cephadm/cephadm

index ef05151902613a3fa73a436be527a20dfee7bde8..4d9a8333719e544db738ae4ff5269d5b21a4ac67 100755 (executable)
@@ -3471,6 +3471,80 @@ def prepare_dashboard(
                     password))
 
 
+def prepare_bootstrap_config(
+    ctx: CephadmContext,
+    fsid: str, mon_addr: str, image: str
+
+) -> str:
+
+    cp = read_config(ctx.args.config)
+    if not cp.has_section('global'):
+        cp.add_section('global')
+    cp.set('global', 'fsid', fsid)
+    cp.set('global', 'mon host', mon_addr)
+    cp.set('global', 'container_image', image)
+    cpf = StringIO()
+    cp.write(cpf)
+    config = cpf.getvalue()
+
+    if ctx.args.registry_json or ctx.args.registry_url:
+        command_registry_login(ctx)
+
+    if not ctx.args.skip_pull:
+        _pull_image(ctx, image)
+
+    return config
+
+
+def finish_bootstrap_config(
+    ctx: CephadmContext,
+    fsid: str,
+    config: str,
+    mon_id: str, mon_dir: str,
+    mon_network: Optional[str], ipv6: bool,
+    cli: Callable
+
+) -> None:
+    if not ctx.args.no_minimize_config:
+        logger.info('Assimilating anything we can from ceph.conf...')
+        cli([
+            'config', 'assimilate-conf',
+            '-i', '/var/lib/ceph/mon/ceph-%s/config' % mon_id
+        ], {
+            mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id
+        })
+        logger.info('Generating new minimal ceph.conf...')
+        cli([
+            'config', 'generate-minimal-conf',
+            '-o', '/var/lib/ceph/mon/ceph-%s/config' % mon_id
+        ], {
+            mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id
+        })
+        # re-read our minimized config
+        with open(mon_dir + '/config', 'r') as f:
+            config = f.read()
+        logger.info('Restarting the monitor...')
+        call_throws(ctx, [
+            'systemctl',
+            'restart',
+            get_unit_name(fsid, 'mon', mon_id)
+        ])
+
+    if mon_network:
+        logger.info('Setting mon public_network...')
+        cli(['config', 'set', 'mon', 'public_network', mon_network])
+
+    if ipv6:
+        logger.info('Enabling IPv6 (ms_bind_ipv6)')
+        cli(['config', 'set', 'global', 'ms_bind_ipv6', 'true'])
+
+
+    with open(ctx.args.output_config, 'w') as f:
+        f.write(config)
+    logger.info('Wrote config to %s' % ctx.args.output_config)
+    pass
+
+
 @default_image
 def command_bootstrap(ctx):
     # type: (CephadmContext) -> int
@@ -3540,22 +3614,7 @@ def command_bootstrap(ctx):
             raise Error('Failed to infer CIDR network for mon ip %s; pass '
                         '--skip-mon-network to configure it later' % base_ip)
 
-    # config
-    cp = read_config(ctx.args.config)
-    if not cp.has_section('global'):
-        cp.add_section('global')
-    cp.set('global', 'fsid', fsid);
-    cp.set('global', 'mon host', addr_arg)
-    cp.set('global', 'container_image', ctx.args.image)
-    cpf = StringIO()
-    cp.write(cpf)
-    config = cpf.getvalue()
-
-    if ctx.args.registry_json or ctx.args.registry_url:
-        command_registry_login(ctx)
-
-    if not ctx.args.skip_pull:
-        _pull_image(ctx, ctx.args.image)
+    config = prepare_bootstrap_config(ctx, fsid, addr_arg, ctx.args.image)
 
     logger.info('Extracting ceph user uid/gid from container image...')
     (uid, gid) = extract_uid_gid(ctx)
@@ -3603,39 +3662,8 @@ def command_bootstrap(ctx):
 
     wait_for_mon(ctx, mon_id, mon_dir, admin_keyring.name, tmp_config.name)
 
-    # assimilate and minimize config
-    if not ctx.args.no_minimize_config:
-        logger.info('Assimilating anything we can from ceph.conf...')
-        cli([
-            'config', 'assimilate-conf',
-            '-i', '/var/lib/ceph/mon/ceph-%s/config' % mon_id
-        ], {
-            mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id
-        })
-        logger.info('Generating new minimal ceph.conf...')
-        cli([
-            'config', 'generate-minimal-conf',
-            '-o', '/var/lib/ceph/mon/ceph-%s/config' % mon_id
-        ], {
-            mon_dir: '/var/lib/ceph/mon/ceph-%s:z' % mon_id
-        })
-        # re-read our minimized config
-        with open(mon_dir + '/config', 'r') as f:
-            config = f.read()
-        logger.info('Restarting the monitor...')
-        call_throws(ctx, [
-            'systemctl',
-            'restart',
-            get_unit_name(fsid, 'mon', mon_id)
-        ])
-
-    if mon_network:
-        logger.info('Setting mon public_network...')
-        cli(['config', 'set', 'mon', 'public_network', mon_network])
-
-    if ipv6:
-        logger.info('Enabling IPv6 (ms_bind_ipv6)')
-        cli(['config', 'set', 'global', 'ms_bind_ipv6', 'true'])
+    finish_bootstrap_config(ctx, fsid, config, mon_id, mon_dir,
+                            mon_network, ipv6, cli)
 
     # output files
     with open(ctx.args.output_keyring, 'w') as f:
@@ -3644,10 +3672,6 @@ def command_bootstrap(ctx):
                 '\tkey = ' + admin_key + '\n')
     logger.info('Wrote keyring to %s' % ctx.args.output_keyring)
 
-    with open(ctx.args.output_config, 'w') as f:
-        f.write(config)
-    logger.info('Wrote config to %s' % ctx.args.output_config)
-
     # create mgr
     create_mgr(ctx, uid, gid, fsid, mgr_id, mgr_key, config, cli)