Cleans up the create_conf tool

* Makes it adhere to the config file format
 * Puts the sample output in etc/nova/nova.conf.sample
 * Updating sample is as easy as ./tools/conf/generate_sample.sh

Change-Id: I01e72cb58dd598a74f50c2c17f102d24df325f2e
This commit is contained in:
Vishvananda Ishaya 2012-03-06 16:08:33 -08:00
parent 52d2ba8237
commit 6ee8a083f0
4 changed files with 1116 additions and 19 deletions

1088
etc/nova/nova.conf.sample Normal file

File diff suppressed because it is too large Load Diff

View File

@ -44,9 +44,6 @@ class NovaConfigOpts(cfg.CommonConfigOpts):
with flagfile.handle_flagfiles_managed(argv[1:]) as args:
return argv[:1] + super(NovaConfigOpts, self).__call__(args)
def retrieve_opt(self, opt_name, group=None):
return self._get_opt_info(opt_name, group)
FLAGS = NovaConfigOpts()

View File

@ -16,9 +16,7 @@
# License for the specific language governing permissions and limitations
# under the License.
"""Generates a nova.conf file.
"""
"""Generates a nova.conf file."""
import os
import re
@ -52,9 +50,12 @@ def main(srcfiles):
"console", "consoleauth", "image"]
return prefer.index(pkg_str) if pkg_str in prefer else ord(pkg_str[0])
print '#', 'nova.conf sample\n'
print '#' * 20 + '\n# nova.conf sample #\n' + '#' * 20
# NOTE(lzyeval): sort top level modules and packages
# to process modules first
print
print '[DEFAULT]'
print
mods_by_pkg = dict()
for filepath in srcfiles:
pkg_name = filepath.split(os.sep)[3]
@ -96,14 +97,14 @@ def print_module(mod_str):
# check if option was processed
if opt_name in _OPTION_CACHE:
continue
opt_dict = flags.retrieve_opt(opt_name)
opt_dict = flags._get_opt_info(opt_name)
opts.append(opt_dict['opt'])
_OPTION_CACHE.append(opt_name)
# return if flags has no unique options
if not opts:
return
# print out module info
print ''.join(['[', mod_str, ']'])
print '######### defined in %s #########' % mod_str
print
for opt in opts:
print_opt(opt)
@ -118,16 +119,21 @@ def print_opt(opt):
sys.stderr.write("%s\n" % str(err))
sys.exit(1)
# print out option info
print "#", "".join(["(", opt_type, ")"]), opt.help
if opt_type == _BOOLOPT:
print "# default: %s" % opt.default
print "#", ''.join(["--", opt.name])
print "######", "".join(["(", opt_type, ")"]), opt.help
if opt.default is None:
print '# %s=<None>' % opt.name
else:
opt_value = str(opt.default)
if (opt.default is None or (opt_type == _STROPT and not opt.default)):
opt_value = "<%s>" % opt.name
print "#", ''.join(["--", opt.name, "=", opt_value])
print
if opt_type == 'StrOpt':
print '# %s="%s"' % (opt.name, opt.default)
elif opt_type == 'ListOpt':
print '# %s="%s"' % (opt.name, ','.join(opt.default))
elif opt_type == 'MultiStrOpt':
for default in opt.default:
print '# %s="%s"' % (opt.name, default)
elif opt_type == 'BoolOpt':
print '# %s=%s' % (opt.name, str(opt.default).lower())
else:
print '# %s=%s' % (opt.name, opt.default)
if __name__ == '__main__':

View File

@ -1,3 +1,4 @@
#!/usr/bin/env bash
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 SINA Corporation
@ -15,5 +16,10 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
pushd $(cd $(dirname "$0") && pwd) >/dev/null
find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec grep -l "Opt(" {} \; | sort -u | xargs python create_conf.py > nova.conf.sample
find ../../nova -type f -name "*.py" ! -path "../../nova/tests/*" -exec \
grep -l "Opt(" {} \; | sort -u | xargs python create_conf.py > \
../../etc/nova/nova.conf.sample
popd >/dev/null