ceph-deploy的set_overrides函数

来源:互联网 发布:网站备案域名查询 编辑:程序博客网 时间:2024/06/05 00:15
在E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\cli.py的_main函数中会调用set_overrides来将在配置文件中定义的命令
 args = ceph_deploy.conf.cephdeploy.set_overrides(args)
其实现在E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\conf\cephdeploy.py
def set_overrides(args, _conf=None):
    """
    Read the configuration file and look for ceph-deploy sections
    to set flags/defaults from the values found. This will alter the
    ``args`` object that is created by argparse.
    """
    # Get the subcommand name to avoid overwritting values from other
    # subcommands that are not going to be used
//给subcommand赋值
    subcommand = args.func.__name__
    command_section = 'ceph-deploy-%s' % subcommand
//加载ceph-deploy的配置
    conf = _conf or load()
 
    for section_name in conf.sections():
        if section_name in ['ceph-deploy-global', command_section]:
//如果配置文件中ceph-deploy-global 和 ceph-deploy-%s的话,则写入args中
            override_subcommand(
                section_name,
                conf.items(section_name),
                args
            )
    return args
    
继续看看load()函数
E:\ceph-deploy-master\ceph-deploy-master\ceph_deploy\conf\cephdeploy.py
def load():
    parser = Conf()
//读取解析配置文件
    parser.read(location())
    return parser
看看location
def location():
    """
    Find and return the location of the ceph-deploy configuration file. If this
    file does not exist, create one in a default location.
    """
    return _locate_or_create()
继续调用
def _locate_or_create():
 
    home_config = path.expanduser('~/.cephdeploy.conf')
    # With order of importance
    locations = [
//当前目录下或者~/下存在cephdeploy.conf的话。
        path.join(os.getcwd(), 'cephdeploy.conf'),
        home_config,
    ]
//当前目录下或者~/下存在cephdeploy.conf的话。则返回location这样在load函数中就可以通过parser.read(location())读到配置文件了
    for location in locations:
        if path.exists(location):
            logger.debug('found configuration file at: %s' % location)
            return location
    logger.info('could not find configuration file, will create one in $HOME')
//如果不存在的话在,则在home_config 也就是null,在~/ 目录下新建一个cephdeploy.conf。并把cd_conf_template作为模块写入.
    create_stub(home_config)
    return home_config
 
 
def create_stub(_path=None):
    _path = _path or path.expanduser('~/.cephdeploy.conf')
    logger.debug('creating new configuration file: %s' % _path)
    with open(_path, 'w') as cd_conf:
        cd_conf.write(cd_conf_template)
这里的cd_conf_template 定义如下:正式的cephdeploy.conf 文件和这个模块类似
cd_conf_template = """
#
# ceph-deploy configuration file
#
 
[ceph-deploy-global]
# Overrides for some of ceph-deploy's global flags, like verbosity or cluster
# name
 
[ceph-deploy-install]
# Overrides for some of ceph-deploy's install flags, like version of ceph to
# install
 
 
#
# Repositories section
#
 
# yum repos:
# [myrepo]
# baseurl = http://gitbuilder.ceph.com/ceph-rpm-centos7-x86_64-basic/ref/hammer
# gpgurl = https://download.ceph.com/keys/autobuild.asc
# default = True
# extra-repos = cephrepo  # will install the cephrepo file too
#
# [cephrepo]
# name=ceph repo noarch packages
# baseurl=http://download.ceph.com/rpm-hammer/el6/noarch
# enabled=1
# gpgcheck=1
# type=rpm-md
# gpgkey=https://download.ceph.com/keys/release.asc
 
# apt repos:
# [myrepo]
# baseurl = http://gitbuilder.ceph.com/ceph-deb-trusty-x86_64-basic/ref/hammer
# gpgurl = https://download.ceph.com/keys/autobuild.asc
# default = True
# extra-repos = cephrepo  # will install the cephrepo file too
#
# [cephrepo]
# baseurl=http://download.ceph.com/debian-hammer
# gpgkey=https://download.ceph.com/keys/release.asc
""".format(gpgurl=gpg.url('release'))
原创粉丝点击