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
44 -- | The instance index type.
47 -- | The node index type.
50 -- | The type used to hold name-to-idx mappings.
51 type NameAssoc = [(String, Int)]
53 -- | A separate name for the cluster score type.
56 -- | The description of an instance placement. It contains the
57 -- instance index, the new primary and secondary node, the move being
58 -- performed and the score of the cluster after the move.
59 type Placement = (Idx, Ndx, Ndx, IMove, Score)
61 -- | An instance move definition
62 data IMove = Failover -- ^ Failover the instance (f)
63 | ReplacePrimary Ndx -- ^ Replace primary (f, r:np, f)
64 | ReplaceSecondary Ndx -- ^ Replace secondary (r:ns)
65 | ReplaceAndFailover Ndx -- ^ Replace secondary, failover (r:np, f)
66 | FailoverAndReplace Ndx -- ^ Failover, replace secondary (f, r:ns)
69 -- | Formatted solution output for one move (involved nodes and
71 type MoveJob = ([Ndx], IMove, [String])
73 -- | A list of command elements
74 type JobSet = [MoveJob]
76 -- | Connection timeout (when using non-file methods).
80 -- | The default timeout for queries (when using non-file methods).
86 This is similar to the JSON library Result type - *very* similar, but
87 we want to use it in multiple places, so we abstract it into a
96 instance Monad Result where
97 (>>=) (Bad x) _ = Bad x
98 (>>=) (Ok x) fn = fn x
102 -- | Reason for an operation's falure
103 data FailMode = FailMem -- ^ Failed due to not enough RAM
104 | FailDisk -- ^ Failed due to not enough disk
105 | FailCPU -- ^ Failed due to not enough CPU capacity
106 | FailN1 -- ^ Failed due to not passing N1 checks
107 deriving (Eq, Enum, Bounded, Show)
109 -- | List with failure statistics
110 type FailStats = [(FailMode, Int)]
112 -- | Either-like data-type customized for our failure modes
113 data OpResult a = OpFail FailMode -- ^ Failed operation
114 | OpGood a -- ^ Success operation
116 instance Monad OpResult where
117 (OpGood x) >>= fn = fn x
118 (OpFail y) >>= _ = OpFail y
121 -- | A generic class for items that have updateable names and indices.
122 class Element a where
123 -- | Returns the name of the element
124 nameOf :: a -> String
125 -- | Returns the index of the element
127 -- | Updates the name of the element
128 setName :: a -> String -> a
129 -- | Updates the index of the element
130 setIdx :: a -> Int -> a