def validate_hostname(hostname):
"""
Validates that the Foreman API uses a FQDN as hostname.
Also looks up the "real" hostname if "localhost" is specified.
Otherwise, the picky Foreman API won't connect.
:param hostname: the hostname to validate
:type hostname: str
"""
if hostname == "localhost":
#get real hostname
hostname = socket.gethostname()
else:
#convert to FQDN if possible:
fqdn = socket.gethostbyaddr(hostname)
if "." in fqdn[0]:
hostname = fqdn[0]
return hostname
评论列表
文章目录