Пример #1
0
def mon_destroy(args):
    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            LOG.debug('Removing mon from %s', name)

            distro = hosts.get(
                host,
                username=args.username,
                callbacks=[packages.ceph_is_installed]
            )
            hostname = distro.conn.remote_module.shortname()

            destroy_mon(
                distro.conn,
                args.cluster,
                hostname,
            )
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to destroy %d monitors' % errors)
Пример #2
0
def mon_destroy(args):
    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            LOG.debug('Removing mon from %s', name)

            distro = hosts.get(
                host,
                username=args.username,
                callbacks=[packages.ceph_is_installed]
            )
            hostname = distro.conn.remote_module.shortname()

            # 删除mon
            destroy_mon(
                distro.conn,
                args.cluster,
                hostname,
            )
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to destroy %d monitors' % errors)
Пример #3
0
    def test_mon_hosts(self):
        hosts = Mock()
        for (name, host) in mon_hosts(('name1', 'name2.localdomain',
                    'name3:1.2.3.6', 'name4:localhost.localdomain')):
            hosts.get(name, host)

        expected = [call.get('name1', 'name1'),
                    call.get('name2', 'name2.localdomain'),
                    call.get('name3', '1.2.3.6'),
                    call.get('name4', 'localhost.localdomain')]
        result = hosts.mock_calls
        assert result == expected
Пример #4
0
def mon_create(args):

    cfg = conf.ceph.load(args)
    if not args.mon:
        args.mon = get_mon_initial_members(args, error_on_empty=True, _cfg=cfg)

    if args.keyrings:
        monitor_keyring = concatenate_keyrings(args)
    else:
        keyring_path = '{cluster}.mon.keyring'.format(cluster=args.cluster)
        try:
            monitor_keyring = files.read_file(keyring_path)
        except IOError:
            LOG.warning('keyring (%s) not found, creating a new one' % keyring_path)
            new_mon_keyring(args)
            monitor_keyring = files.read_file(keyring_path)

    LOG.debug(
        'Deploying mon, cluster %s hosts %s',
        args.cluster,
        ' '.join(args.mon),
        )

    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            # TODO add_bootstrap_peer_hint
            LOG.debug('detecting platform for host %s ...', name)
            distro = hosts.get(
                host,
                username=args.username,
                callbacks=[packages.ceph_is_installed]
            )
            LOG.info('distro info: %s %s %s', distro.name, distro.release, distro.codename)
            rlogger = logging.getLogger(name)

            # ensure remote hostname is good to go
            hostname_is_compatible(distro.conn, rlogger, name)
            rlogger.debug('deploying mon to %s', name)
            distro.mon.create(distro, args, monitor_keyring)

            # tell me the status of the deployed mon
            time.sleep(2)  # give some room to start
            mon_status(distro.conn, rlogger, name, args)
            catch_mon_errors(distro.conn, rlogger, name, cfg, args)
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to create %d monitors' % errors)
Пример #5
0
    def test_mon_hosts(self):
        hosts = Mock()
        for (name, host) in mon_hosts(('name1', 'name2.localdomain',
                    'name3:1.2.3.6', 'name4:localhost.localdomain')):
            hosts.get(name, host)

        expected = [call.get('name1', 'name1'),
                    call.get('name2', 'name2.localdomain'),
                    call.get('name3', '1.2.3.6'),
                    call.get('name4', 'localhost.localdomain')]
        result = hosts.mock_calls
        assert result == expected
