MCPcopy
hub / github.com/saltstack/salt / fqdns

Function fqdns

salt/modules/network.py:2136–2210  ·  view source on GitHub ↗

Return all known FQDNs for the system by enumerating all interfaces and then trying to reverse resolve them (excluding 'lo' interface). CLI Example: .. code-block:: bash salt '*' network.fqdns

()

Source from the content-addressed store, hash-verified

2134
2135
2136def fqdns():
2137 """
2138 Return all known FQDNs for the system by enumerating all interfaces and
2139 then trying to reverse resolve them (excluding 'lo' interface).
2140
2141 CLI Example:
2142
2143 .. code-block:: bash
2144
2145 salt '*' network.fqdns
2146 """
2147 # Provides:
2148 # fqdns
2149
2150 # Possible value for h_errno defined in netdb.h
2151 HOST_NOT_FOUND = 1
2152 NO_DATA = 4
2153
2154 fqdns = set()
2155
2156 def _lookup_fqdn(ip):
2157 # Random sleep between 0.005 and 0.025 to avoid hitting
2158 # the GLIBC race condition.
2159 # For more info, see:
2160 # https://sourceware.org/bugzilla/show_bug.cgi?id=19329
2161 time.sleep(random.randint(5, 25) / 1000)
2162 try:
2163 return [socket.getfqdn(socket.gethostbyaddr(ip)[0])]
2164 except socket.herror as err:
2165 if err.errno in (0, HOST_NOT_FOUND, NO_DATA):
2166 # No FQDN for this IP address, so we don't need to know this all the time.
2167 log.debug("Unable to resolve address %s: %s", ip, err)
2168 else:
2169 log.error("Failed to resolve address %s: %s", ip, err)
2170 except Exception as err: # pylint: disable=broad-except
2171 log.error("Failed to resolve address %s: %s", ip, err)
2172
2173 start = time.time()
2174
2175 addresses = salt.utils.network.ip_addrs(
2176 include_loopback=False, interface_data=salt.utils.network._get_interfaces()
2177 )
2178 addresses.extend(
2179 salt.utils.network.ip_addrs6(
2180 include_loopback=False, interface_data=salt.utils.network._get_interfaces()
2181 )
2182 )
2183
2184 # Create a ThreadPool to process the underlying calls to
2185 # 'socket.gethostbyaddr' in parallel. This avoid blocking the execution
2186 # when the "fqdn" is not defined for certains IP addresses, which was
2187 # causing that "socket.timeout" was reached multiple times sequentially,
2188 # blocking execution for several seconds.
2189 try:
2190 with concurrent.futures.ThreadPoolExecutor(8) as pool:
2191 future_lookups = {
2192 pool.submit(_lookup_fqdn, address): address for address in addresses
2193 }

Callers

nothing calls this directly

Calls 6

timeMethod · 0.80
debugMethod · 0.80
setFunction · 0.70
extendMethod · 0.45
updateMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected