summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-05-29 08:27:05 +0100
committerMark McLoughlin <markmc@redhat.com>2012-05-29 08:27:05 +0100
commit141fe5b9741296f72b0695a85089fd1a0b2c2173 (patch)
tree9c734c76e43862cc41e5fe8783f5dd868a13974f /openstack/common
parent3308e123ad4a0699e95e209dcd94cb0dedf7e63b (diff)
downloadoslo-141fe5b9741296f72b0695a85089fd1a0b2c2173.tar.gz
oslo-141fe5b9741296f72b0695a85089fd1a0b2c2173.tar.xz
oslo-141fe5b9741296f72b0695a85089fd1a0b2c2173.zip
cfg: add a global CONF object
Implements blueprint cfg-global-object Add an instance of the CommonConfigOpts class to the cfg module's global namespace. The usage pattern is: from openstack.common import cfg opts = [ cfg.StrOpt('foo', default='blaa'), cfg.StrOpt('bar', default='blaa'), ] CONF = cfg.CONF CONF.register_opts(opts) def do_something_later(): print CONF.foo, CONF.bar def main(): CONF(project='pulsar') Change-Id: I77e87b1e186c243b2638a4b1c202f865249dafce
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/cfg.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/openstack/common/cfg.py b/openstack/common/cfg.py
index 0e7f615..66aeb3c 100644
--- a/openstack/common/cfg.py
+++ b/openstack/common/cfg.py
@@ -233,6 +233,22 @@ log files:
...
]
+This module also contains a global instance of the CommonConfigOpts class
+in order to support a common usage pattern in OpenStack:
+
+ from openstack.common import cfg
+
+ opts = [
+ cfg.StrOpt('bind_host' default='0.0.0.0'),
+ cfg.IntOpt('bind_port', default=9292),
+ ]
+
+ CONF = cfg.CONF
+ CONF.register_opts(opts)
+
+ def start(server, app):
+ server.start(app, CONF.bind_port, CONF.bind_host)
+
"""
import collections
@@ -1540,3 +1556,6 @@ class CommonConfigOpts(ConfigOpts):
super(CommonConfigOpts, self).__init__()
self.register_cli_opts(self.common_cli_opts)
self.register_cli_opts(self.logging_cli_opts)
+
+
+CONF = CommonConfigOpts()