Skip to content

Instantly share code, notes, and snippets.

@alistairncoles
Created September 9, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alistairncoles/5d1662059dc8a4d1f64743169780589f to your computer and use it in GitHub Desktop.
Save alistairncoles/5d1662059dc8a4d1f64743169780589f to your computer and use it in GitHub Desktop.
Playing with oslo config to parse a swift conf file
diff --git a/swift/config.py b/swift/config.py
new file mode 100644
index 0000000..1c7526d
--- /dev/null
+++ b/swift/config.py
@@ -0,0 +1,45 @@
+import json
+from oslo.config import cfg
+
+
+FILE_OPTIONS = {
+ None: [
+ cfg.StrOpt('anc1', secret=False, default='dflt',
+ help='blah')],
+ 'proxy': [cfg.StrOpt('anc2', default='dflt2')]
+}
+
+
+def setup_config():
+ conf = cfg.CONF
+
+ for section in FILE_OPTIONS:
+ for option in FILE_OPTIONS[section]:
+ if section:
+ conf.register_opt(option, group=section)
+ else:
+ conf.register_opt(option)
+
+ config_files = ['/etc/swift/proxy-server.conf']
+
+ conf(args=[],
+ project='swift',
+ version='0.0.TODO',
+ default_config_files=config_files)
+
+ print 'ANC %s' % conf.anc1
+ print 'ANC %s' % conf.proxy.anc2
+
+
+def dump_config():
+ conf = cfg.CONF
+ out = {}
+ for key in conf.keys():
+ out[key] = {}
+ try:
+ section = conf.get(key)
+ for item in section.keys():
+ out[key][item] = section.get(item)
+ except AttributeError:
+ out[key] = str(conf.get(key)) + ' EXC'
+ return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment