Example #1
0
def cleanup_environment(env_id):
    env = objects.Environment(env_id)

    nodes = env.get_all_nodes()
    for node in nodes:
        node_util.remove_compute_upgrade_levels(node)

    controller = env_util.get_one_controller(env)
    sftp = ssh.sftp(controller)
    admin_pass = env_util.get_admin_password(env, controller)
    script_filename = 'clean_env.py'

    with ssh.tempdir(controller) as tempdir:
        script_src_filename = os.path.join(magic_consts.CWD, "helpers",
                                           script_filename)
        script_dst_filename = os.path.join(tempdir, script_filename)
        sftp.put(script_src_filename, script_dst_filename)

        command = [
            'sh',
            '-c',
            '. /root/openrc; export OS_PASSWORD={0}; python {1}'.format(
                admin_pass, script_dst_filename),
        ]

        with ssh.popen(command, node=controller, stdin=ssh.PIPE) as proc:
            roles = ["controller", "compute"]
            for node in env_util.get_nodes(env, roles):
                data = "{0}\n{1}\n".format(node.data['fqdn'].split('.')[0],
                                           node.data['fqdn'])
                proc.stdin.write(data)
Example #2
0
def cleanup_environment(env_id):
    env = objects.Environment(env_id)

    controller = env_util.get_one_controller(env)
    sftp = ssh.sftp(controller)
    admin_pass = env_util.get_admin_password(env, controller)
    script_filename = 'clean_env.py'

    with ssh.tempdir(controller) as tempdir:
        script_src_filename = os.path.join(
            magic_consts.CWD, "helpers", script_filename)
        script_dst_filename = os.path.join(tempdir, script_filename)
        sftp.put(script_src_filename, script_dst_filename)

        command = [
            'sh', '-c', '. /root/openrc; export OS_PASSWORD={0}; python {1}'
            .format(admin_pass, script_dst_filename),
        ]

        with ssh.popen(command, node=controller, stdin=ssh.PIPE) as proc:
            roles = ["controller", "compute"]
            for node in env_util.get_nodes(env, roles):
                data = "{0}\n{1}\n".format(node.data['fqdn'].split('.')[0],
                                           node.data['fqdn'])
                proc.stdin.write(data)
Example #3
0
 def evacuate_host(self):
     controller = env_util.get_one_controller(self.env)
     with ssh.tempdir(controller) as tempdir:
         local_path = os.path.join(
             magic_consts.CWD, 'bin', 'host_evacuation.sh')
         remote_path = os.path.join(tempdir, 'host_evacuation.sh')
         sftp = ssh.sftp(controller)
         sftp.put(local_path, remote_path)
         sftp.chmod(remote_path, stat.S_IRWXO)
         ssh.call(
             [remote_path, 'node-{0}'.format(self.node.data['id'])],
             node=controller,
         )
Example #4
0
 def evacuate_host(self):
     controller = env_util.get_one_controller(self.env)
     with ssh.tempdir(controller) as tempdir:
         local_path = os.path.join(magic_consts.CWD, 'bin',
                                   'host_evacuation.sh')
         remote_path = os.path.join(tempdir, 'host_evacuation.sh')
         sftp = ssh.sftp(controller)
         sftp.put(local_path, remote_path)
         sftp.chmod(remote_path, stat.S_IRWXO)
         ssh.call(
             [remote_path, 'node-{0}'.format(self.node.data['id'])],
             node=controller,
         )