Пример #6
0
def mon_create(args):

    cfg = conf.ceph.load(args)
    if not args.mon:
        args.mon = get_mon_initial_members(args, error_on_empty=True, _cfg=cfg)

    if args.keyrings:
        monitor_keyring = concatenate_keyrings(args)
    else:
        keyring_path = '{cluster}.mon.keyring'.format(cluster=args.cluster)
        try:
            monitor_keyring = files.read_file(keyring_path)
        except IOError:
            LOG.warning('keyring (%s) not found, creating a new one' %
                        keyring_path)
            new_mon_keyring(args)
            monitor_keyring = files.read_file(keyring_path)

    LOG.debug(
        'Deploying mon, cluster %s hosts %s',
        args.cluster,
        ' '.join(args.mon),
    )

    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            # TODO add_bootstrap_peer_hint
            LOG.debug('detecting platform for host %s ...', name)
            distro = hosts.get(host,
                               username=args.username,
                               callbacks=[packages.ceph_is_installed])
            LOG.info('distro info: %s %s %s', distro.name, distro.release,
                     distro.codename)
            rlogger = logging.getLogger(name)

            # ensure remote hostname is good to go
            hostname_is_compatible(distro.conn, rlogger, name)
            rlogger.debug('deploying mon to %s', name)
            distro.mon.create(distro, args, monitor_keyring)

            # tell me the status of the deployed mon
            time.sleep(2)  # give some room to start
            mon_status(distro.conn, rlogger, name, args)
            catch_mon_errors(distro.conn, rlogger, name, cfg, args)
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to create %d monitors' % errors)
Пример #7
0
def mon_create(args):

    cfg = conf.ceph.load(args)
    if not args.mon:
        mon_initial_members = cfg.safe_get('global', 'mon_initial_members')
        args.mon = re.split(r'[,\s]+', mon_initial_members)

    if not args.mon:
        raise exc.NeedHostError()

    if args.keyrings:
        monitor_keyring = concatenate_keyrings(args)
    else:
        try:
            with file('{cluster}.mon.keyring'.format(cluster=args.cluster),
                      'rb') as f:
                monitor_keyring = f.read()
        except IOError:
            raise RuntimeError('mon keyring not found; run \'new\' to create a new cluster')

    LOG.debug(
        'Deploying mon, cluster %s hosts %s',
        args.cluster,
        ' '.join(args.mon),
        )

    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            # TODO add_bootstrap_peer_hint
            LOG.debug('detecting platform for host %s ...', name)
            distro = hosts.get(host, username=args.username)
            LOG.info('distro info: %s %s %s', distro.name, distro.release, distro.codename)
            rlogger = logging.getLogger(name)

            # ensure remote hostname is good to go
            hostname_is_compatible(distro.conn, rlogger, name)
            rlogger.debug('deploying mon to %s', name)
            distro.mon.create(distro, args, monitor_keyring)

            # tell me the status of the deployed mon
            time.sleep(2)  # give some room to start
            mon_status(distro.conn, rlogger, name, args)
            catch_mon_errors(distro.conn, rlogger, name, cfg, args)
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to create %d monitors' % errors)
Пример #8
0
def mon_destroy(args):
    errors = 0
    for (name, host) in mon_hosts(args.mon):
        try:
            LOG.debug("Removing mon from %s", name)

            distro = hosts.get(host, username=args.username)
            hostname = distro.conn.remote_module.shortname()

            destroy_mon(distro.conn, args.cluster, hostname)
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError("Failed to destroy %d monitors" % errors)
Пример #9
0
def new(args):
    if args.ceph_conf:
        raise RuntimeError(
            'will not create a Ceph conf file if attemtping to re-use with `--ceph-conf` flag'
        )
    LOG.debug('Creating new cluster named %s', args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section('global')
    cfg.add_section('client')
    cfg.add_section('mon')
    cfg.add_section('osd')

    fsid = args.fsid or uuid.uuid4()
    cfg.set('global', 'fsid', str(fsid))

    # if networks were passed in, lets set them in the
    # global section
    #    if args.public_network:
    #        cfg.set('global', 'public network', str(args.public_network))

    #    if args.cluster_network:
    #        cfg.set('global', 'cluster network', str(args.cluster_network))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        # Try to ensure we can ssh in properly before anything else
        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

        # Now get the non-local IPs from the remote node
        distro = hosts.get(host, username=args.username)
        remote_ips = net.ip_addresses(distro.conn)
        ceph_dir = '/Ceph'
        ceph_mon_dir = '/Ceph/Data/Mon'
        ceph_meta_dir = '/Ceph/Meta/Keyring'
        if not distro.conn.remote_module.path_exists(ceph_dir):
            distro.conn.remote_module.create_ceph_path(ceph_dir, 167, 167)
            distro.conn.remote_module.create_mon_path(ceph_mon_dir, 167, 167)
            distro.conn.remote_module.create_meta_path(ceph_meta_dir, 167, 167)
        # custom cluster names on sysvinit hosts won't work
        if distro.init == 'sysvinit' and args.cluster != 'ceph':
            LOG.error(
                'custom cluster names are not supported on sysvinit hosts')
            raise exc.ClusterNameError(
                'host %s does not support custom cluster names' % host)

        distro.conn.exit()

        # Validate subnets if we received any
        if args.public_network or args.cluster_network:
            validate_host_ip(remote_ips,
                             [args.public_network, args.cluster_network])

        # Pick the IP that matches the public cluster (if we were told to do
        # so) otherwise pick the first, non-local IP
        LOG.debug('Resolving host %s', host)
        if args.public_network:
            ip = get_public_network_ip(remote_ips, args.public_network)
        else:
            ip = net.get_nonlocal_ip(host)
        LOG.debug('Monitor %s at %s', name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')
            cfg.set('global', 'ms bind ipv6', 'true')
        except socket.error:
            mon_host.append(ip)

    LOG.debug('Monitor initial members are %s', mon_initial_members)
    LOG.debug('Monitor addrs are %s', mon_host)

    #cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    #cfg.set('global', 'mon host', ','.join(mon_host))

    cfg.set('global', 'keyring', '/Ceph/Meta/Keyring/$name.keyring')
    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set('global', 'auth cluster required', 'cephx')
    cfg.set('global', 'auth service required', 'cephx')
    cfg.set('global', 'auth client required', 'cephx')

    cfg.set('client', 'rbd cache', 'false')
    cfg.set('client', 'client cache size', '16384000')
    cfg.set('client', 'client_oc_size', '838860800')
    cfg.set('client', 'admin socket', '/var/run/ceph/rbd-client-$pid.asok')
    cfg.set('client', 'log file', '/var/log/ceph/ceph.client.log')

    cfg.set('mon', 'mon clock drift allowed', '0.5')
    cfg.set('mon', 'mon debug dump transactions', 'false')
    cfg.set('mon', 'mon osd max split count', '10000')
    cfg.set('mon', 'mon data', '/Ceph/Data/Mon/mon.$id')

    cfg.set('osd', 'osd crush update on start', 'false')
    cfg.set('osd', 'osd journal size', '10240')
    cfg.set('osd', 'osd new ceph', 'false')
    cfg.set('osd', 'osd max backfills', '1')
    cfg.set('osd', 'osd recovery max active', '1')
    cfg.set('osd', 'osd deep scrub interval', '209018880000')
    cfg.set('osd', 'osd scrub begin hour', '0')
    cfg.set('osd', 'osd scrub end hour', '8')
    cfg.set('osd', 'osd deep scrub primary write', 'false')
    cfg.set('osd', 'osd deep scrub replica write', 'false')
    cfg.set('osd', 'osd max object name len', '256')

    path = '{name}.conf'.format(name=args.cluster, )

    new_mon_keyring(args)

    LOG.debug('Writing initial config to %s...', path)
    tmp = '%s.tmp' % path
    with open(tmp, 'w') as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise
Пример #10
0
def new(args):
    if args.ceph_conf:
        raise RuntimeError(
            'will not create a Ceph conf file if attemtping to re-use with `--ceph-conf` flag'
        )
    LOG.debug('Creating new cluster named %s', args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section('global')

    fsid = args.fsid or uuid.uuid4()
    cfg.set('global', 'fsid', str(fsid))

    # if networks were passed in, lets set them in the
    # global section
    if args.public_network:
        cfg.set('global', 'public network', str(args.public_network))

    if args.cluster_network:
        cfg.set('global', 'cluster network', str(args.cluster_network))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        # Try to ensure we can ssh in properly before anything else
        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

        # Now get the non-local IPs from the remote node
        distro = hosts.get(host, username=args.username)
        remote_ips = net.ip_addresses(distro.conn)

        # custom cluster names on sysvinit hosts won't work
        if distro.init == 'sysvinit' and args.cluster != 'ceph':
            LOG.error(
                'custom cluster names are not supported on sysvinit hosts')
            raise exc.ClusterNameError(
                'host %s does not support custom cluster names' % host)

        distro.conn.exit()

        # Validate subnets if we received any
        if args.public_network or args.cluster_network:
            validate_host_ip(remote_ips,
                             [args.public_network, args.cluster_network])

        # Pick the IP that matches the public cluster (if we were told to do
        # so) otherwise pick the first, non-local IP
        LOG.debug('Resolving host %s', host)
        if args.public_network:
            ip = get_public_network_ip(remote_ips, args.public_network)
        else:
            ip = net.get_nonlocal_ip(host)
        LOG.debug('Monitor %s at %s', name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')
            cfg.set('global', 'ms bind ipv6', 'true')
        except socket.error:
            mon_host.append(ip)

    LOG.debug('Monitor initial members are %s', mon_initial_members)
    LOG.debug('Monitor addrs are %s', mon_host)

    cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    cfg.set('global', 'mon host', ','.join(mon_host))

    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set('global', 'auth cluster required', 'cephx')
    cfg.set('global', 'auth service required', 'cephx')
    cfg.set('global', 'auth client required', 'cephx')

    path = '{name}.conf'.format(name=args.cluster, )

    new_mon_keyring(args)

    LOG.debug('Writing initial config to %s...', path)
    tmp = '%s.tmp' % path
    with open(tmp, 'w') as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise
Пример #11
0
def new(args):
    if args.ceph_conf:
        raise RuntimeError('will not create a ceph conf file if attemtping to re-use with `--ceph-conf` flag')
    LOG.debug('Creating new cluster named %s', args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section('global')

    fsid = args.fsid or uuid.uuid4()
    cfg.set('global', 'fsid', str(fsid))

    # if networks were passed in, lets set them in the
    # global section
    if args.public_network:
        cfg.set('global', 'public network', str(args.public_network))

    if args.cluster_network:
        cfg.set('global', 'cluster network', str(args.cluster_network))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        # Try to ensure we can ssh in properly before anything else
        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

        # Now get the non-local IPs from the remote node
        distro = hosts.get(host, username=args.username)
        remote_ips = net.ip_addresses(distro.conn)
        distro.conn.exit()

        # Validate subnets if we received any
        if args.public_network or args.cluster_network:
            validate_host_ip(remote_ips, [args.public_network, args.cluster_network])

        # Pick the IP that matches the public cluster (if we were told to do
        # so) otherwise pick the first, non-local IP
        LOG.debug('Resolving host %s', host)
        if args.public_network:
            ip = get_public_network_ip(remote_ips, args.public_network)
        else:
            ip = net.get_nonlocal_ip(host)
        LOG.debug('Monitor %s at %s', name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')
            cfg.set('global', 'ms bind ipv6', 'true')
        except socket.error:
            mon_host.append(ip)



    LOG.debug('Monitor initial members are %s', mon_initial_members)
    LOG.debug('Monitor addrs are %s', mon_host)

    cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    cfg.set('global', 'mon host', ','.join(mon_host))

    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set('global', 'auth cluster required', 'cephx')
    cfg.set('global', 'auth service required', 'cephx')
    cfg.set('global', 'auth client required', 'cephx')

    # http://tracker.newdream.net/issues/3138
    cfg.set('global', 'filestore xattr use omap', 'true')

    path = '{name}.conf'.format(
        name=args.cluster,
        )

    # FIXME: create a random key
    LOG.debug('Creating a random mon key...')
    mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % generate_auth_key()

    keypath = '{name}.mon.keyring'.format(
        name=args.cluster,
        )

    LOG.debug('Writing initial config to %s...', path)
    tmp = '%s.tmp' % path
    with file(tmp, 'w') as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise

    LOG.debug('Writing monitor keyring to %s...', keypath)
    tmp = '%s.tmp' % keypath
    with file(tmp, 'w') as f:
        f.write(mon_keyring)
    try:
        os.rename(tmp, keypath)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(keypath)
        else:
            raise
Пример #12
0
def mon_create(args):

    # 获取配置文件
    cfg = conf.ceph.load(args)
    if not args.mon:
        # 参数没指定mon,调用get_mon_initial_members函数从配置文件获取mon_initial_members作为mon
        args.mon = get_mon_initial_members(args, error_on_empty=True, _cfg=cfg)

    if args.keyrings:
        monitor_keyring = concatenate_keyrings(args)
    else:
        keyring_path = '{cluster}.mon.keyring'.format(cluster=args.cluster)
        try:
            # 获取ceph.mon.keyring文件信息
            monitor_keyring = files.read_file(keyring_path)
        except IOError:
            LOG.warning('keyring (%s) not found, creating a new one' % keyring_path)
            new_mon_keyring(args)
            monitor_keyring = files.read_file(keyring_path)

    LOG.debug(
        'Deploying mon, cluster %s hosts %s',
        args.cluster,
        ' '.join(args.mon),
        )

    errors = 0
    # 循环mon
    for (name, host) in mon_hosts(args.mon):
        try:
            # TODO add_bootstrap_peer_hint
            LOG.debug('detecting platform for host %s ...', name)

            # 获取操作系统版本信息,检查是否安装ceph包,如果需要修改代码支持其他操作系统,可以从hosts入手修改
            distro = hosts.get(
                host,
                username=args.username,
                callbacks=[packages.ceph_is_installed]
            )
            LOG.info('distro info: %s %s %s', distro.name, distro.release, distro.codename)
            rlogger = logging.getLogger(name)

            # ensure remote hostname is good to go
            hostname_is_compatible(distro.conn, rlogger, name)
            rlogger.debug('deploying mon to %s', name)
            # 创建mon,调用hosts目录的相应操作系列目录,比如系统是centos,那就是hosts/centos下的mon模块
            distro.mon.create(distro, args, monitor_keyring)

            # tell me the status of the deployed mon
            time.sleep(2)  # give some room to start

            # 检测mon的状态
            mon_status(distro.conn, rlogger, name, args)

            # 检测mon是否在monmap中存在,配置文件中是否配置public_addr、public_network等信息,写入logger warning
            catch_mon_errors(distro.conn, rlogger, name, cfg, args)
            distro.conn.exit()

        except RuntimeError as e:
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to create %d monitors' % errors)
Пример #13
0
def new(args):
    LOG.debug('Creating new cluster named %s', args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section('global')

    fsid = uuid.uuid4()
    cfg.set('global', 'fsid', str(fsid))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        LOG.debug('Resolving host %s', host)
        ip = net.get_nonlocal_ip(host)
        LOG.debug('Monitor %s at %s', name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')
            cfg.set('global', 'ms bind ipv6', 'true')
        except socket.error:
            mon_host.append(ip)

        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

    LOG.debug('Monitor initial members are %s', mon_initial_members)
    LOG.debug('Monitor addrs are %s', mon_host)

    cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    cfg.set('global', 'mon host', ','.join(mon_host))

    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set('global', 'auth cluster required', 'cephx')
    cfg.set('global', 'auth service required', 'cephx')
    cfg.set('global', 'auth client required', 'cephx')

    # http://tracker.newdream.net/issues/3138
    cfg.set('global', 'filestore xattr use omap', 'true')

    path = '{name}.conf'.format(name=args.cluster, )

    # FIXME: create a random key
    LOG.debug('Creating a random mon key...')
    mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % generate_auth_key(
    )

    keypath = '{name}.mon.keyring'.format(name=args.cluster, )

    LOG.debug('Writing initial config to %s...', path)
    tmp = '%s.tmp' % path
    with file(tmp, 'w') as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise

    LOG.debug('Writing monitor keyring to %s...', keypath)
    tmp = '%s.tmp' % keypath
    with file(tmp, 'w') as f:
        f.write(mon_keyring)
    try:
        os.rename(tmp, keypath)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(keypath)
        else:
            raise
Пример #14
0
def new(args):
    LOG.debug('Creating new cluster named %s', args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section('global')

    fsid = uuid.uuid4()
    cfg.set('global', 'fsid', str(fsid))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        LOG.debug('Resolving host %s', host)
        ip = net.get_nonlocal_ip(host)
        LOG.debug('Monitor %s at %s', name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info('Monitors are IPv6, binding Messenger traffic on IPv6')
            cfg.set('global', 'ms bind ipv6', 'true')
        except socket.error:
            mon_host.append(ip)

        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

    LOG.debug('Monitor initial members are %s', mon_initial_members)
    LOG.debug('Monitor addrs are %s', mon_host)

    cfg.set('global', 'mon initial members', ', '.join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    cfg.set('global', 'mon host', ','.join(mon_host))

    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set('global', 'auth cluster required', 'cephx')
    cfg.set('global', 'auth service required', 'cephx')
    cfg.set('global', 'auth client required', 'cephx')

    # http://tracker.newdream.net/issues/3138
    cfg.set('global', 'filestore xattr use omap', 'true')

    path = '{name}.conf'.format(
        name=args.cluster,
        )

    # FIXME: create a random key
    LOG.debug('Creating a random mon key...')
    mon_keyring = '[mon.]\nkey = %s\ncaps mon = allow *\n' % generate_auth_key()

    keypath = '{name}.mon.keyring'.format(
        name=args.cluster,
        )

    LOG.debug('Writing initial config to %s...', path)
    tmp = '%s.tmp' % path
    with file(tmp, 'w') as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise

    LOG.debug('Writing monitor keyring to %s...', keypath)
    tmp = '%s.tmp' % keypath
    with file(tmp, 'w') as f:
        f.write(mon_keyring)
    try:
        os.rename(tmp, keypath)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(keypath)
        else:
            raise
Пример #15
0
def new(args):
    if args.ceph_conf:
        raise RuntimeError("will not create a ceph conf file if attemtping to re-use with `--ceph-conf` flag")
    LOG.debug("Creating new cluster named %s", args.cluster)
    cfg = conf.ceph.CephConf()
    cfg.add_section("global")

    fsid = args.fsid or uuid.uuid4()
    cfg.set("global", "fsid", str(fsid))

    mon_initial_members = []
    mon_host = []

    for (name, host) in mon_hosts(args.mon):
        LOG.debug("Resolving host %s", host)
        ip = net.get_nonlocal_ip(host)
        LOG.debug("Monitor %s at %s", name, ip)
        mon_initial_members.append(name)
        try:
            socket.inet_pton(socket.AF_INET6, ip)
            mon_host.append("[" + ip + "]")
            LOG.info("Monitors are IPv6, binding Messenger traffic on IPv6")
            cfg.set("global", "ms bind ipv6", "true")
        except socket.error:
            mon_host.append(ip)

        if args.ssh_copykey:
            ssh_copy_keys(host, args.username)

    LOG.debug("Monitor initial members are %s", mon_initial_members)
    LOG.debug("Monitor addrs are %s", mon_host)

    cfg.set("global", "mon initial members", ", ".join(mon_initial_members))
    # no spaces here, see http://tracker.newdream.net/issues/3145
    cfg.set("global", "mon host", ",".join(mon_host))

    # override undesirable defaults, needed until bobtail

    # http://tracker.ceph.com/issues/6788
    cfg.set("global", "auth cluster required", "cephx")
    cfg.set("global", "auth service required", "cephx")
    cfg.set("global", "auth client required", "cephx")

    # http://tracker.newdream.net/issues/3138
    cfg.set("global", "filestore xattr use omap", "true")

    path = "{name}.conf".format(name=args.cluster)

    # FIXME: create a random key
    LOG.debug("Creating a random mon key...")
    mon_keyring = "[mon.]\nkey = %s\ncaps mon = allow *\n" % generate_auth_key()

    keypath = "{name}.mon.keyring".format(name=args.cluster)

    LOG.debug("Writing initial config to %s...", path)
    tmp = "%s.tmp" % path
    with file(tmp, "w") as f:
        cfg.write(f)
    try:
        os.rename(tmp, path)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(path)
        else:
            raise

    LOG.debug("Writing monitor keyring to %s...", keypath)
    tmp = "%s.tmp" % keypath
    with file(tmp, "w") as f:
        f.write(mon_keyring)
    try:
        os.rename(tmp, keypath)
    except OSError as e:
        if e.errno == errno.EEXIST:
            raise exc.ClusterExistsError(keypath)
        else:
            raise
Пример #16
0
def mon_create(args):

    cfg = conf.ceph.load(args)
    if not args.mon:
        args.mon = get_mon_initial_members(args, error_on_empty=True, _cfg=cfg)

    if args.keyrings:
        monitor_keyring = concatenate_keyrings(args)
    else:
        keyring_path = '/root/{cluster}.mon.keyring'.format(cluster=args.cluster)
        try:
            monitor_keyring = files.read_file(keyring_path)
        except IOError:
            LOG.warning('keyring (%s) not found, creating a new one' % keyring_path)
            new_mon_keyring(args)
            monitor_keyring = files.read_file(keyring_path)

    LOG.debug(
        'Deploying mon, cluster %s hosts %s',
        args.cluster,
        ' '.join(args.mon),
        )

    errors = 0
    mon_no = None
    for (name, host) in mon_hosts(args.mon):
        try:
            # TODO add_bootstrap_peer_hint
            LOG.debug('detecting platform for host %s ...', name)
            distro = hosts.get(
                host,
                username=args.username,
                callbacks=[packages.ceph_is_installed]
            )
            LOG.info('distro info: %s %s %s', distro.name, distro.release, distro.codename)
            rlogger = logging.getLogger(name)

            # ensure remote hostname is good to go
            hostname_is_compatible(distro.conn, rlogger, name)
            LOG.debug('write mon config to /etc/ceph.conf')
            mon_ip = net.get_nonlocal_ip(name)
            LOG.debug('get host ip : %s', mon_ip)
            LOG.debug('Create:add mon to ceph.conf')
            mon_no = add_mon_conf(name, mon_ip)
            rlogger.debug('deploying mon to %s ,mon_index : %s', name, mon_no.split('.')[1])
            distro.mon.create(distro, args, monitor_keyring, mon_no.split('.')[1])

            # tell me the status of the deployed mon
            time.sleep(5)  # give some room to start
            mon_status(distro.conn, rlogger, mon_no.split('.')[1], args)
            catch_mon_errors(distro.conn, rlogger, name, mon_no.split('.')[1], cfg, args)
            distro.conn.exit()

        except RuntimeError as e:
            del_conf(mon_no)
            LOG.error(e)
            errors += 1

    if errors:
        raise exc.GenericError('Failed to create %d monitors' % errors)
    # cp clientkey for create osd
    cmd = "cp /Ceph/Meta/Keyring/client.admin.keyring /root/"
    (ret, out) = commands.getstatusoutput(cmd)
    # start sync all monitors ceph.conf
    conf_data = conf.ceph.load_raw(args)
    errnos = 0
    for (name, host) in mon_hosts(args.mon):
        LOG.debug('sync configfile for host %s ...', name)
        try:
            distro = hosts.get(host, username=args.username)
            distro.conn.remote_module.write_conf(
                args.cluster,
                conf_data,
                args.overwrite_conf,
            )
            distro.conn.exit()
        except RuntimeError as e:
            LOG.error(e)
            errnos += 1
    if errnos:
        raise exc.GenericError('Failed to sync configfile %d monitors' % errors)