mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 09:23:56 +00:00
Merge pull request #11674 from terminalmage/fix-get_fqhostname
Fix traceback in salt.utils.network.get_fqhostname
This commit is contained in:
commit
4f8fa1241d
@ -89,10 +89,25 @@ def get_fqhostname():
|
||||
if h_name.find('.') >= 0:
|
||||
return h_name
|
||||
else:
|
||||
family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(
|
||||
try:
|
||||
addrinfo = socket.getaddrinfo(
|
||||
h_name, 0, socket.AF_UNSPEC, socket.SOCK_STREAM,
|
||||
socket.SOL_TCP, socket.AI_CANONNAME)[0]
|
||||
return canonname
|
||||
socket.SOL_TCP, socket.AI_CANONNAME
|
||||
)[0]
|
||||
except IndexError:
|
||||
# Handle possible empty struct returns
|
||||
return 'localhost'
|
||||
except socket.gaierror:
|
||||
return 'localhost'
|
||||
else:
|
||||
# Struct contanis the following elements:
|
||||
# family, socktype, proto, canonname, sockaddr
|
||||
try:
|
||||
# Prevent returning an empty string by falling back to
|
||||
# 'localhost'
|
||||
return addrinfo[3] or 'localhost'
|
||||
except IndexError:
|
||||
return 'localhost'
|
||||
|
||||
|
||||
def ip_to_host(ip):
|
||||
|
Loading…
Reference in New Issue
Block a user