Example #5
0
def ceph_set_new_mons(seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))
    hostnames = map(short_hostname, node_util.get_hostnames(nodes))
    mgmt_ips = map(remove_mask, node_util.get_ips('management', nodes))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()
        conf = replace_addresses(conf, hostnames, mgmt_ips)

    fsid = get_fsid(conf)
    monmaptool_cmd = ['monmaptool', '--fsid', fsid, '--clobber', '--create']
    for node_hostname, node_ip in itertools.izip(hostnames, mgmt_ips):
        monmaptool_cmd += ['--add', node_hostname, node_ip]

    for node, node_hostname in itertools.izip(nodes, hostnames):
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        node_conf = replace_host(conf, node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        ssh.call(['rm', '-rf', node_db_path], node=node)
        node_util.untar_files(filename, node)
        sftp = ssh.sftp(node)
        with sftp.open(conf_filename, 'w') as f:
            f.write(node_conf)
        ssh.call(['mv', db_path, node_db_path], node=node)

        sysvinit = os.path.join(node_db_path, 'sysvinit')
        try:
            sftp.remove(sysvinit)
        except IOError:
            pass
        upstart = os.path.join(node_db_path, 'upstart')
        sftp.open(upstart, 'w').close()

        with ssh.tempdir(node) as tempdir:
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(monmaptool_cmd + [monmap_filename], node=node)
            ssh.call([
                'ceph-mon', '-i', node_hostname, '--inject-monmap',
                monmap_filename
            ],
                     node=node)

    for node, node_hostname in itertools.izip(nodes, hostnames):
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])
Example #6
0
def ceph_set_new_mons(seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))
    hostnames = map(short_hostname, node_util.get_hostnames(nodes))
    mgmt_ips = map(remove_mask, node_util.get_ips('management', nodes))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()
        conf = replace_addresses(conf, hostnames, mgmt_ips)

    fsid = get_fsid(conf)
    monmaptool_cmd = ['monmaptool', '--fsid', fsid, '--clobber', '--create']
    for node_hostname, node_ip in itertools.izip(hostnames, mgmt_ips):
        monmaptool_cmd += ['--add', node_hostname, node_ip]

    for node, node_hostname in itertools.izip(nodes, hostnames):
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        node_conf = replace_host(conf, node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        ssh.call(['rm', '-rf', node_db_path], node=node)
        node_util.untar_files(filename, node)
        sftp = ssh.sftp(node)
        with sftp.open(conf_filename, 'w') as f:
            f.write(node_conf)
        ssh.call(['mv', db_path, node_db_path], node=node)

        sysvinit = os.path.join(node_db_path, 'sysvinit')
        try:
            sftp.remove(sysvinit)
        except IOError:
            pass
        upstart = os.path.join(node_db_path, 'upstart')
        sftp.open(upstart, 'w').close()

        with ssh.tempdir(node) as tempdir:
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(monmaptool_cmd + [monmap_filename], node=node)
            ssh.call(['ceph-mon', '-i', node_hostname, '--inject-monmap',
                      monmap_filename], node=node)

    for node, node_hostname in itertools.izip(nodes, hostnames):
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])
Example #7
0
def ceph_set_new_mons(orig_env, seed_env, filename, conf_filename, db_path):
    nodes = list(env_util.get_controllers(seed_env))

    with contextlib.closing(tarfile.open(filename)) as f:
        conf = f.extractfile(conf_filename).read()

    fsid = get_fsid(conf)

    for node in nodes:
        node_hostname = short_hostname(node.data['fqdn'])
        node_db_path = "/var/lib/ceph/mon/ceph-{0}".format(node_hostname)
        try:
            ssh.call(['stop', 'ceph-mon', "id={0}".format(node_hostname)],
                     node=node)
        except subprocess.CalledProcessError:
            pass
        with ssh.tempdir(node) as tempdir:
            # save current seed conf and monmap in tmp dir
            monmap_filename = os.path.join(tempdir, 'monmap')
            ssh.call(["ceph-mon", "-i", node_hostname,
                     "--extract-monmap", monmap_filename], node=node)
            seed_conf_path = os.path.join(tempdir, "ceph.conf")
            ssh.call(['cp', conf_filename, seed_conf_path], node=node)

            ssh.call(['rm', '-rf', node_db_path], node=node)
            node_util.untar_files(filename, node)

            # return seed ceph confs
            ssh.call(['cp', seed_conf_path, conf_filename], node=node)
            # change fsid for orig fsid value
            change_fsid(conf_filename, node, fsid)
            # change fsid value in monmap
            ssh.call(["monmaptool", "--fsid", fsid,
                      "--clobber", monmap_filename], node=node)
            ssh.call(['mv', db_path, node_db_path], node=node)
            if version.StrictVersion(orig_env.data["fuel_version"]) < \
                    version.StrictVersion(magic_consts.CEPH_UPSTART_VERSION):
                _activate_upstart_instead_sysvinit(node, db_path, node_db_path)
            # return old monmap value
            ssh.call(['ceph-mon', '-i', node_hostname,
                      '--inject-monmap', monmap_filename], node=node)
        ssh.call(['start', 'ceph-mon', "id={0}".format(node_hostname)],
                 node=node)
    import_bootstrap_osd(nodes[0])