Commit baecc91f authored by Klaus Aehlig's avatar Klaus Aehlig
Browse files

Add version of getFQDN accepting preferences



Still the best way to get the "canonical name" of a host
is to look up its host name and reverse look up the IP
address obtained. Obviously, that the result depends
on the protocol family used. So accept hints on which
family to prefer.

Note that getFQDN is exported on higher branches, so we
keep its type stable to avoid semantic merge conflicts.
Signed-off-by: default avatarKlaus Aehlig <aehlig@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent cf1bf3ad
...@@ -308,10 +308,10 @@ vClusterHostNameEnvVar :: String ...@@ -308,10 +308,10 @@ vClusterHostNameEnvVar :: String
vClusterHostNameEnvVar = "GANETI_HOSTNAME" vClusterHostNameEnvVar = "GANETI_HOSTNAME"
-- | Get the real full qualified host name. -- | Get the real full qualified host name.
getFQDN' :: IO String getFQDN' :: Maybe Socket.AddrInfo -> IO String
getFQDN' = do getFQDN' hints = do
hostname <- getHostName hostname <- getHostName
addrInfos <- Socket.getAddrInfo Nothing (Just hostname) Nothing addrInfos <- Socket.getAddrInfo hints (Just hostname) Nothing
let address = listToMaybe addrInfos >>= (Just . Socket.addrAddress) let address = listToMaybe addrInfos >>= (Just . Socket.addrAddress)
case address of case address of
Just a -> do Just a -> do
...@@ -319,9 +319,10 @@ getFQDN' = do ...@@ -319,9 +319,10 @@ getFQDN' = do
return (fromMaybe hostname fqdn) return (fromMaybe hostname fqdn)
Nothing -> return hostname Nothing -> return hostname
-- | Return the full qualified host name, honoring the vcluster setup. -- | Return the full qualified host name, honoring the vcluster setup
getFQDN :: IO String -- and hints on the preferred socket type or protocol.
getFQDN = do getFQDNwithHints :: Maybe Socket.AddrInfo -> IO String
getFQDNwithHints hints = do
let ioErrorToNothing :: IOError -> IO (Maybe String) let ioErrorToNothing :: IOError -> IO (Maybe String)
ioErrorToNothing _ = return Nothing ioErrorToNothing _ = return Nothing
vcluster_node <- Control.Exception.catch vcluster_node <- Control.Exception.catch
...@@ -329,7 +330,11 @@ getFQDN = do ...@@ -329,7 +330,11 @@ getFQDN = do
ioErrorToNothing ioErrorToNothing
case vcluster_node of case vcluster_node of
Just node_name -> return node_name Just node_name -> return node_name
Nothing -> getFQDN' Nothing -> getFQDN' hints
-- | Return the full qualified host name, honoring the vcluster setup.
getFQDN :: IO String
getFQDN = getFQDNwithHints Nothing
-- | Returns if the current node is the master node. -- | Returns if the current node is the master node.
isMaster :: IO Bool isMaster :: IO Bool
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment