Commit 0dc1bf87 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add a new Group.hs module describing node groups



This is not yet used by the rest of the code.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent edd0a48f
{-| Module describing a node group.
-}
{-
Copyright (C) 2010 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
-}
module Ganeti.HTools.Group
( Group(..)
, List
, AssocList
-- * Constructor
, create
, setIdx
) where
import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Types as T
-- * Type declarations
-- | The node group type.
data Group = Group
{ name :: String -- ^ The node name
, uuid :: T.GroupID -- ^ The UUID of the group
, idx :: T.Gdx -- ^ Internal index for book-keeping
, allocPolicy :: T.AllocPolicy -- ^ The allocation policy for this group
} deriving (Show, Eq)
-- Note: we use the name as the alias, and the UUID as the official
-- name
instance T.Element Group where
nameOf = uuid
idxOf = idx
setAlias = setName
setIdx = setIdx
allNames n = [name n, uuid n]
-- | A simple name for the int, node association list.
type AssocList = [(T.Gdx, Group)]
-- | A simple name for a node map.
type List = Container.Container Group
-- * Initialization functions
-- | Create a new group.
create :: String -> T.GroupID -> T.AllocPolicy -> Group
create name_init id_init apol_init =
Group { name = name_init
, uuid = id_init
, allocPolicy = apol_init
, idx = -1
}
-- This is used only during the building of the data structures.
setIdx :: Group -> T.Gdx -> Group
setIdx t i = t {idx = i}
-- | Changes the alias.
--
-- This is used only during the building of the data structures.
setName :: Group -> String -> Group
setName t s = t { name = s }
......@@ -26,10 +26,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.HTools.Types
( Idx
, Ndx
, Gdx
, NameAssoc
, Score
, Weight
, GroupID
, AllocPolicy(..)
, RSpec(..)
, DynUtil(..)
, zeroUtil
......@@ -65,6 +67,9 @@ type Idx = Int
-- | The node index type.
type Ndx = Int
-- | The group index type.
type Gdx = Int
-- | The type used to hold name-to-idx mappings.
type NameAssoc = M.Map String Int
......@@ -74,9 +79,15 @@ type Score = Double
-- | A separate name for a weight metric.
type Weight = Double
-- | The Group UUID type
-- | The Group UUID type.
type GroupID = String
-- | The Group allocation policy type.
data AllocPolicy = AllocPreferred
| AllocLastResort
| AllocUnallocable
deriving (Show, Eq)
-- | The resource spec type.
data RSpec = RSpec
{ rspecCpu :: Int -- ^ Requested VCPUs
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment