Statistics
| Branch: | Tag: | Revision:

root / src / Ganeti / HTools / Group.hs @ 9d049fb4

History | View | Annotate | Download (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 139c0683 Iustin Pop
Copyright (C) 2010, 2011, 2012 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 ebf38064 Iustin Pop
  ( Group(..)
28 ebf38064 Iustin Pop
  , List
29 ebf38064 Iustin Pop
  , AssocList
30 ebf38064 Iustin Pop
  -- * Constructor
31 ebf38064 Iustin Pop
  , create
32 ebf38064 Iustin Pop
  , setIdx
33 ebf38064 Iustin Pop
  , isAllocable
34 ebf38064 Iustin Pop
  ) where
35 0dc1bf87 Iustin Pop
36 0dc1bf87 Iustin Pop
import qualified Ganeti.HTools.Container as Container
37 0dc1bf87 Iustin Pop
38 0dc1bf87 Iustin Pop
import qualified Ganeti.HTools.Types as T
39 0dc1bf87 Iustin Pop
40 0dc1bf87 Iustin Pop
-- * Type declarations
41 0dc1bf87 Iustin Pop
42 0dc1bf87 Iustin Pop
-- | The node group type.
43 0dc1bf87 Iustin Pop
data Group = Group
44 ebf38064 Iustin Pop
  { name        :: String        -- ^ The node name
45 ebf38064 Iustin Pop
  , uuid        :: T.GroupID     -- ^ The UUID of the group
46 ebf38064 Iustin Pop
  , idx         :: T.Gdx         -- ^ Internal index for book-keeping
47 ebf38064 Iustin Pop
  , allocPolicy :: T.AllocPolicy -- ^ The allocation policy for this group
48 c8b199db Thomas Thrainer
  , networks    :: [T.NetworkID] -- ^ The networks connected to this group
49 6cff91f5 Iustin Pop
  , iPolicy     :: T.IPolicy     -- ^ The instance policy for this group
50 6b6e335b Dato Simó
  , allTags     :: [String]      -- ^ The tags for this group
51 139c0683 Iustin Pop
  } deriving (Show, Eq)
52 0dc1bf87 Iustin Pop
53 0dc1bf87 Iustin Pop
-- Note: we use the name as the alias, and the UUID as the official
54 0dc1bf87 Iustin Pop
-- name
55 0dc1bf87 Iustin Pop
instance T.Element Group where
56 ebf38064 Iustin Pop
  nameOf     = uuid
57 ebf38064 Iustin Pop
  idxOf      = idx
58 ebf38064 Iustin Pop
  setAlias   = setName
59 ebf38064 Iustin Pop
  setIdx     = setIdx
60 ebf38064 Iustin Pop
  allNames n = [name n, uuid n]
61 0dc1bf87 Iustin Pop
62 0dc1bf87 Iustin Pop
-- | A simple name for the int, node association list.
63 0dc1bf87 Iustin Pop
type AssocList = [(T.Gdx, Group)]
64 0dc1bf87 Iustin Pop
65 0dc1bf87 Iustin Pop
-- | A simple name for a node map.
66 0dc1bf87 Iustin Pop
type List = Container.Container Group
67 0dc1bf87 Iustin Pop
68 0dc1bf87 Iustin Pop
-- * Initialization functions
69 0dc1bf87 Iustin Pop
70 0dc1bf87 Iustin Pop
-- | Create a new group.
71 c8b199db Thomas Thrainer
create :: String        -- ^ The node name
72 c8b199db Thomas Thrainer
       -> T.GroupID     -- ^ The UUID of the group
73 c8b199db Thomas Thrainer
       -> T.AllocPolicy -- ^ The allocation policy for this group
74 c8b199db Thomas Thrainer
       -> [T.NetworkID] -- ^ The networks connected to this group
75 c8b199db Thomas Thrainer
       -> T.IPolicy     -- ^ The instance policy for this group
76 c8b199db Thomas Thrainer
       -> [String]      -- ^ The tags for this group
77 c8b199db Thomas Thrainer
       -> Group
78 c8b199db Thomas Thrainer
create name_init id_init apol_init nets_init ipol_init tags_init =
79 ebf38064 Iustin Pop
  Group { name        = name_init
80 ebf38064 Iustin Pop
        , uuid        = id_init
81 ebf38064 Iustin Pop
        , allocPolicy = apol_init
82 c8b199db Thomas Thrainer
        , networks    = nets_init
83 6cff91f5 Iustin Pop
        , iPolicy     = ipol_init
84 6b6e335b Dato Simó
        , allTags     = tags_init
85 ebf38064 Iustin Pop
        , idx         = -1
86 ebf38064 Iustin Pop
        }
87 0dc1bf87 Iustin Pop
88 179c0828 Iustin Pop
-- | Sets the group index.
89 179c0828 Iustin Pop
--
90 0dc1bf87 Iustin Pop
-- This is used only during the building of the data structures.
91 0dc1bf87 Iustin Pop
setIdx :: Group -> T.Gdx -> Group
92 0dc1bf87 Iustin Pop
setIdx t i = t {idx = i}
93 0dc1bf87 Iustin Pop
94 0dc1bf87 Iustin Pop
-- | Changes the alias.
95 0dc1bf87 Iustin Pop
--
96 0dc1bf87 Iustin Pop
-- This is used only during the building of the data structures.
97 0dc1bf87 Iustin Pop
setName :: Group -> String -> Group
98 0dc1bf87 Iustin Pop
setName t s = t { name = s }
99 0ec6344e Iustin Pop
100 0ec6344e Iustin Pop
-- | Checks if a group is allocable.
101 0ec6344e Iustin Pop
isAllocable :: Group -> Bool
102 0ec6344e Iustin Pop
isAllocable = (/= T.AllocUnallocable) . allocPolicy