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
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)
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:
'\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)