parent
42a0c83248
commit
4e9b01a8a7
|
@ -121,12 +121,6 @@ doNothing = property "noop property" noChange
|
||||||
withOS :: Desc -> (Maybe System -> Propellor Result) -> Property
|
withOS :: Desc -> (Maybe System -> Propellor Result) -> Property
|
||||||
withOS desc a = property desc $ a =<< getOS
|
withOS desc a = property desc $ a =<< getOS
|
||||||
|
|
||||||
boolProperty :: Desc -> IO Bool -> Property
|
|
||||||
boolProperty desc a = property desc $ ifM (liftIO a)
|
|
||||||
( return MadeChange
|
|
||||||
, return FailedChange
|
|
||||||
)
|
|
||||||
|
|
||||||
-- | Undoes the effect of a property.
|
-- | Undoes the effect of a property.
|
||||||
revert :: RevertableProperty -> RevertableProperty
|
revert :: RevertableProperty -> RevertableProperty
|
||||||
revert (RevertableProperty p1 p2) = RevertableProperty p2 p1
|
revert (RevertableProperty p1 p2) = RevertableProperty p2 p1
|
||||||
|
|
|
@ -13,7 +13,6 @@ import "mtl" Control.Monad.Reader
|
||||||
|
|
||||||
import Propellor.Types
|
import Propellor.Types
|
||||||
import Propellor.Property
|
import Propellor.Property
|
||||||
import Utility.Monad
|
|
||||||
import Utility.SafeCommand
|
import Utility.SafeCommand
|
||||||
import Utility.Env
|
import Utility.Env
|
||||||
|
|
||||||
|
@ -28,10 +27,7 @@ cmdProperty cmd params = cmdProperty' cmd params []
|
||||||
cmdProperty' :: String -> [String] -> [(String, String)] -> Property
|
cmdProperty' :: String -> [String] -> [(String, String)] -> Property
|
||||||
cmdProperty' cmd params env = property desc $ liftIO $ do
|
cmdProperty' cmd params env = property desc $ liftIO $ do
|
||||||
env' <- addEntries env <$> getEnvironment
|
env' <- addEntries env <$> getEnvironment
|
||||||
ifM (boolSystemEnv cmd (map Param params) (Just env'))
|
toResult <$> boolSystemEnv cmd (map Param params) (Just env')
|
||||||
( return MadeChange
|
|
||||||
, return FailedChange
|
|
||||||
)
|
|
||||||
where
|
where
|
||||||
desc = unwords $ cmd : params
|
desc = unwords $ cmd : params
|
||||||
|
|
||||||
|
|
|
@ -379,7 +379,8 @@ runningContainer cid@(ContainerId hn cn) image runps = containerDesc cid $ prope
|
||||||
createDirectoryIfMissing True (takeDirectory $ identFile cid)
|
createDirectoryIfMissing True (takeDirectory $ identFile cid)
|
||||||
shim <- liftIO $ Shim.setup (localdir </> "propellor") Nothing (localdir </> shimdir cid)
|
shim <- liftIO $ Shim.setup (localdir </> "propellor") Nothing (localdir </> shimdir cid)
|
||||||
liftIO $ writeFile (identFile cid) (show ident)
|
liftIO $ writeFile (identFile cid) (show ident)
|
||||||
ensureProperty $ boolProperty "run" $ runContainer img
|
ensureProperty $ property "run" $ liftIO $
|
||||||
|
toResult <$> runContainer img
|
||||||
(runps ++ ["-i", "-d", "-t"])
|
(runps ++ ["-i", "-d", "-t"])
|
||||||
[shim, "--continue", show (DockerInit (fromContainerId cid))]
|
[shim, "--continue", show (DockerInit (fromContainerId cid))]
|
||||||
|
|
||||||
|
@ -466,7 +467,7 @@ stoppedContainer :: ContainerId -> Property
|
||||||
stoppedContainer cid = containerDesc cid $ property desc $
|
stoppedContainer cid = containerDesc cid $ property desc $
|
||||||
ifM (liftIO $ elem cid <$> listContainers RunningContainers)
|
ifM (liftIO $ elem cid <$> listContainers RunningContainers)
|
||||||
( liftIO cleanup `after` ensureProperty
|
( liftIO cleanup `after` ensureProperty
|
||||||
(boolProperty desc $ stopContainer cid)
|
(property desc $ liftIO $ toResult <$> stopContainer cid)
|
||||||
, return NoChange
|
, return NoChange
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
|
@ -33,8 +33,7 @@ rule c t rs = property ("firewall rule: " <> show r) addIpTable
|
||||||
exist <- boolSystem "iptables" (chk args)
|
exist <- boolSystem "iptables" (chk args)
|
||||||
if exist
|
if exist
|
||||||
then return NoChange
|
then return NoChange
|
||||||
else ifM (boolSystem "iptables" (add args))
|
else toResult <$> boolSystem "iptables" (add args)
|
||||||
( return MadeChange , return FailedChange)
|
|
||||||
add params = (Param "-A") : params
|
add params = (Param "-A") : params
|
||||||
chk params = (Param "-C") : params
|
chk params = (Param "-C") : params
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ module Propellor.Types
|
||||||
, requires
|
, requires
|
||||||
, Desc
|
, Desc
|
||||||
, Result(..)
|
, Result(..)
|
||||||
|
, ToResult(..)
|
||||||
, ActionResult(..)
|
, ActionResult(..)
|
||||||
, CmdLine(..)
|
, CmdLine(..)
|
||||||
, PrivDataField(..)
|
, PrivDataField(..)
|
||||||
|
@ -131,6 +132,13 @@ instance Monoid Result where
|
||||||
mappend _ MadeChange = MadeChange
|
mappend _ MadeChange = MadeChange
|
||||||
mappend NoChange NoChange = NoChange
|
mappend NoChange NoChange = NoChange
|
||||||
|
|
||||||
|
class ToResult t where
|
||||||
|
toResult :: t -> Result
|
||||||
|
|
||||||
|
instance ToResult Bool where
|
||||||
|
toResult False = FailedChange
|
||||||
|
toResult True = MadeChange
|
||||||
|
|
||||||
-- | Results of actions, with color.
|
-- | Results of actions, with color.
|
||||||
class ActionResult a where
|
class ActionResult a where
|
||||||
getActionResult :: a -> (String, ColorIntensity, Color)
|
getActionResult :: a -> (String, ColorIntensity, Color)
|
||||||
|
|
Loading…
Reference in New Issue