From 6fb45673d03f6d49a2de0896ad7ce9e4b3d335aa Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 1 Jan 2015 13:42:34 -0400 Subject: propellor spin --- src/Propellor/Spin.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index c2fde99e..42f7bf7b 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -96,29 +96,27 @@ spin target relay hst = do -- the host in it at all, use one of the Host's IPs instead. getSshTarget :: HostName -> Host -> IO String getSshTarget target hst - | isJust configip = go =<< tryIO (BSD.getHostByName target) + | null configips = go =<< tryIO (BSD.getHostByName target) | otherwise = return target where go (Left e) = useip (show e) - go (Right hostentry) = ifM (anyM matchingtarget (BSD.hostAddresses hostentry)) + go (Right hostentry) = ifM (anyM matchingconfig (BSD.hostAddresses hostentry)) ( return target , do ips <- mapM inet_ntoa (BSD.hostAddresses hostentry) - useip ("DNS " ++ show ips ++ " /= configured " ++ show (maybeToList configip)) + useip ("DNS " ++ show ips ++ " vs configured " ++ show configips) ) - matchingtarget a = (==) target <$> inet_ntoa a + matchingconfig a = flip elem configips <$> inet_ntoa a - useip why = case configip of + useip why = case headMaybe configips of Nothing -> return target Just ip -> do warningMessage $ "DNS seems out of date for " ++ target ++ " (" ++ why ++ "); using IP address from configuration instead." return ip - configip = case mapMaybe getIPAddr (S.toList (_dns (hostInfo hst))) of - [] -> Nothing - (IPv4 a:_) -> Just a - (IPv6 a:_) -> Just a + configips = map fromIPAddr $ mapMaybe getIPAddr $ + S.toList $ _dns $ hostInfo hst -- Update the privdata, repo url, and git repo over the ssh -- connection, talking to the user's local propellor instance which is -- cgit v1.2.3