def down(self): if engine() == 'podman': run_shell_command( f'{engine_compose()} -f {Config.get("podman_yaml")} down') else: run_shell_command( f'{engine_compose()} -f {Config.get("docker_yaml")} down') print('Successfully killed all boxes')
def main(): Session = sessionmaker() eng = engine() Session.configure(bind=eng) session = Session() if 'KML_BOOTSTRAP' in os.environ: Base.metadata.create_all(eng) insert(parse(src), session)
def get_box_image(): print('Getting box image') if engine() == 'docker': run_shell_command( f'{engine()} build -t cephadm-box -f DockerfileDocker .') else: run_shell_command( f'{engine()} build -t cephadm-box -f DockerfilePodman .') print('Box image added')
def setup(self): if engine() == 'podman': run_shell_command( 'pip3 install https://github.com/containers/podman-compose/archive/devel.tar.gz' ) check_cgroups() check_selinux() get_ceph_image() get_box_image()
def start(self): check_cgroups() check_selinux() osds = Config.get('osds') hosts = Config.get('hosts') # ensure boxes don't exist self.down() # podman is ran without sudo if engine() == 'podman': I_am = run_shell_command('whoami') if 'root' in I_am: print(root_error_msg) sys.exit(1) print('Checking docker images') if not image_exists(CEPH_IMAGE): get_ceph_image() if not image_exists(BOX_IMAGE): get_box_image() used_loop = "" if not Config.get('skip_create_loop'): print( 'Adding logical volumes (block devices) in loopback device...') used_loop = osd.create_loopback_devices(osds) print(f'Added {osds} logical volumes in a loopback device') loop_device_arg = "" if used_loop: loop_device_arg = f'--device {used_loop} -v /dev/vg1:/dev/vg1:Z' for o in range(osds): loop_device_arg += f' --device /dev/dm-{o}' print('Starting containers') if engine() == 'docker': dcflags = f'-f {Config.get("docker_yaml")}' if not os.path.exists('/sys/fs/cgroup/cgroup.controllers'): dcflags += f' -f {Config.get("docker_v1_yaml")}' run_shell_command( f'{engine_compose()} {dcflags} up --scale hosts={hosts} -d') else: run_shell_command( f'{engine_compose()} -f {Config.get("podman_yaml")} --podman-run-args "--group-add keep-groups --network=host --device /dev/fuse -it {loop_device_arg}" up --scale hosts={hosts} -d' ) run_shell_command('sudo sysctl net.ipv4.conf.all.forwarding=1') run_shell_command('sudo iptables -P FORWARD ACCEPT') # don't update clock with chronyd / setup chronyd on all boxes chronyd_setup = """ sed 's/$OPTIONS/-x/g' /usr/lib/systemd/system/chronyd.service -i systemctl daemon-reload systemctl start chronyd systemctl status --no-pager chronyd """ for h in range(hosts): run_dc_shell_commands(h + 1, 'hosts', chronyd_setup) run_dc_shell_commands(1, 'seed', chronyd_setup) print('Seting up host ssh servers') for h in range(hosts): host._setup_ssh('hosts', h + 1) host._setup_ssh('seed', 1) verbose = '-v' if Config.get('verbose') else '' skip_deploy = '--skip-deploy-osds' if Config.get( 'skip-deploy-osds') else '' skip_monitoring_stack = ('--skip-monitoring-stack' if Config.get('skip-monitoring-stack') else '') skip_dashboard = '--skip-dashboard' if Config.get( 'skip-dashboard') else '' box_bootstrap_command = ( f'/cephadm/box/box.py {verbose} --engine {engine()} cluster bootstrap ' f'--osds {osds} ' f'--hosts {hosts} ' f'{skip_deploy} ' f'{skip_dashboard} ' f'{skip_monitoring_stack} ') run_dc_shell_command(box_bootstrap_command, 1, 'seed') info = get_boxes_container_info() ips = info['ips'] hostnames = info['hostnames'] print(ips) host._copy_cluster_ssh_key(ips) expanded = Config.get('expanded') if expanded: host._add_hosts(ips, hostnames) # TODO: add osds if expanded and not Config.get('skip-deploy-osds'): if engine() == 'podman': print('osd deployment not supported in podman') else: print('Deploying osds... This could take up to minutes') osd.deploy_osds_in_vg('vg1') print('Osds deployed') dashboard_ip = 'localhost' info = get_boxes_container_info(with_seed=True) if engine() == 'docker': for i in range(info['size']): if 'seed' in info['container_names'][i]: dashboard_ip = info["ips"][i] print( colored(f'dashboard available at https://{dashboard_ip}:8443', Colors.OKGREEN)) print('Bootstrap finished successfully')
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!')