summaryrefslogtreecommitdiffstats
path: root/tools/conf
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2012-08-23 10:38:58 +0100
committerMark McLoughlin <markmc@redhat.com>2012-08-23 11:49:15 +0100
commit705ee5e660ed10d2b306677c9db8dc68ad75bd52 (patch)
treec5c351d3d60ea7256460ce81654b471701d7d8ab /tools/conf
parent9fecad9e6f7803f3422e7769c01ba3b9076ed308 (diff)
downloadnova-705ee5e660ed10d2b306677c9db8dc68ad75bd52.tar.gz
nova-705ee5e660ed10d2b306677c9db8dc68ad75bd52.tar.xz
nova-705ee5e660ed10d2b306677c9db8dc68ad75bd52.zip
Don't include hostname and IP in generated sample conf
Avoid including the hostname and IP address of the machine generating the sample config file. Change-Id: Idf791efef8b0bf760c4c95f6f5f53d20bdf5ee7a
Diffstat (limited to 'tools/conf')
-rw-r--r--tools/conf/extract_opts.py32
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py
index 44ae2b000..a65a4bd2d 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
@@ -100,11 +101,30 @@ def _print_module(mod_str):
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):
@@ -128,7 +148,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())