diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-08-24 16:33:30 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-08-24 16:33:30 +0000 |
| commit | 30fd506e238eb5cd87eda055f9dddbfa1fc059ac (patch) | |
| tree | 62dfc6c321b2cf37c51c157175e3a1797090458a /tools/conf | |
| parent | 626ec25f3cd6995e48b1c8cf88f41621e9735bf5 (diff) | |
| parent | 705ee5e660ed10d2b306677c9db8dc68ad75bd52 (diff) | |
| download | nova-30fd506e238eb5cd87eda055f9dddbfa1fc059ac.tar.gz nova-30fd506e238eb5cd87eda055f9dddbfa1fc059ac.tar.xz nova-30fd506e238eb5cd87eda055f9dddbfa1fc059ac.zip | |
Merge "Don't include hostname and IP in generated sample conf"
Diffstat (limited to 'tools/conf')
| -rw-r--r-- | tools/conf/extract_opts.py | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py index 42fac6969..9445eab87 100644 --- a/tools/conf/extract_opts.py +++ b/tools/conf/extract_opts.py @@ -20,6 +20,7 @@ import os import re +import socket import sys import textwrap @@ -105,11 +106,30 @@ def _list_opts(obj, name): print -def _convert_abspath(s): - """Set up a reasonably sensible default for pybasedir.""" - if not s.startswith(BASEDIR): - return s - return s.replace(BASEDIR, '/usr/lib/python/site-packages') +def _get_my_ip(): + try: + csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + csock.connect(('8.8.8.8', 80)) + (addr, port) = csock.getsockname() + csock.close() + return addr + except socket.error: + return None + + +MY_IP = _get_my_ip() +HOST = socket.gethostname() + + +def _sanitize_default(s): + """Set up a reasonably sensible default for pybasedir, my_ip and host.""" + if s.startswith(BASEDIR): + return s.replace(BASEDIR, '/usr/lib/python/site-packages') + elif s == MY_IP: + return '10.0.0.1' + elif s == HOST: + return 'nova' + return s def _wrap(msg, indent): @@ -133,7 +153,7 @@ def _print_opt(opt): print '# %s=<None>' % opt_name elif opt_type == STROPT: assert(isinstance(opt_default, basestring)) - print '# %s=%s' % (opt_name, _convert_abspath(opt_default)) + print '# %s=%s' % (opt_name, _sanitize_default(opt_default)) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) print '# %s=%s' % (opt_name, str(opt_default).lower()) |
