root / Ganeti / HTools / Types.hs @ 497e30a1
History | View | Annotate | Download (1.4 kB)
1 | e4c5beaf | Iustin Pop | {-| Some common types. |
---|---|---|---|
2 | e4c5beaf | Iustin Pop | |
3 | e4c5beaf | Iustin Pop | -} |
4 | e4c5beaf | Iustin Pop | |
5 | e4c5beaf | Iustin Pop | module Ganeti.HTools.Types |
6 | e4c5beaf | Iustin Pop | where |
7 | e4c5beaf | Iustin Pop | |
8 | e4c5beaf | Iustin Pop | import qualified Ganeti.HTools.Container as Container |
9 | e4c5beaf | Iustin Pop | import qualified Ganeti.HTools.Instance as Instance |
10 | e4c5beaf | Iustin Pop | import qualified Ganeti.HTools.Node as Node |
11 | e4c5beaf | Iustin Pop | |
12 | e4c5beaf | Iustin Pop | type NodeList = Container.Container Node.Node |
13 | e4c5beaf | Iustin Pop | type InstanceList = Container.Container Instance.Instance |
14 | e4c5beaf | Iustin Pop | |
15 | e4c5beaf | Iustin Pop | -- | The type used to hold idx-to-name mappings |
16 | e4c5beaf | Iustin Pop | type NameList = [(Int, String)] |
17 | e4c5beaf | Iustin Pop | |
18 | e4c5beaf | Iustin Pop | -- | The type used to hold name-to-idx mappings |
19 | e4c5beaf | Iustin Pop | type NameAssoc = [(String, Int)] |
20 | e4c5beaf | Iustin Pop | |
21 | e4c5beaf | Iustin Pop | type IdxNode = [(Int, Node.Node)] |
22 | e4c5beaf | Iustin Pop | type IdxInstance = [(Int, Instance.Instance)] |
23 | e4c5beaf | Iustin Pop | |
24 | e4c5beaf | Iustin Pop | {- |
25 | e4c5beaf | Iustin Pop | |
26 | e4c5beaf | Iustin Pop | This is similar to the JSON library Result type - *very* similar, but |
27 | e4c5beaf | Iustin Pop | we want to use it in multiple places, so we abstract it into a |
28 | e4c5beaf | Iustin Pop | mini-library here |
29 | e4c5beaf | Iustin Pop | |
30 | e4c5beaf | Iustin Pop | -} |
31 | e4c5beaf | Iustin Pop | |
32 | e4c5beaf | Iustin Pop | data Result a |
33 | e4c5beaf | Iustin Pop | = Bad String |
34 | e4c5beaf | Iustin Pop | | Ok a |
35 | e4c5beaf | Iustin Pop | deriving (Show) |
36 | e4c5beaf | Iustin Pop | |
37 | e4c5beaf | Iustin Pop | instance Monad Result where |
38 | e4c5beaf | Iustin Pop | (>>=) (Bad x) _ = Bad x |
39 | e4c5beaf | Iustin Pop | (>>=) (Ok x) fn = fn x |
40 | e4c5beaf | Iustin Pop | return = Ok |
41 | e4c5beaf | Iustin Pop | fail = Bad |
42 | 497e30a1 | Iustin Pop | |
43 | 497e30a1 | Iustin Pop | -- | A generic class for nodes and instances |
44 | 497e30a1 | Iustin Pop | class Element a where |
45 | 497e30a1 | Iustin Pop | name :: a -> String |
46 | 497e30a1 | Iustin Pop | idx :: a -> Int |
47 | 497e30a1 | Iustin Pop | setName :: a -> String -> a |
48 | 497e30a1 | Iustin Pop | setIdx :: a -> Int -> a |
49 | 497e30a1 | Iustin Pop | |
50 | 497e30a1 | Iustin Pop | -- Let's make nodes elements of the cluster |
51 | 497e30a1 | Iustin Pop | instance Element Node.Node where |
52 | 497e30a1 | Iustin Pop | name = Node.name |
53 | 497e30a1 | Iustin Pop | idx = Node.idx |
54 | 497e30a1 | Iustin Pop | setName = Node.setName |
55 | 497e30a1 | Iustin Pop | setIdx = Node.setIdx |
56 | 497e30a1 | Iustin Pop | |
57 | 497e30a1 | Iustin Pop | -- And instances too |
58 | 497e30a1 | Iustin Pop | instance Element Instance.Instance where |
59 | 497e30a1 | Iustin Pop | name = Instance.name |
60 | 497e30a1 | Iustin Pop | idx = Instance.idx |
61 | 497e30a1 | Iustin Pop | setName = Instance.setName |
62 | 497e30a1 | Iustin Pop | setIdx = Instance.setIdx |