Revision 525bfb36 htools/Ganeti/HTools/Types.hs
b/htools/Ganeti/HTools/Types.hs | ||
---|---|---|
102 | 102 |
-- allocations |
103 | 103 |
deriving (Show, Read, Eq, Ord) |
104 | 104 |
|
105 |
-- | Convert a string to an alloc policy |
|
105 |
-- | Convert a string to an alloc policy.
|
|
106 | 106 |
apolFromString :: (Monad m) => String -> m AllocPolicy |
107 | 107 |
apolFromString s = |
108 | 108 |
case () of |
... | ... | |
111 | 111 |
| s == C.allocPolicyUnallocable -> return AllocUnallocable |
112 | 112 |
| otherwise -> fail $ "Invalid alloc policy mode: " ++ s |
113 | 113 |
|
114 |
-- | Convert an alloc policy to the Ganeti string equivalent |
|
114 |
-- | Convert an alloc policy to the Ganeti string equivalent.
|
|
115 | 115 |
apolToString :: AllocPolicy -> String |
116 | 116 |
apolToString AllocPreferred = C.allocPolicyPreferred |
117 | 117 |
apolToString AllocLastResort = C.allocPolicyLastResort |
... | ... | |
140 | 140 |
, netWeight :: Weight -- ^ Standardised network usage |
141 | 141 |
} deriving (Show, Read, Eq) |
142 | 142 |
|
143 |
-- | Initial empty utilisation |
|
143 |
-- | Initial empty utilisation.
|
|
144 | 144 |
zeroUtil :: DynUtil |
145 | 145 |
zeroUtil = DynUtil { cpuWeight = 0, memWeight = 0 |
146 | 146 |
, dskWeight = 0, netWeight = 0 } |
147 | 147 |
|
148 |
-- | Base utilisation (used when no actual utilisation data is |
|
149 |
-- supplied). |
|
148 | 150 |
baseUtil :: DynUtil |
149 | 151 |
baseUtil = DynUtil { cpuWeight = 1, memWeight = 1 |
150 | 152 |
, dskWeight = 1, netWeight = 1 } |
151 | 153 |
|
154 |
-- | Sum two utilisation records. |
|
152 | 155 |
addUtil :: DynUtil -> DynUtil -> DynUtil |
153 | 156 |
addUtil (DynUtil a1 a2 a3 a4) (DynUtil b1 b2 b3 b4) = |
154 | 157 |
DynUtil (a1+b1) (a2+b2) (a3+b3) (a4+b4) |
155 | 158 |
|
159 |
-- | Substracts one utilisation record from another. |
|
156 | 160 |
subUtil :: DynUtil -> DynUtil -> DynUtil |
157 | 161 |
subUtil (DynUtil a1 a2 a3 a4) (DynUtil b1 b2 b3 b4) = |
158 | 162 |
DynUtil (a1-b1) (a2-b2) (a3-b3) (a4-b4) |
... | ... | |
162 | 166 |
-- performed and the score of the cluster after the move. |
163 | 167 |
type Placement = (Idx, Ndx, Ndx, IMove, Score) |
164 | 168 |
|
165 |
-- | An instance move definition |
|
169 |
-- | An instance move definition.
|
|
166 | 170 |
data IMove = Failover -- ^ Failover the instance (f) |
167 | 171 |
| ReplacePrimary Ndx -- ^ Replace primary (f, r:np, f) |
168 | 172 |
| ReplaceSecondary Ndx -- ^ Replace secondary (r:ns) |
... | ... | |
171 | 175 |
deriving (Show, Read) |
172 | 176 |
|
173 | 177 |
-- | Formatted solution output for one move (involved nodes and |
174 |
-- commands |
|
178 |
-- commands.
|
|
175 | 179 |
type MoveJob = ([Ndx], Idx, IMove, [String]) |
176 | 180 |
|
177 |
-- | Unknown field in table output |
|
181 |
-- | Unknown field in table output.
|
|
178 | 182 |
unknownField :: String |
179 | 183 |
unknownField = "<unknown field>" |
180 | 184 |
|
181 |
-- | A list of command elements |
|
185 |
-- | A list of command elements.
|
|
182 | 186 |
type JobSet = [MoveJob] |
183 | 187 |
|
184 | 188 |
-- | Connection timeout (when using non-file methods). |
... | ... | |
211 | 215 |
|
212 | 216 |
{-| |
213 | 217 |
|
214 |
This is similar to the JSON library Result type - *very* similar, but
|
|
218 |
This is similar to the JSON library Result type - /very/ similar, but
|
|
215 | 219 |
we want to use it in multiple places, so we abstract it into a |
216 | 220 |
mini-library here |
217 | 221 |
|
... | ... | |
227 | 231 |
return = Ok |
228 | 232 |
fail = Bad |
229 | 233 |
|
230 |
-- | Simple checker for whether Result is OK
|
|
234 |
-- | Simple checker for whether a 'Result' is OK.
|
|
231 | 235 |
isOk :: Result a -> Bool |
232 | 236 |
isOk (Ok _) = True |
233 | 237 |
isOk _ = False |
234 | 238 |
|
235 |
-- | Simple checker for whether Result is a failure
|
|
239 |
-- | Simple checker for whether a 'Result' is a failure.
|
|
236 | 240 |
isBad :: Result a -> Bool |
237 | 241 |
isBad = not . isOk |
238 | 242 |
|
239 |
-- | Reason for an operation's falure |
|
243 |
-- | Reason for an operation's falure.
|
|
240 | 244 |
data FailMode = FailMem -- ^ Failed due to not enough RAM |
241 | 245 |
| FailDisk -- ^ Failed due to not enough disk |
242 | 246 |
| FailCPU -- ^ Failed due to not enough CPU capacity |
... | ... | |
244 | 248 |
| FailTags -- ^ Failed due to tag exclusion |
245 | 249 |
deriving (Eq, Enum, Bounded, Show, Read) |
246 | 250 |
|
247 |
-- | List with failure statistics |
|
251 |
-- | List with failure statistics.
|
|
248 | 252 |
type FailStats = [(FailMode, Int)] |
249 | 253 |
|
250 |
-- | Either-like data-type customized for our failure modes |
|
254 |
-- | Either-like data-type customized for our failure modes.
|
|
251 | 255 |
data OpResult a = OpFail FailMode -- ^ Failed operation |
252 | 256 |
| OpGood a -- ^ Success operation |
253 | 257 |
deriving (Show, Read) |
... | ... | |
268 | 272 |
-- | Updates the alias of the element |
269 | 273 |
setAlias :: a -> String -> a |
270 | 274 |
-- | Compute the alias by stripping a given suffix (domain) from |
271 |
-- | the name
|
|
275 |
-- the name |
|
272 | 276 |
computeAlias :: String -> a -> a |
273 | 277 |
computeAlias dom e = setAlias e alias |
274 | 278 |
where alias = take (length name - length dom) name |
Also available in: Unified diff