From 38eec6fc37054df1838be905670e1ed1ff308a65 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 23 Jan 2015 01:29:47 -0400 Subject: OS.preserveNetwork finally written --- src/Propellor/Property/OS.hs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Propellor/Property/OS.hs b/src/Propellor/Property/OS.hs index b60151e8..c1b085a6 100644 --- a/src/Propellor/Property/OS.hs +++ b/src/Propellor/Property/OS.hs @@ -10,6 +10,7 @@ module Propellor.Property.OS ( import Propellor import qualified Propellor.Property.Debootstrap as Debootstrap import qualified Propellor.Property.Ssh as Ssh +import qualified Propellor.Property.Network as Network import qualified Propellor.Property.User as User import qualified Propellor.Property.File as File import qualified Propellor.Property.Reboot as Reboot @@ -51,7 +52,7 @@ import Control.Exception (throw) -- > `onChange` propertyList "fixing up after clean install" -- > [ preserveNetwork -- > , preserveResolvConf --- > , preserverRootSshAuthorized +-- > , preserveRootSshAuthorized -- > , Apt.update -- > -- , Grub.boots "/dev/sda" -- > -- `requires` Grub.installed Grub.PC @@ -192,7 +193,17 @@ confirmed desc (Confirmed c) = property desc $ do -- interface that currently has a default route configured, using -- the same (static) IP address. preserveNetwork :: Property -preserveNetwork = undefined -- TODO +preserveNetwork = go `requires` Network.cleanInterfacesFile + where + go = property "preserve network configuration" $ do + ls <- liftIO $ lines <$> readProcess "ip" + ["route", "list", "scope", "global"] + case words <$> headMaybe ls of + Just ("default":"via":_:"dev":iface:_) -> + ensureProperty $ Network.static iface + _ -> do + warningMessage "did not find any default ipv4 route" + return FailedChange -- | is copied from the old OS preserveResolvConf :: Property -- cgit v1.2.3