ceph-deploy的admin 命令

ceph-deploy的admin命令指定了位置参数client用于将conf_data和keyring文件写到远端的host中
其入口在E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\admin.py
@priority(70)
def make(parser):
    """
    Push configuration and client.admin key to a remote host.
    """
    parser.add_argument(
        'client',
        metavar='HOST',
        nargs='+',
        help='host to configure for Ceph administration',
        )
    parser.set_defaults(
        func=admin,
        )
这里的装饰器priority定义如下,本例中用于将Client 这个命令的优先级设置为70
def priority(num):
    """
    Decorator to add a `priority` attribute to the function.
    """
    def add_priority(fn):
        fn.priority = num
        return fn
    return add_priority
在make函数中调用parser。其参数nargs="+" 表示一次可以指定多个client,parse的set_defaults 设置对client命令处理的函数是admin
def admin(args):
#打开需要写到远端host的配置文件
    conf_data = conf.ceph.load_raw(args)
#将keyring信息读到keyring中
    try:
        with open('%s.client.admin.keyring' % args.cluster, 'rb') as f:
            keyring = f.read()
    except:
        raise RuntimeError('%s.client.admin.keyring not found' %
                           args.cluster)

    errors = 0
#client这个命令可以同时指定几个hostname作为client
    for hostname in args.client:
        LOG.debug('Pushing admin keys and conf to %s', hostname)
        try:
#得到发行版的信息,这里的发行版之前介绍过,例如suse/ubuntu等,然后就可以通过remoto库的remote_module函数来讲conf-data和keyring写到hostname代表的
#远程机器中,这里可以明显看到keyring是写到/etc/ceph/%s.client.admin.keyring 这个文件中,而conf_data是写到args.cluster 文件中
            distro = hosts.get(hostname, username=args.username)

            distro.conn.remote_module.write_conf(
                args.cluster,
                conf_data,
                args.overwrite_conf,
            )

            distro.conn.remote_module.write_file(
                '/etc/ceph/%s.client.admin.keyring' % args.cluster,
                keyring,
                0o600,
            )
#调用remoto库后需要退出,因此remoto是通过socket通讯的,所以需要释放socket占用的资源
            distro.conn.exit()

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

    if errors:
        raise exc.GenericError('Failed to configure %d admin hosts' % errors)
		

你可能感兴趣的:(ceph,python)