root / Ganeti / HTools / Group.hs @ 2ca68e2b
History | View | Annotate | Download (2.3 kB)
1 | 0dc1bf87 | Iustin Pop | {-| Module describing a node group. |
---|---|---|---|
2 | 0dc1bf87 | Iustin Pop | |
3 | 0dc1bf87 | Iustin Pop | -} |
4 | 0dc1bf87 | Iustin Pop | |
5 | 0dc1bf87 | Iustin Pop | {- |
6 | 0dc1bf87 | Iustin Pop | |
7 | 0dc1bf87 | Iustin Pop | Copyright (C) 2010 Google Inc. |
8 | 0dc1bf87 | Iustin Pop | |
9 | 0dc1bf87 | Iustin Pop | This program is free software; you can redistribute it and/or modify |
10 | 0dc1bf87 | Iustin Pop | it under the terms of the GNU General Public License as published by |
11 | 0dc1bf87 | Iustin Pop | the Free Software Foundation; either version 2 of the License, or |
12 | 0dc1bf87 | Iustin Pop | (at your option) any later version. |
13 | 0dc1bf87 | Iustin Pop | |
14 | 0dc1bf87 | Iustin Pop | This program is distributed in the hope that it will be useful, but |
15 | 0dc1bf87 | Iustin Pop | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | 0dc1bf87 | Iustin Pop | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 | 0dc1bf87 | Iustin Pop | General Public License for more details. |
18 | 0dc1bf87 | Iustin Pop | |
19 | 0dc1bf87 | Iustin Pop | You should have received a copy of the GNU General Public License |
20 | 0dc1bf87 | Iustin Pop | along with this program; if not, write to the Free Software |
21 | 0dc1bf87 | Iustin Pop | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
22 | 0dc1bf87 | Iustin Pop | 02110-1301, USA. |
23 | 0dc1bf87 | Iustin Pop | |
24 | 0dc1bf87 | Iustin Pop | -} |
25 | 0dc1bf87 | Iustin Pop | |
26 | 0dc1bf87 | Iustin Pop | module Ganeti.HTools.Group |
27 | 0dc1bf87 | Iustin Pop | ( Group(..) |
28 | 0dc1bf87 | Iustin Pop | , List |
29 | 0dc1bf87 | Iustin Pop | , AssocList |
30 | 0dc1bf87 | Iustin Pop | -- * Constructor |
31 | 0dc1bf87 | Iustin Pop | , create |
32 | 0dc1bf87 | Iustin Pop | , setIdx |
33 | 0dc1bf87 | Iustin Pop | ) where |
34 | 0dc1bf87 | Iustin Pop | |
35 | 0dc1bf87 | Iustin Pop | import qualified Ganeti.HTools.Container as Container |
36 | 0dc1bf87 | Iustin Pop | |
37 | 0dc1bf87 | Iustin Pop | import qualified Ganeti.HTools.Types as T |
38 | 0dc1bf87 | Iustin Pop | |
39 | 0dc1bf87 | Iustin Pop | -- * Type declarations |
40 | 0dc1bf87 | Iustin Pop | |
41 | 0dc1bf87 | Iustin Pop | -- | The node group type. |
42 | 0dc1bf87 | Iustin Pop | data Group = Group |
43 | 0dc1bf87 | Iustin Pop | { name :: String -- ^ The node name |
44 | 0dc1bf87 | Iustin Pop | , uuid :: T.GroupID -- ^ The UUID of the group |
45 | 0dc1bf87 | Iustin Pop | , idx :: T.Gdx -- ^ Internal index for book-keeping |
46 | 0dc1bf87 | Iustin Pop | , allocPolicy :: T.AllocPolicy -- ^ The allocation policy for this group |
47 | 6bc39970 | Iustin Pop | } deriving (Show, Read, Eq) |
48 | 0dc1bf87 | Iustin Pop | |
49 | 0dc1bf87 | Iustin Pop | -- Note: we use the name as the alias, and the UUID as the official |
50 | 0dc1bf87 | Iustin Pop | -- name |
51 | 0dc1bf87 | Iustin Pop | instance T.Element Group where |
52 | 0dc1bf87 | Iustin Pop | nameOf = uuid |
53 | 0dc1bf87 | Iustin Pop | idxOf = idx |
54 | 0dc1bf87 | Iustin Pop | setAlias = setName |
55 | 0dc1bf87 | Iustin Pop | setIdx = setIdx |
56 | 0dc1bf87 | Iustin Pop | allNames n = [name n, uuid n] |
57 | 0dc1bf87 | Iustin Pop | |
58 | 0dc1bf87 | Iustin Pop | -- | A simple name for the int, node association list. |
59 | 0dc1bf87 | Iustin Pop | type AssocList = [(T.Gdx, Group)] |
60 | 0dc1bf87 | Iustin Pop | |
61 | 0dc1bf87 | Iustin Pop | -- | A simple name for a node map. |
62 | 0dc1bf87 | Iustin Pop | type List = Container.Container Group |
63 | 0dc1bf87 | Iustin Pop | |
64 | 0dc1bf87 | Iustin Pop | -- * Initialization functions |
65 | 0dc1bf87 | Iustin Pop | |
66 | 0dc1bf87 | Iustin Pop | -- | Create a new group. |
67 | 0dc1bf87 | Iustin Pop | create :: String -> T.GroupID -> T.AllocPolicy -> Group |
68 | 0dc1bf87 | Iustin Pop | create name_init id_init apol_init = |
69 | 0dc1bf87 | Iustin Pop | Group { name = name_init |
70 | 0dc1bf87 | Iustin Pop | , uuid = id_init |
71 | 0dc1bf87 | Iustin Pop | , allocPolicy = apol_init |
72 | 0dc1bf87 | Iustin Pop | , idx = -1 |
73 | 0dc1bf87 | Iustin Pop | } |
74 | 0dc1bf87 | Iustin Pop | |
75 | 0dc1bf87 | Iustin Pop | -- This is used only during the building of the data structures. |
76 | 0dc1bf87 | Iustin Pop | setIdx :: Group -> T.Gdx -> Group |
77 | 0dc1bf87 | Iustin Pop | setIdx t i = t {idx = i} |
78 | 0dc1bf87 | Iustin Pop | |
79 | 0dc1bf87 | Iustin Pop | -- | Changes the alias. |
80 | 0dc1bf87 | Iustin Pop | -- |
81 | 0dc1bf87 | Iustin Pop | -- This is used only during the building of the data structures. |
82 | 0dc1bf87 | Iustin Pop | setName :: Group -> String -> Group |
83 | 0dc1bf87 | Iustin Pop | setName t s = t { name = s } |