Revision 3603605a htools/Ganeti/HTools/IAlloc.hs
b/htools/Ganeti/HTools/IAlloc.hs | ||
---|---|---|
50 | 50 |
import Ganeti.HTools.Utils |
51 | 51 |
import Ganeti.HTools.Types |
52 | 52 |
|
53 |
{-# ANN module "HLint: ignore Eta reduce" #-} |
|
54 |
|
|
53 | 55 |
-- | Type alias for the result of an IAllocator call. |
54 | 56 |
type IAllocResult = (String, JSValue, Node.List, Instance.List) |
55 | 57 |
|
... | ... | |
83 | 85 |
else readEitherString $ head nodes |
84 | 86 |
pidx <- lookupNode ktn n pnode |
85 | 87 |
let snodes = tail nodes |
86 |
sidx <- (if null snodes then return Node.noSecondary |
|
87 |
else readEitherString (head snodes) >>= lookupNode ktn n) |
|
88 |
sidx <- if null snodes |
|
89 |
then return Node.noSecondary |
|
90 |
else readEitherString (head snodes) >>= lookupNode ktn n |
|
88 | 91 |
return (n, Instance.setBoth (snd base) pidx sidx) |
89 | 92 |
|
90 | 93 |
-- | Parses a node as found in the cluster node list. |
... | ... | |
101 | 104 |
vm_capable <- annotateResult desc $ maybeFromObj a "vm_capable" |
102 | 105 |
let vm_capable' = fromMaybe True vm_capable |
103 | 106 |
gidx <- lookupGroup ktg n guuid |
104 |
node <- (if offline || drained || not vm_capable'
|
|
105 |
then return $ Node.create n 0 0 0 0 0 0 True gidx |
|
106 |
else do |
|
107 |
mtotal <- extract "total_memory" |
|
108 |
mnode <- extract "reserved_memory" |
|
109 |
mfree <- extract "free_memory" |
|
110 |
dtotal <- extract "total_disk" |
|
111 |
dfree <- extract "free_disk" |
|
112 |
ctotal <- extract "total_cpus" |
|
113 |
return $ Node.create n mtotal mnode mfree |
|
114 |
dtotal dfree ctotal False gidx)
|
|
107 |
node <- if offline || drained || not vm_capable' |
|
108 |
then return $ Node.create n 0 0 0 0 0 0 True gidx
|
|
109 |
else do
|
|
110 |
mtotal <- extract "total_memory"
|
|
111 |
mnode <- extract "reserved_memory"
|
|
112 |
mfree <- extract "free_memory"
|
|
113 |
dtotal <- extract "total_disk"
|
|
114 |
dfree <- extract "free_disk"
|
|
115 |
ctotal <- extract "total_cpus"
|
|
116 |
return $ Node.create n mtotal mnode mfree
|
|
117 |
dtotal dfree ctotal False gidx
|
|
115 | 118 |
return (n, node) |
116 | 119 |
|
117 | 120 |
-- | Parses a group as found in the cluster group list. |
... | ... | |
330 | 333 |
hPutStrLn stderr $ "Error: " ++ err |
331 | 334 |
exitWith $ ExitFailure 1 |
332 | 335 |
Ok (fix_msgs, rq) -> maybeShowWarnings fix_msgs >> return rq |
333 |
(if isJust (optDataFile opts) || (not . null . optNodeSim) opts
|
|
334 |
then do |
|
335 |
cdata <- loadExternalData opts |
|
336 |
let Request rqt _ = r1 |
|
337 |
return $ Request rqt cdata |
|
338 |
else return r1)
|
|
336 |
if isJust (optDataFile opts) || (not . null . optNodeSim) opts |
|
337 |
then do
|
|
338 |
cdata <- loadExternalData opts
|
|
339 |
let Request rqt _ = r1
|
|
340 |
return $ Request rqt cdata
|
|
341 |
else return r1
|
|
339 | 342 |
|
340 | 343 |
-- | Main iallocator pipeline. |
341 | 344 |
runIAllocator :: Request -> (Maybe (Node.List, Instance.List), String) |
Also available in: Unified diff