secondaryFor

This commit is contained in:
Joey Hess 2014-04-19 01:55:32 -04:00
parent f10c4d4aff
commit f4c0df84ee
2 changed files with 24 additions and 10 deletions

View File

@ -2,6 +2,7 @@ module Propellor.Property.Dns (
module Propellor.Types.Dns,
primary,
secondary,
secondaryFor,
mkSOA,
rootAddressesFrom,
writeZoneFile,
@ -71,10 +72,23 @@ primary hosts domain soa rs = withwarnings (check needupdate baseprop)
-- | Secondary dns server for a domain.
--
-- The primary server is determined by looking at the properties of other
-- hosts to find which one is configured as the primary.
--
-- Note that if a host is declared to be a primary and a secondary dns
-- server for the same domain, the primary server config always wins.
secondary :: [Host] -> Domain -> HostName -> Property
secondary hosts domain master = pureAttrProperty desc (addNamedConf conf)
secondary :: [Host] -> Domain -> Property
secondary hosts domain = secondaryFor masters hosts domain
where
masters = M.keys $ M.filter ismaster $ hostAttrMap hosts
ismaster attr = case M.lookup domain (_namedconf attr) of
Nothing -> False
Just conf -> confType conf == Master && confDomain conf == domain
-- | This variant is useful if the primary server does not have its DNS
-- configured via propellor.
secondaryFor :: [HostName] -> [Host] -> Domain -> -> Property
secondaryFor masters hosts domain = pureAttrProperty desc (addNamedConf conf)
`requires` servingZones
where
desc = "dns secondary for " ++ domain
@ -82,7 +96,7 @@ secondary hosts domain master = pureAttrProperty desc (addNamedConf conf)
{ confDomain = domain
, confType = Secondary
, confFile = "db." ++ domain
, confMasters = hostAddresses master hosts
, confMasters = concatMap (\m -> hostAddresses m hosts) masters
, confLines = ["allow-transfer { }"]
}

View File

@ -246,15 +246,15 @@ cleanCloudAtCost = propertyList "cloudatcost cleanup"
myDnsSecondary :: Property
myDnsSecondary = propertyList "dns secondary for all my domains"
[ Dns.secondary hosts "kitenet.net" master
, Dns.secondary hosts "joeyh.name" master
, Dns.secondary hosts "ikiwiki.info" master
, Dns.secondary hosts "olduse.net" master
, Dns.secondary hosts "branchable.com" branchablemaster
[ Dns.secondaryFor wren hosts "kitenet.net"
, Dns.secondaryFor wren hosts "joeyh.name"
, Dns.secondaryFor wren hosts "ikiwiki.info"
, Dns.secondary hosts "olduse.net"
, Dns.secondaryFor branchable hosts "branchable.com"
]
where
master = "wren.kitenet.net"
branchablemaster = "branchable.com"
wren = ["wren.kitenet.net"]
branchable = ["branchable.com"]
main :: IO ()
main = defaultMain hosts