7 Copyright (C) 2009 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.Types
36 -- | The instance index type.
39 -- | The node index type.
42 -- | The type used to hold name-to-idx mappings.
43 type NameAssoc = [(String, Int)]
47 This is similar to the JSON library Result type - *very* similar, but
48 we want to use it in multiple places, so we abstract it into a
57 instance Monad Result where
58 (>>=) (Bad x) _ = Bad x
59 (>>=) (Ok x) fn = fn x
63 -- | Reason for an operation's falure
64 data FailMode = FailMem -- ^ Failed due to not enough RAM
65 | FailDisk -- ^ Failed due to not enough disk
66 | FailCPU -- ^ Failed due to not enough CPU capacity
67 | FailN1 -- ^ Failed due to not passing N1 checks
68 deriving (Eq, Enum, Bounded, Show)
70 -- | Either-like data-type customized for our failure modes
71 data OpResult a = OpFail FailMode -- ^ Failed operation
72 | OpGood a -- ^ Success operation
74 instance Monad OpResult where
75 (OpGood x) >>= fn = fn x
76 (OpFail y) >>= _ = OpFail y
79 -- | A generic class for items that have updateable names and indices.
81 -- | Returns the name of the element
83 -- | Returns the index of the element
85 -- | Updates the name of the element
86 setName :: a -> String -> a
87 -- | Updates the index of the element
88 setIdx :: a -> Int -> a