MCPcopy Create free account
hub / github.com/ceph/ceph / command_bootstrap

Function command_bootstrap

src/cephadm/cephadm.py:2805–3098  ·  view source on GitHub ↗
(ctx)

Source from the content-addressed store, hash-verified

2803@rollback
2804@default_image
2805def command_bootstrap(ctx):
2806 # type: (CephadmContext) -> int
2807
2808 ctx.error_code = 0
2809
2810 if not ctx.output_config:
2811 ctx.output_config = os.path.join(ctx.output_dir, CEPH_CONF)
2812 if not ctx.output_keyring:
2813 ctx.output_keyring = os.path.join(ctx.output_dir, CEPH_KEYRING)
2814 if not ctx.output_pub_ssh_key:
2815 ctx.output_pub_ssh_key = os.path.join(ctx.output_dir, CEPH_PUBKEY)
2816
2817 if ctx.apply_spec and not os.path.exists(ctx.apply_spec):
2818 # Given that nothing has been deployed at this point, setting `ctx.no_cleanup_on_failure = True`
2819 # as there's no need to call _rm_cluster() which would generate the message:
2820 # "ERROR: must select the cluster to delete by passing --fsid to proceed"
2821 ctx.no_cleanup_on_failure = True
2822 raise Error(f"--apply-spec has been specified but {ctx.apply_spec} doesn't exist.")
2823
2824 if (
2825 (bool(ctx.ssh_private_key) is not bool(ctx.ssh_public_key))
2826 and (bool(ctx.ssh_private_key) is not bool(ctx.ssh_signed_cert))
2827 ):
2828 raise Error('--ssh-private-key must be passed with either --ssh-public-key in the case of standard pubkey '
2829 'authentication or with --ssh-signed-cert in the case of CA signed signed keys or not provided at all.')
2830
2831 if (bool(ctx.ssh_public_key) and bool(ctx.ssh_signed_cert)):
2832 raise Error('--ssh-public-key and --ssh-signed-cert are mututally exclusive. --ssh-public-key is intended '
2833 'for standard pubkey encryption where the public key is set as an authorized key on cluster hosts. '
2834 '--ssh-signed-cert is intended for the CA signed keys use case where cluster hosts are configured to trust '
2835 'a CA pub key and authentication during SSH is done by authenticating the signed cert, requiring no '
2836 'public key to be installed on the cluster hosts.')
2837
2838 if ctx.fsid:
2839 data_dir_base = os.path.join(ctx.data_dir, ctx.fsid)
2840 if os.path.exists(data_dir_base):
2841 raise ClusterAlreadyExists(f"A cluster with the same fsid '{ctx.fsid}' already exists.")
2842 else:
2843 logger.warning('Specifying an fsid for your cluster offers no advantages and may increase the likelihood of fsid conflicts.')
2844
2845 # initial vars
2846 ctx.fsid = ctx.fsid or make_fsid()
2847 fsid = ctx.fsid
2848 if not is_fsid(fsid):
2849 raise Error('not an fsid: %s' % fsid)
2850
2851 # verify output files
2852 for f in [ctx.output_config, ctx.output_keyring, ctx.output_pub_ssh_key]:
2853 if not ctx.allow_overwrite:
2854 if os.path.exists(f):
2855 raise ClusterAlreadyExists('%s already exists; delete or pass --allow-overwrite to overwrite' % f)
2856 dirname = os.path.dirname(f)
2857 if dirname and not os.path.exists(dirname):
2858 fname = os.path.basename(f)
2859 logger.info(f'Creating directory {dirname} for {fname}')
2860 try:
2861 # use makedirs to create intermediate missing dirs
2862 os.makedirs(dirname, 0o755)

Callers

nothing calls this directly

Calls 15

acquireMethod · 0.95
ErrorClass · 0.90
is_fsidFunction · 0.90
get_config_and_keyringFunction · 0.90
check_ssh_connectivityFunction · 0.90
get_hostnameFunction · 0.90
get_short_hostnameFunction · 0.90
FileLockClass · 0.90
CephContainerClass · 0.90
extract_uid_gidFunction · 0.90
write_newFunction · 0.90

Tested by

no test coverage detected