diff options
author | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2007-10-03 13:24:58 -0400 |
---|---|---|
committer | Adrian Likins <alikins@grimlock.devel.redhat.com> | 2007-10-03 13:24:58 -0400 |
commit | 2854c6c80ce947eaac7d50c207a15ae77852f612 (patch) | |
tree | 6898e38b36dd52c7a56d5e42a89d8798211fc32d /func/minion/utils.py | |
parent | 63e937cf144f0c61811bb6d842cfc22838a6b851 (diff) | |
download | func-2854c6c80ce947eaac7d50c207a15ae77852f612.tar.gz func-2854c6c80ce947eaac7d50c207a15ae77852f612.tar.xz func-2854c6c80ce947eaac7d50c207a15ae77852f612.zip |
should help fix some of the problems people were seeing when running
on machines where the hostname appeared to be "localhost"
Diffstat (limited to 'func/minion/utils.py')
-rwxr-xr-x | func/minion/utils.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/func/minion/utils.py b/func/minion/utils.py index eceb90f..d13808e 100755 --- a/func/minion/utils.py +++ b/func/minion/utils.py @@ -25,12 +25,52 @@ from func import certs from func.config import read_config from func.commonconfig import FuncdConfig +# "localhost" is a lame hostname to use for a key, so try to get +# a more meaningful hostname. We do this by connecting to the certmaster +# and seeing what interface/ip it uses to make that connection, and looking +# up the hostname for that. +def get_hostname(): + + # FIXME: this code ignores http proxies (which granted, we don't + # support elsewhere either. It also hardcodes the port number + # for the certmaster for now + hostname = None + hostname = socket.gethostname() + ip = socket.gethostbyname(hostname) + if ip != "127.0.0.1": + return hostname + + + config_file = '/etc/func/minion.conf' + config = read_config(config_file, FuncdConfig) + + server = config.certmaster + port = 51235 + + try: + s = socket.socket() + s.settimeout(5) + s.connect((server, port)) + (intf, port) = s.getsockname() + hostname = socket.gethostbyaddr(intf)[0] + s.close() + except: + s.close() + raise + + return hostname + + + def create_minion_keys(): config_file = '/etc/func/minion.conf' config = read_config(config_file, FuncdConfig) cert_dir = config.cert_dir master_uri = 'http://%s:51235/' % config.certmaster - hn = socket.getfqdn() + hn = get_hostname() + + if hn is None: + raise codes.FuncException("Could not determine a hostname other than localhost") key_file = '%s/%s.pem' % (cert_dir, hn) csr_file = '%s/%s.csr' % (cert_dir, hn) |