From 80caa6c09d8c15f0ed5d3ce147869b67c0c9f2a8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 18 Apr 2014 17:38:21 -0400 Subject: my secondary dns server now uses Ip Attrs --- Propellor/Attr.hs | 20 ++++++++++++++++++++ Propellor/Types/Dns.hs | 4 ++++ 2 files changed, 24 insertions(+) (limited to 'Propellor') 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 -- cgit v1.2.3