コード例 #1
0
def gatherkeys_with_mon(args, host, dest_dir):
    """
    Connect to mon and gather keys if mon is in quorum.
    """
    distro = hosts.get(host, username=args.username)
    remote_hostname = distro.conn.remote_module.shortname()
    dir_keytype_mon = ceph_deploy.util.paths.mon.path(args.cluster,
                                                      remote_hostname)
    path_keytype_mon = "%s/keyring" % (dir_keytype_mon)
    mon_key = distro.conn.remote_module.get_file(path_keytype_mon)
    if mon_key is None:
        LOG.warning("No mon key found in host: %s", host)
        return False
    mon_name_local = keytype_path_to(args, "mon")
    mon_path_local = os.path.join(dest_dir, mon_name_local)
    with open(mon_path_local, 'wb') as f:
        f.write(mon_key)
    rlogger = logging.getLogger(host)
    path_asok = ceph_deploy.util.paths.mon.asok(args.cluster, remote_hostname)
    out, err, code = remoto.process.check(distro.conn, [
        "/usr/bin/ceph", "--connect-timeout=25",
        "--cluster={cluster}".format(cluster=args.cluster),
        "--admin-daemon={asok}".format(asok=path_asok), "mon_status"
    ])
    if code != 0:
        rlogger.error('"ceph mon_status %s" returned %s', host, code)
        for line in err:
            rlogger.debug(line)
        return False
    try:
        mon_status = json.loads(b''.join(out).decode('utf-8'))
    except ValueError:
        rlogger.error('"ceph mon_status %s" output was not json', host)
        for line in out:
            rlogger.error(line)
        return False
    mon_number = None
    mon_map = mon_status.get('monmap')
    if mon_map is None:
        rlogger.error("could not find mon map for mons on '%s'", host)
        return False
    mon_quorum = mon_status.get('quorum')
    if mon_quorum is None:
        rlogger.error("could not find quorum for mons on '%s'", host)
        return False
    mon_map_mons = mon_map.get('mons')
    if mon_map_mons is None:
        rlogger.error("could not find mons in monmap on '%s'", host)
        return False
    for mon in mon_map_mons:
        if mon.get('name') == remote_hostname:
            mon_number = mon.get('rank')
            break
    if mon_number is None:
        rlogger.error("could not find '%s' in monmap", remote_hostname)
        return False
    if not mon_number in mon_quorum:
        rlogger.error("Not yet quorum for '%s'", host)
        return False
    for keytype in ["admin", "mds", "osd", "rgw"]:
        if not gatherkeys_missing(args, distro, rlogger, path_keytype_mon,
                                  keytype, dest_dir):
            # We will return failure if we fail to gather any key
            rlogger.error("Failed to return '%s' key from host ", keytype,
                          host)
            return False
    return True
コード例 #2
0
ファイル: gatherkeys.py プロジェクト: SUSE/ceph-deploy
def gatherkeys_with_mon(args, host, dest_dir):
    """
    Connect to mon and gather keys if mon is in quorum.
    """
    distro = hosts.get(host, username=args.username)
    remote_hostname = distro.conn.remote_module.shortname()
    dir_keytype_mon = ceph_deploy.util.paths.mon.path(args.cluster, remote_hostname)
    path_keytype_mon = "%s/keyring" % (dir_keytype_mon)
    mon_key = distro.conn.remote_module.get_file(path_keytype_mon)
    if mon_key is None:
        LOG.warning("No mon key found in host: %s", host)
        return False
    mon_name_local = keytype_path_to(args, "mon")
    mon_path_local = os.path.join(dest_dir, mon_name_local)
    with open(mon_path_local, 'wb') as f:
        f.write(mon_key)
    rlogger = logging.getLogger(host)
    path_asok = ceph_deploy.util.paths.mon.asok(args.cluster, remote_hostname)
    out, err, code = remoto.process.check(
        distro.conn,
            [
                "/usr/bin/ceph",
                "--connect-timeout=25",
                "--cluster={cluster}".format(
                    cluster=args.cluster),
                "--admin-daemon={asok}".format(
                    asok=path_asok),
                "mon_status"
            ]
        )
    if code != 0:
        rlogger.error('"ceph mon_status %s" returned %s', host, code)
        for line in err:
            rlogger.debug(line)
        return False
    try:
        mon_status = json.loads(b''.join(out).decode('utf-8'))
    except ValueError:
        rlogger.error('"ceph mon_status %s" output was not json', host)
        for line in out:
            rlogger.error(line)
        return False
    mon_number = None
    mon_map = mon_status.get('monmap')
    if mon_map is None:
        rlogger.error("could not find mon map for mons on '%s'", host)
        return False
    mon_quorum = mon_status.get('quorum')
    if mon_quorum is None:
        rlogger.error("could not find quorum for mons on '%s'" , host)
        return False
    mon_map_mons = mon_map.get('mons')
    if mon_map_mons is None:
        rlogger.error("could not find mons in monmap on '%s'", host)
        return False
    for mon in mon_map_mons:
        if mon.get('name') == remote_hostname:
           mon_number = mon.get('rank')
           break
    if mon_number is None:
        rlogger.error("could not find '%s' in monmap", remote_hostname)
        return False
    if not mon_number in mon_quorum:
        rlogger.error("Not yet quorum for '%s'", host)
        return False
    for keytype in ["admin", "mds", "osd", "rgw"]:
        if not gatherkeys_missing(args, distro, rlogger, path_keytype_mon, keytype, dest_dir):
            # We will return failure if we fail to gather any key
            rlogger.error("Failed to return '%s' key from host ", keytype, host)
            return False
    return True