Rework the tryAlloc/tryReloc functions
[ganeti-local] / Ganeti / HTools / Types.hs
index 0a24802..662cef2 100644 (file)
@@ -2,33 +2,51 @@
 
 -}
 
-module Ganeti.HTools.Types
-    where
+{-
 
-import qualified Ganeti.HTools.Container as Container
-import qualified Ganeti.HTools.Instance as Instance
-import qualified Ganeti.HTools.Node as Node
+Copyright (C) 2009 Google Inc.
 
-type NodeList = Container.Container Node.Node
-type InstanceList = Container.Container Instance.Instance
+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.
 
--- | The type used to hold idx-to-name mappings
-type NameList = [(Int, String)]
+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.
 
--- | The type used to hold name-to-idx mappings
-type NameAssoc = [(String, Int)]
+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.
 
-type IdxNode = [(Int, Node.Node)]
-type IdxInstance = [(Int, Instance.Instance)]
+-}
 
-{-
+module Ganeti.HTools.Types
+    ( Idx
+    , Ndx
+    , NameAssoc
+    , Result(..)
+    , Element(..)
+    ) where
+
+-- | The instance index type.
+type Idx = Int
+
+-- | The node index type.
+type Ndx = Int
+
+-- | The type used to hold name-to-idx mappings.
+type NameAssoc = [(String, Int)]
+
+{-|
 
 This is similar to the JSON library Result type - *very* similar, but
 we want to use it in multiple places, so we abstract it into a
 mini-library here
 
 -}
-
 data Result a
     = Bad String
     | Ok a
@@ -39,3 +57,14 @@ instance Monad Result where
     (>>=) (Ok x) fn = fn x
     return = Ok
     fail = Bad
+
+-- | A generic class for items that have updateable names and indices.
+class Element a where
+    -- | Returns the name of the element
+    nameOf  :: a -> String
+    -- | Returns the index of the element
+    idxOf   :: a -> Int
+    -- | Updates the name of the element
+    setName :: a -> String -> a
+    -- | Updates the index of the element
+    setIdx  :: a -> Int -> a