2014-03-31 03:37:54 +00:00
|
|
|
module Propellor.Types where
|
2014-03-30 23:10:32 +00:00
|
|
|
|
2014-03-31 14:36:45 +00:00
|
|
|
import Data.Monoid
|
2014-03-31 22:31:08 +00:00
|
|
|
import System.Console.ANSI
|
2014-03-31 14:36:45 +00:00
|
|
|
|
2014-03-30 23:10:32 +00:00
|
|
|
type HostName = String
|
|
|
|
type UserName = String
|
|
|
|
|
|
|
|
data Property = Property
|
|
|
|
{ propertyDesc :: Desc
|
2014-03-31 03:37:54 +00:00
|
|
|
-- | must be idempotent; may run repeatedly
|
2014-03-30 23:10:32 +00:00
|
|
|
, propertySatisfy :: IO Result
|
|
|
|
}
|
|
|
|
|
2014-04-02 16:13:39 +00:00
|
|
|
data RevertableProperty = RevertableProperty Property Property
|
|
|
|
|
|
|
|
class IsProp p where
|
|
|
|
-- | Sets description.
|
|
|
|
describe :: p -> Desc -> p
|
|
|
|
toProp :: p -> Property
|
|
|
|
-- | Indicates that the first property can only be satisfied
|
|
|
|
-- once the second one is.
|
|
|
|
requires :: p -> Property -> p
|
|
|
|
|
|
|
|
instance IsProp Property where
|
|
|
|
describe p d = p { propertyDesc = d }
|
|
|
|
toProp p = p
|
|
|
|
x `requires` y = Property (propertyDesc x) $ do
|
|
|
|
r <- propertySatisfy y
|
|
|
|
case r of
|
|
|
|
FailedChange -> return FailedChange
|
|
|
|
_ -> propertySatisfy x
|
|
|
|
|
|
|
|
instance IsProp RevertableProperty where
|
|
|
|
-- | Sets the description of both sides.
|
|
|
|
describe (RevertableProperty p1 p2) d =
|
|
|
|
RevertableProperty (describe p1 d) (describe p2 ("not " ++ d))
|
|
|
|
toProp (RevertableProperty p1 _) = p1
|
|
|
|
(RevertableProperty p1 p2) `requires` y =
|
|
|
|
RevertableProperty (p1 `requires` y) p2
|
|
|
|
|
2014-03-30 23:10:32 +00:00
|
|
|
type Desc = String
|
|
|
|
|
|
|
|
data Result = NoChange | MadeChange | FailedChange
|
2014-04-01 05:12:05 +00:00
|
|
|
deriving (Read, Show, Eq)
|
2014-03-30 23:10:32 +00:00
|
|
|
|
2014-03-31 14:36:45 +00:00
|
|
|
instance Monoid Result where
|
|
|
|
mempty = NoChange
|
|
|
|
|
|
|
|
mappend FailedChange _ = FailedChange
|
|
|
|
mappend _ FailedChange = FailedChange
|
|
|
|
mappend MadeChange _ = MadeChange
|
|
|
|
mappend _ MadeChange = MadeChange
|
|
|
|
mappend NoChange NoChange = NoChange
|
2014-03-31 22:31:08 +00:00
|
|
|
|
2014-04-01 20:58:11 +00:00
|
|
|
-- | High level descritption of a operating system.
|
|
|
|
data System = System Distribution Architecture
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
data Distribution
|
|
|
|
= Debian DebianSuite
|
|
|
|
| Ubuntu Release
|
|
|
|
deriving (Show)
|
|
|
|
|
|
|
|
data DebianSuite = Experimental | Unstable | Testing | Stable | DebianRelease Release
|
2014-04-10 04:29:47 +00:00
|
|
|
deriving (Show, Eq)
|
2014-04-01 20:58:11 +00:00
|
|
|
|
|
|
|
type Release = String
|
|
|
|
|
2014-04-02 03:49:15 +00:00
|
|
|
type Architecture = String
|
2014-04-01 20:58:11 +00:00
|
|
|
|
|
|
|
-- | Results of actions, with color.
|
2014-03-31 22:31:08 +00:00
|
|
|
class ActionResult a where
|
|
|
|
getActionResult :: a -> (String, ColorIntensity, Color)
|
|
|
|
|
|
|
|
instance ActionResult Bool where
|
2014-03-31 22:36:53 +00:00
|
|
|
getActionResult False = ("failed", Vivid, Red)
|
2014-04-02 04:52:39 +00:00
|
|
|
getActionResult True = ("done", Dull, Green)
|
2014-03-31 22:31:08 +00:00
|
|
|
|
|
|
|
instance ActionResult Result where
|
2014-04-02 04:52:39 +00:00
|
|
|
getActionResult NoChange = ("ok", Dull, Green)
|
2014-03-31 22:31:08 +00:00
|
|
|
getActionResult MadeChange = ("done", Vivid, Green)
|
|
|
|
getActionResult FailedChange = ("failed", Vivid, Red)
|
2014-04-01 17:51:58 +00:00
|
|
|
|
|
|
|
data CmdLine
|
|
|
|
= Run HostName
|
|
|
|
| Spin HostName
|
|
|
|
| Boot HostName
|
|
|
|
| Set HostName PrivDataField
|
|
|
|
| AddKey String
|
|
|
|
| Continue CmdLine
|
|
|
|
| Chain HostName
|
2014-04-02 00:47:25 +00:00
|
|
|
| Docker HostName
|
2014-04-01 17:51:58 +00:00
|
|
|
deriving (Read, Show, Eq)
|
|
|
|
|
|
|
|
-- | Note that removing or changing field names will break the
|
|
|
|
-- serialized privdata files, so don't do that!
|
|
|
|
-- It's fine to add new fields.
|
|
|
|
data PrivDataField
|
|
|
|
= DockerAuthentication
|
|
|
|
| SshPrivKey UserName
|
|
|
|
| Password UserName
|
2014-04-08 20:58:11 +00:00
|
|
|
| PrivFile FilePath
|
2014-04-01 17:51:58 +00:00
|
|
|
deriving (Read, Show, Ord, Eq)
|
2014-04-02 16:13:39 +00:00
|
|
|
|
|
|
|
|