+def getlocaldomain(): # get the parent fqdn of current server
+ domain = socket.getfqdn().split('.', 1)
+ if len(domain) == 2:
+ logger.warning('Could not get domain of this server, only hostname. Please consider updating /etc/hosts')
+ return ''
+ else:
+ return domain[-1]
+
+def resolve(ip, fqdn = 'host-only'): # try to resolve an ip to hostname
+ # Possible values for fqdn:
+ # fqdn show full hostname and domain
+ # fqdn-implicit show hostname and domain unless local
+ # host-only only show hostname
+ # ip never resolve anything
+ # resolve-domains defined in individual sections of the config take priority over global config
+
+ if not fqdn:
+ fqdn = config['resolve-domains']
+
+ if fqdn == 'ip':
+ return(ip)