Skip to content

Commit

Permalink
Trying something
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Dec 12, 2023
1 parent bfaafa7 commit de7d203
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions cylc/flow/hostuserutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,28 @@ def get_host_ip_by_name(target):
"""Return internal IP address of target."""
return socket.gethostbyname(target)

@staticmethod
def resolve_macos_ip6_fqdn(target: str) -> str:
"""Python's socket bindings don't play nicely with MacOS
so we sometimes get an ip6.arpa address from
socket.getfqdn.
Note that this does *not* match `hostname -f`.
https://github.com/cylc/cylc-flow/issues/2689
https://github.com/cylc/cylc-flow/issues/3768
"""
if IS_MAC_OS and target == (
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'0.0.0.0.0.0.ip6.arpa'
):
return socket.gethostname()
return target

def _get_host_info(self, target=None):
"""Return the extended info of the current host."""
if target not in self._host_exs:
if target is None:
target = socket.getfqdn()
if (
IS_MAC_OS
and target == (
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.'
'0.0.0.0.0.0.ip6.arpa'
)
):
# Python's socket bindings don't play nicely with mac os
# so by default we get the above ip6.arpa address from
# socket.getfqdn, note this does *not* match `hostname -f`.
# https://github.com/cylc/cylc-flow/issues/2689
# https://github.com/cylc/cylc-flow/issues/3595
target = socket.gethostname()
target = self.resolve_macos_ip6_fqdn(socket.getfqdn())
try:
self._host_exs[target] = socket.gethostbyname_ex(target)
except IOError as exc:
Expand Down Expand Up @@ -202,12 +206,15 @@ def is_remote_host(self, name):
self._remote_hosts[name] = False
else:
try:
host_info = self._get_host_info(name)
ip_addr = socket.gethostbyname(name)
except IOError:
self._remote_hosts[name] = True
else:
self._remote_hosts[name] = (
host_info != self._get_host_info())
ip_addr != socket.gethostbyname(
self.resolve_macos_ip6_fqdn(socket.getfqdn())
)
)
return self._remote_hosts[name]

def is_remote_user(self, name):
Expand Down

0 comments on commit de7d203

Please sign in to comment.