예제 #1
0
def deploy_osds_in_vg(vg: str):
    """
    rotate host will deploy each osd in a different host

    deploying osds will not succeed with starting services so this
    makes another process to run on the background
    """
    if inside_container():
        lvs = json.loads(run_shell_command('lvs --reportformat json'))
        # distribute osds per host
        hosts = get_orch_hosts()
        host_index = 0
        for lv in lvs['report'][0]['lv']:
            if lv['vg_name'] == vg:
                deployed = False
                while not deployed:
                    deployed = deploy_osd(
                        f'{vg}/{lv["lv_name"]}', hosts[host_index]['hostname']
                    )
                host_index = (host_index + 1) % len(hosts)
    else:
        verbose = '-v' if Config.get('verbose') else ''
        print('Redirecting deploy osd in vg to inside container')
        run_dc_shell_command(
            f'/cephadm/box/box.py {verbose} osd deploy --vg {vg}', 1, 'seed'
        )
예제 #2
0
def _setup_ssh(container_index):
    if inside_container():
        if not os.path.exists('/root/.ssh/known_hosts'):
            run_shell_command('ssh-keygen -A')

        run_shell_command('echo "root:root" | chpasswd')
        with open('/etc/ssh/sshd_config', 'a+') as f:
            f.write('PermitRootLogin yes\n')
            f.write('PasswordAuthentication yes\n')
            f.flush()
        run_shell_command('/usr/sbin/sshd')
    else:
        print('Redirecting to _setup_ssh to container') 
        verbose = '-v' if Config.get('verbose') else ''
        run_dc_shell_command(f'/cephadm/box/box.py {verbose} host setup_ssh {container_index}', container_index, 'hosts')
예제 #3
0
def _copy_cluster_ssh_key(ips: List[str]):
    if inside_container():
        local_ip = run_shell_command('hostname -i')
        for ip in ips:
            if ip != local_ip:
                run_shell_command(('sshpass -p "root" ssh-copy-id -f '
                                    f'-o StrictHostKeyChecking=no -i /etc/ceph/ceph.pub "root@{ip}"'))

    else:
        print('Redirecting to _copy_cluster_ssh to container') 
        verbose = '-v' if Config.get('verbose') else ''
        print(ips)
        ips = ' '.join(ips)
        ips = f"{ips}"
        # assume we only have one seed
        run_dc_shell_command(f'/cephadm/box/box.py {verbose} host copy_cluster_ssh_key 1 --ips {ips}',
                             1, 'seed')
예제 #4
0
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',
        )
예제 #5
0
def _setup_ssh(container_type, container_index):
    if inside_container():
        if not os.path.exists('/root/.ssh/known_hosts'):
            run_shell_command(
                'ssh-keygen -b 2048 -t rsa -f /root/.ssh/id_rsa -q -N ""')

        run_shell_command('echo "root:root" | chpasswd')
        with open('/etc/ssh/sshd_config', 'a+') as f:
            f.write('PermitRootLogin yes\n')
            f.write('PasswordAuthentication yes\n')
            f.flush()
        run_shell_command('systemctl restart sshd')
    else:
        print('Redirecting to _setup_ssh to container')
        verbose = '-v' if Config.get('verbose') else ''
        run_dc_shell_command(
            f'/cephadm/box/box.py {verbose} --engine {engine()} host setup_ssh {container_type} {container_index}',
            container_index,
            container_type,
        )