propellor spin

This commit is contained in:
Joey Hess 2014-04-02 20:56:02 -04:00
parent 595794a250
commit 5674818300
Failed to extract signature
2 changed files with 25 additions and 15 deletions

View File

@ -69,6 +69,12 @@ check c property = Property (propertyDesc property) $ ifM c
, return NoChange
)
boolProperty :: Desc -> IO Bool -> Property
boolProperty desc a = Property desc $ ifM a
( return MadeChange
, return FailedChange
)
-- | Undoes the effect of a property.
revert :: RevertableProperty -> RevertableProperty
revert (RevertableProperty p1 p2) = RevertableProperty p2 p1

View File

@ -54,12 +54,14 @@ docked findc hn cn = findContainer findc hn cn $
runningContainer cid image containerprops
`requires`
installed
teardown = Property ("undocked " ++ fromContainerId cid) $
teardown = combineProperties ("undocked " ++ fromContainerId cid)
[ stoppedContainer cid
, Property ("cleaned up " ++ fromContainerId cid) $
report <$> mapM id
[ stopContainerIfRunning cid
, removeContainer cid
[ removeContainer cid
, removeImage image
]
]
in RevertableProperty setup teardown
where
cid = ContainerId hn cn
@ -260,10 +262,9 @@ runningContainer cid@(ContainerId hn cn) image containerprops = containerDesc ci
clearProvisionedFlag cid
createDirectoryIfMissing True (takeDirectory $ identFile cid)
writeFile (identFile cid) (show ident)
ifM (runContainer img (runps ++ ["-i", "-d", "-t"]) chaincmd)
( return MadeChange
, return FailedChange
)
ensureProperty $ boolProperty "run" $ runContainer img
(runps ++ ["-i", "-d", "-t"])
chaincmd
-- | Called when propellor is running inside a docker container.
-- The string should be the container's ContainerId.
@ -338,11 +339,14 @@ provisionContainer cid = containerDesc cid $ Property "provision" $ do
stopContainer :: ContainerId -> IO Bool
stopContainer cid = boolSystem dockercmd [Param "stop", Param $ fromContainerId cid ]
stopContainerIfRunning :: ContainerId -> IO Bool
stopContainerIfRunning cid = ifM (elem cid <$> listContainers RunningContainers)
( stopContainer cid
, return True
stoppedContainer :: ContainerId -> Property
stoppedContainer cid = containerDesc cid $ Property desc $
ifM (elem cid <$> listContainers RunningContainers)
( ensureProperty $ boolProperty desc $ stopContainer cid
, return NoChange
)
where
desc = "stopped"
removeContainer :: ContainerId -> IO Bool
removeContainer cid = catchBoolIO $