X-Git-Url: https://pwan.org/git/?p=certmaster.git;a=blobdiff_plain;f=certmaster%2Futils.py;h=3dec6a54a283fc699d466da2723100137c297449;hp=7927c555e388e199ed3876b57a1f017c524acbd7;hb=613a485c4798b38a65042e9d78968896c590fdd0;hpb=d6dfdb25c4e8be31d77ba8db7c3499e3f10e0c4b diff --git a/certmaster/utils.py b/certmaster/utils.py index 7927c55..3dec6a5 100755 --- a/certmaster/utils.py +++ b/certmaster/utils.py @@ -75,7 +75,7 @@ def is_error(result): return True return False -def get_hostname(): +def get_hostname(talk_to_certmaster=True): """ "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 @@ -94,23 +94,23 @@ def get_hostname(): if ip != "127.0.0.1": return hostname + if talk_to_certmaster: + config_file = '/etc/certmaster/minion.conf' + config = read_config(config_file, MinionConfig) - config_file = '/etc/certmaster/minion.conf' - config = read_config(config_file, MinionConfig) - - server = config.certmaster - port = 51235 + 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 + 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