From 266cbceb19197d4dd2c95bd2c62c79d23ae95ef9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 26 Jul 2017 16:20:23 -0400 Subject: propellor spin --- src/Propellor/Property/Network.hs | 29 ++++++++++++++++++++++++++--- src/Propellor/Property/OS.hs | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/Network.hs b/src/Propellor/Property/Network.hs index 9ed9e591..0e47b88f 100644 --- a/src/Propellor/Property/Network.hs +++ b/src/Propellor/Property/Network.hs @@ -39,7 +39,30 @@ dhcp iface = tightenTargets $ hasContent (interfaceDFile iface) `describe` ("dhcp " ++ iface) `requires` interfacesDEnabled --- | Writes a static interface file for the specified interface. +newtype Gateway = Gateway IPAddr + +-- | Configures an interface with a static address and gateway. +static :: Interface -> IPAddr -> Maybe Gateway-> Property DebianLike +static iface addr gateway = + tightenTargets $ hasContent (interfaceDFile iface) ls + `describe` ("static IP address for " ++ iface) + `requires` interfacesDEnabled + where + ls = catMaybes + [ Just $ "auto " ++ iface + , Just $ "iface " ++ iface ++ " " ++ inet ++ " static" + , Just $ "\taddress" ++ val addr + , case gateway of + Just (Gateway gaddr) -> + Just $ "\tgateway" ++ val gaddr + Nothing -> Nothing + ] + inet = case addr of + IPv4 _ -> "inet" + IPv6 _ -> "inet6" + +-- | Writes a static interface file for the specified interface +-- to preserve its current configuration. -- -- The interface has to be up already. It could have been brought up by -- DHCP, or by other means. The current ipv4 addresses @@ -50,8 +73,8 @@ dhcp iface = tightenTargets $ hasContent (interfaceDFile iface) -- -- (ipv6 addresses are not included because it's assumed they come up -- automatically in most situations.) -static :: Interface -> Property DebianLike -static iface = tightenTargets $ +preserveStatic :: Interface -> Property DebianLike +preserveStatic iface = tightenTargets $ check (not <$> doesFileExist f) setup `describe` desc `requires` interfacesDEnabled diff --git a/src/Propellor/Property/OS.hs b/src/Propellor/Property/OS.hs index 10d7afc0..c31bef7b 100644 --- a/src/Propellor/Property/OS.hs +++ b/src/Propellor/Property/OS.hs @@ -207,7 +207,7 @@ preserveNetwork = go `requires` Network.cleanInterfacesFile ["route", "list", "scope", "global"] case words <$> headMaybe ls of Just ("default":"via":_:"dev":iface:_) -> - ensureProperty w $ Network.static iface + ensureProperty w $ Network.preserveStatic iface _ -> do warningMessage "did not find any default ipv4 route" return FailedChange -- cgit v1.2.3