summaryrefslogtreecommitdiff
path: root/Propellor/Attr.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Propellor/Attr.hs')
-rw-r--r--Propellor/Attr.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/Propellor/Attr.hs b/Propellor/Attr.hs
index 21736588..f3e2e2e5 100644
--- a/Propellor/Attr.hs
+++ b/Propellor/Attr.hs
@@ -9,6 +9,7 @@ import Propellor.Types.Dns
import "mtl" Control.Monad.Reader
import qualified Data.Set as S
import qualified Data.Map as M
+import Data.Maybe
import Control.Applicative
pureAttrProperty :: Desc -> SetAttr -> Property
@@ -28,6 +29,20 @@ os system = pureAttrProperty ("Operating " ++ show system) $
getOS :: Propellor (Maybe System)
getOS = asks _os
+-- | Indidate that a host has an A record in the DNS.
+--
+-- TODO check at run time if the host really has this address.
+-- (Can't change the host's address, but as a sanity check.)
+ipv4 :: String -> Property
+ipv4 addr = pureAttrProperty ("ipv4 " ++ addr)
+ (addDNS $ Address $ IPv4 addr)
+
+-- | Indidate that a host has an AAAA record in the DNS.
+ipv6 :: String -> Property
+ipv6 addr = pureAttrProperty ("ipv6 " ++ addr)
+ (addDNS $ Address $ IPv6 addr)
+
+-- | Indicate that a host has a CNAME pointing at it in the DNS.
cname :: Domain -> Property
cname domain = pureAttrProperty ("cname " ++ domain)
(addDNS $ CNAME $ AbsDomain domain)
@@ -62,6 +77,11 @@ hostMap l = M.fromList $ zip (map (_hostname . hostAttr) l) l
findHost :: [Host] -> HostName -> Maybe Host
findHost l hn = M.lookup hn (hostMap l)
+getAddresses :: HostName -> [Host] -> [IPAddr]
+getAddresses hn hosts = case hostAttr <$> findHost hosts hn of
+ Nothing -> []
+ Just attr -> mapMaybe getIPAddr $ S.toList $ _dns attr
+
-- | Lifts an action into a different host.
--
-- For example, `fromHost hosts "otherhost" getSshPubKey`