1 {-| Module describing a node group.
7 Copyright (C) 2010, 2011 Google Inc.
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.
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.
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
26 module Ganeti.HTools.Group
36 import qualified Ganeti.HTools.Container as Container
38 import qualified Ganeti.HTools.Types as T
40 -- * Type declarations
42 -- | The node group type.
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 , iPolicy :: T.IPolicy -- ^ The instance policy for this group
49 } deriving (Show, Read, Eq)
51 -- Note: we use the name as the alias, and the UUID as the official
53 instance T.Element Group where
58 allNames n = [name n, uuid n]
60 -- | A simple name for the int, node association list.
61 type AssocList = [(T.Gdx, Group)]
63 -- | A simple name for a node map.
64 type List = Container.Container Group
66 -- * Initialization functions
68 -- | Create a new group.
69 create :: String -> T.GroupID -> T.AllocPolicy -> T.IPolicy -> Group
70 create name_init id_init apol_init ipol_init =
71 Group { name = name_init
73 , allocPolicy = apol_init
78 -- | Sets the group index.
80 -- This is used only during the building of the data structures.
81 setIdx :: Group -> T.Gdx -> Group
82 setIdx t i = t {idx = i}
84 -- | Changes the alias.
86 -- This is used only during the building of the data structures.
87 setName :: Group -> String -> Group
88 setName t s = t { name = s }
90 -- | Checks if a group is allocable.
91 isAllocable :: Group -> Bool
92 isAllocable = (/= T.AllocUnallocable) . allocPolicy