美文网首页
oslo_config

oslo_config

作者: lmem | 来源:发表于2017-04-13 11:08 被阅读109次
from oslo_config import cfg

opt_simple_group = cfg.OptGroup(name='simple', title='A Simple Example')
opt_morestuff_group = cfg.OptGroup(name='morestuff', title='A More Complex Example')

simple_opts = [
    cfg.BoolOpt('enable', default=False, help=('True enables, False disables'))
]

morestuff_opts = [
    cfg.StrOpt('message', default='No data', help=('A message')),
    cfg.ListOpt('usernames', default=None, help=('A list of usernames')),
    cfg.DictOpt('jobtitles', default=None, help=('A dictionary of usernames titles')),
    cfg.IntOpt('payday', default=30, help=('Default payday monthly date')),
    cfg.FloatOpt('pi', default=0.0, help=('The value of Pi'))
]
#get conf
CONF = cfg.CONF

#register group
CONF.register_group(opt_simple_group)
CONF.register_opts(simple_opts, opt_simple_group)

CONF.register_group(opt_morestuff_group)
CONF.register_opts(morestuff_opts, opt_morestuff_group)

if __name__ == "__main__":
    CONF(default_config_files=['app.conf'])
    print('(simple)enable: {}'.format(CONF.simple.enable))
    print('(morestuff) message :{}'.format(CONF.morestuff.message))
    print('(morestuff) usernames: {}'.format(CONF.morestuff.usernames))
    print('(morestuff) jobtitles: {}'.format(CONF.morestuff.jobtitles))
    print('(morestuff) payday: {}'.format(CONF.morestuff.payday))
    print('(morestuff) pi: {}'.format(CONF.morestuff.pi))
    for i in CONF.morestuff.usernames:
        print  i

app.conf

[simple]
enable = True

[morestuff]
#StrOpt
message = Hello World
#ListOpt
usernames = ['Joe', 'Jessica', 'Peter']
# DictOpt
usermetadata = {'Joe': 'Manager', 'Jessica': 'CEO', 'Peter': 'Security Guard'}
#IntOpt
payday = 20
#FloatOpt
pi = 3.14

相关文章

  • oslo: oslo_log解析

    oslo_config介绍了oslo_config组件的使用说明。本章中,介绍oslo_log的使用。oslo_l...

  • oslo_config

    app.conf

  • oslo_config 项目

    使用oslo_config项目来管理配置文件,下面算是一个Hello World。

  • oslo: oslo_config组件解析

    OpenStack中大量使用了一些第三方组件,为了使一些基础组件的接口的统一及更友好的使用,Openstack利用...

网友评论

      本文标题:oslo_config

      本文链接:https://www.haomeiwen.com/subject/rbcbattx.html