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