oslo.config库是openstack读取配置的一个公共库,其实它就是是一套解析配置文件的框架。
[root@devstack oslo_config_practice]# cat app.py # 来看个例子 from oslo_config import cfg # 创建一个组 test_group_1 = cfg.OptGroup(name='DEFAULT', title='group1') # 再创建一个组 test_group_2 = cfg.OptGroup(name='nova', title='group2') group1_opts = [ cfg.BoolOpt('enable_tunneling', default=False, help=('True enables, False disables')), cfg.IPOpt('bind_host', default='0.0.0.0', help='IP address the API server will listen on.'), cfg.StrOpt('query_scope', default='one', choices=['one', 'sub'], help='The LDAP scope for queries, "one" represents ' 'oneLevel/singleLevel and "sub" represents ' 'subtree/wholeSubtree options.'), cfg.StrOrIPOpt('glance_api_host', default='localhost', help='glance api server fqdn'), ] group2_opts = [ cfg.StrOpt('bind_address', default='0.0.0.0', help=('Server listen on.')), cfg.ListOpt('service_plugins', default=[], help=("The service plugins Neutron will use")), cfg.DictOpt('notification_service_id', default={'mysql': '2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b', 'percona': 'fd1723f5-68d2-409c-994f-a4a197892a17', 'pxc': '75a628c3-f81b-4ffb-b10a-4087c26bc854', 'redis': 'b216ffc5-1947-456c-a4cf-70f94c05f7d0', 'cassandra': '459a230d-4e97-4344-9067-2a54a310b0ed', 'couchbase': 'fa62fe68-74d9-4779-a24e-36f19602c415', 'mongodb': 'c8c907af-7375-456f-b929-b637ff9209ee', 'postgresql': 'ac277e0d-4f21-40aa-b347-1ea31e571720', 'couchdb': 'f0a9ab7b-66f7-4352-93d7-071521d44c7c', 'vertica': 'a8d805ae-a3b2-c4fd-gb23-b62cee5201ae', 'db2': 'e040cd37-263d-4869-aaa6-c62aa97523b5', 'mariadb': '7a4f82cc-10d2-4bc6-aadc-d9aacc2a3cb5'}, help='Unique ID to tag notification events.'), cfg.IntOpt('glance_request_timeout', default=None, help='http/https timeout value for glance operations. If no ' 'value (None) is supplied here, the glanceclient default ' 'value is used.'), cfg.PortOpt('bind_port', default=9696, help=("The port to bind to")), cfg.FloatOpt('pi', default=0.0, help=('The value of Pi')), cfg.MultiStrOpt('osapi_volume_extension', default=['cinder.api.contrib.standard_extensions'], help='osapi volume extension to load') ] CONF = cfg.CONF CONF.register_group(test_group_1) # 登记test_group_1 CONF.register_opts(group1_opts, test_group_1) # 配置项登记到test_group_1 CONF.register_group(test_group_2) # 登记test_group_2 CONF.register_opts(group2_opts, test_group_2) # 配置项登记到test_group_2 if __name__ == "__main__": CONF(default_config_files=[ 'app_1.conf', 'app_2.conf']) print('(DEFAULT) enable_tunneling: {}'.format(CONF.DEFAULT.enable_tunneling)) print('(DEFAULT) bind_host: {}'.format(CONF.DEFAULT.bind_host)) print('(DEFAULT) query_scope: {}'.format(CONF.DEFAULT.query_scope)) print('(DEFAULT) glance_api_host: {}'.format(CONF.DEFAULT.glance_api_host)) print('(nova) bind_address:{}'.format(CONF.nova.bind_address)) print('(nova) service_plugins: {}'.format(CONF.nova.service_plugins)) print('(nova) notification_service_id: {}'.format(CONF.nova.notification_service_id)) print('(nova) glance_request_timeout: {}'.format(CONF.nova.glance_request_timeout)) print('(nova) bind_port: {}'.format(CONF.nova.bind_port)) print('(nova) pi: {}'.format(CONF.nova.pi)) print('(nova) osapi_volume_extension: {}'.format(CONF.nova.osapi_volume_extension)) [root@devstack oslo_config_practice]# cat app_1.conf [DEFAULT] enable_tunneling = true bind_host = 192.168.1.1 query_scope = one glance_api_host = 102.34.43.5 [root@devstack oslo_config_practice]# cat app_2.conf [nova] bind_address = 127.0.0.1 service_plugins = ['router','lb'] notification_service_id = {'mysql': '2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b'} glance_request_timeout = 300 bind_port = 9696 pi = 3.14 osapi_volume_extension = cinder.api.contrib.standard_extensions osapi_volume_extension = cinder.api.contrib.standard_extensions_2222
参考链接
http://docs.openstack.org/developer/oslo.config/
http://ronaldbradford.com/blog/understanding-the-different-openstack-tox-configs-2015-04-30/ tox使用教程