example

# config.conf

[DEFAULT]
name = testname
bind_host = 127.0.0.1
bind_port = 20018

[rabbit]
host = 127.0.0.1
# port = 6789

#!/usr/bin/env python
# -*-coding:utf-8 -*-

from oslo_config import cfg
from oslo_config import types

CONF = cfg.CONF

PortType = types.Integer(1, 65535)

common_opt = cfg.StrOpt('name', default='test', help='')

common_opts = [
    cfg.StrOpt('bind_host',
               default='0.0.0.0',
               required=True,
               help='IP address to listen on.'),
    cfg.Opt('bind_port',
            type=PortType,
            default=9292,
            help='Port number to listen on.')
]

CONF.register_cli_opt(common_opt)
CONF.register_cli_opts(common_opts)


rabbit_group = cfg.OptGroup(name='rabbit',
                            title='RabbitMQ options')

rabbit_opts = [
    cfg.StrOpt('host',
               default='localhost',
               help='IP/hostname to listen on.'),
    cfg.PortOpt('port',
                default=5672,
                help='Port number to listen on.')
]

CONF.register_group(rabbit_group)
# options can be registered under a group in either of these ways:
CONF.register_opts(rabbit_opts, rabbit_group)


CONF(default_config_files=['config.conf'])

print CONF.name, CONF.bind_host, CONF.bind_port
print CONF.rabbit.host, CONF.rabbit.port

官方文档