def _add_hosts(ips: Union[List[str], str], hostnames: Union[List[str], str]): if inside_container(): assert len(ips) == len(hostnames) for i in range(len(ips)): run_cephadm_shell_command( f'ceph orch host add {hostnames[i]} {ips[i]}') else: print('Redirecting to _add_hosts to container') verbose = '-v' if Config.get('verbose') else '' print(ips) ips = ' '.join(ips) ips = f'{ips}' hostnames = ' '.join(hostnames) hostnames = f'{hostnames}' run_dc_shell_command( f'/cephadm/box/box.py {verbose} host add_hosts 1 --ips {ips} --hostnames {hostnames}', 1, 'seed', )
def get_lvm_osd_data(data: str) -> Dict[str, str]: osd_lvm_info = run_cephadm_shell_command(f'ceph-volume lvm list {data}') osd_data = {} for line in osd_lvm_info.split('\n'): line = line.strip() if not line: continue line = line.split() if line[0].startswith('===') or line[0].startswith('[block]'): continue # "block device" key -> "block_device" key = '_'.join(line[:-1]) osd_data[key] = line[-1] return osd_data
def deploy_osd(data: str, hostname: str): run_cephadm_shell_command(f'ceph orch daemon add osd "{hostname}:{data}"')
def bootstrap(self): print('Running bootstrap on seed') cephadm_path = os.environ.get('CEPHADM_PATH') os.symlink('/cephadm/cephadm', cephadm_path) if engine() == 'docker': # restart to ensure docker is using daemon.json run_shell_command('systemctl restart docker') st = os.stat(cephadm_path) os.chmod(cephadm_path, st.st_mode | stat.S_IEXEC) run_shell_command( f'{engine()} load < /cephadm/box/docker/ceph/image/quay.ceph.image.tar' ) # cephadm guid error because it sometimes tries to use quay.ceph.io/ceph-ci/ceph:<none> # instead of main branch's tag run_shell_command('export CEPH_SOURCE_FOLDER=/ceph') run_shell_command( 'export CEPHADM_IMAGE=quay.ceph.io/ceph-ci/ceph:main') run_shell_command( 'echo "export CEPHADM_IMAGE=quay.ceph.io/ceph-ci/ceph:main" >> ~/.bashrc' ) extra_args = [] extra_args.append('--skip-pull') # cephadm prints in warning, let's redirect it to the output so shell_command doesn't # complain extra_args.append('2>&0') extra_args = ' '.join(extra_args) skip_monitoring_stack = ('--skip-monitoring-stack' if Config.get('skip-monitoring-stack') else '') skip_dashboard = '--skip-dashboard' if Config.get( 'skip-dashboard') else '' fsid = Config.get('fsid') config_folder = Config.get('config_folder') config = Config.get('config') keyring = Config.get('keyring') if not os.path.exists(config_folder): os.mkdir(config_folder) cephadm_bootstrap_command = ('$CEPHADM_PATH --verbose bootstrap ' '--mon-ip "$(hostname -i)" ' '--allow-fqdn-hostname ' '--initial-dashboard-password admin ' '--dashboard-password-noupdate ' '--shared_ceph_folder /ceph ' '--allow-overwrite ' f'--output-config {config} ' f'--output-keyring {keyring} ' f'--output-config {config} ' f'--fsid "{fsid}" ' '--log-to-file ' f'{skip_dashboard} ' f'{skip_monitoring_stack} ' f'{extra_args} ') print('Running cephadm bootstrap...') run_shell_command(cephadm_bootstrap_command) print('Cephadm bootstrap complete') run_shell_command('sudo vgchange --refresh') run_shell_command('cephadm ls') run_shell_command('ln -s /ceph/src/cephadm/box/box.py /usr/bin/box') run_cephadm_shell_command('ceph -s') print('Bootstrap completed!')
def deploy_osd(data: str, hostname: str) -> bool: out = run_cephadm_shell_command(f'ceph orch daemon add osd "{hostname}:{data}"') return 'Created osd(s)' in out
def bootstrap(self): print('Running bootstrap on seed') cephadm_path = os.environ.get('CEPHADM_PATH') os.symlink('/cephadm/cephadm', cephadm_path) run_shell_command('systemctl restart docker') # restart to ensure docker is using daemon.json st = os.stat(cephadm_path) os.chmod(cephadm_path, st.st_mode | stat.S_IEXEC) run_shell_command('docker load < /cephadm/box/docker/ceph/image/quay.ceph.image.tar') # cephadm guid error because it sometimes tries to use quay.ceph.io/ceph-ci/ceph:<none> # instead of master's tag run_shell_command('export CEPH_SOURCE_FOLDER=/ceph') run_shell_command('export CEPHADM_IMAGE=quay.ceph.io/ceph-ci/ceph:master') run_shell_command('echo "export CEPHADM_IMAGE=quay.ceph.io/ceph-ci/ceph:master" >> ~/.bashrc') extra_args = [] shared_ceph_folder = os.environ.get('SHARED_CEPH_FOLDER') if shared_ceph_folder: extra_args.extend(['--shared_ceph_folder', shared_ceph_folder]) extra_args.append('--skip-pull') # cephadm prints in warning, let's redirect it to the output so shell_command doesn't # complain extra_args.append('2>&0') extra_args = ' '.join(extra_args) skip_monitoring_stack = '--skip_monitoring_stack' if Config.get('skip_monitoring_stack') else '' skip_dashboard = '--skip_dashboard' if Config.get('skip_dashboard') else '' fsid = Config.get('fsid') config_folder = Config.get('config_folder') config = Config.get('config') mon_config = Config.get('mon_config') keyring = Config.get('keyring') if not os.path.exists(config_folder): os.mkdir(config_folder) cephadm_bootstrap_command = ( '$CEPHADM_PATH --verbose bootstrap ' '--mon-ip "$(hostname -i)" ' '--allow-fqdn-hostname ' '--initial-dashboard-password admin ' '--dashboard-password-noupdate ' '--shared_ceph_folder /ceph ' '--allow-overwrite ' f'--output-config {config} ' f'--output-keyring {keyring} ' f'--output-config {config} ' f'--fsid "{fsid}" ' '--log-to-file ' f'{skip_dashboard} ' f'{skip_monitoring_stack} ' f'{extra_args} ' ) print('Running cephadm bootstrap...') run_shell_command(cephadm_bootstrap_command) print('Cephadm bootstrap complete') run_shell_command('sudo vgchange --refresh') run_shell_command('cephadm ls') run_shell_command('ln -s /ceph/src/cephadm/box/box.py /usr/bin/box') hostname = run_shell_command('hostname') # NOTE: sometimes cephadm in the box takes a while to update the containers # running in the cluster and it cannot deploy the osds. In this case # run: box -v osd deploy --vg vg1 to deploy osds again. if not Config.get('skip_deploy_osds'): print('Deploying osds...') osds = Config.get('osds') for o in range(osds): osd.deploy_osd(f'vg1/lv{o}', hostname) print('Osds deployed') run_cephadm_shell_command('ceph -s') print('Bootstrap completed!')