summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2017-07-26 16:20:23 -0400
committerJoey Hess2017-07-26 16:20:23 -0400
commit266cbceb19197d4dd2c95bd2c62c79d23ae95ef9 (patch)
tree2200222c5b12bb4cf96c66eff5561cc5a2ce50e7 /src
parent939c642d14b5ecc3289e0bc0a55355201c6db3e1 (diff)
propellor spin
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Network.hs29
-rw-r--r--src/Propellor/Property/OS.hs2
2 files changed, 27 insertions, 4 deletions
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