summaryrefslogtreecommitdiff
path: root/Propellor
diff options
context:
space:
mode:
authorJoey Hess2014-04-18 17:38:21 -0400
committerJoey Hess2014-04-18 17:38:21 -0400
commit80caa6c09d8c15f0ed5d3ce147869b67c0c9f2a8 (patch)
treebe1b133d3675ddcf802ecdbc09e6547a845314e3 /Propellor
parent39d697ca789c04da07bb14cc7476899e717d9413 (diff)
my secondary dns server now uses Ip Attrs
Diffstat (limited to 'Propellor')
-rw-r--r--Propellor/Attr.hs20
-rw-r--r--Propellor/Types/Dns.hs4
2 files changed, 24 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`
diff --git a/Propellor/Types/Dns.hs b/Propellor/Types/Dns.hs
index 4b5925c1..026920fb 100644
--- a/Propellor/Types/Dns.hs
+++ b/Propellor/Types/Dns.hs
@@ -60,6 +60,10 @@ data Record
| TXT String
deriving (Read, Show, Eq, Ord)
+getIPAddr :: Record -> Maybe IPAddr
+getIPAddr (Address addr) = Just addr
+getIPAddr _ = Nothing
+
-- | Bind serial numbers are unsigned, 32 bit integers.
type SerialNumber = CInt