Revision 497e30a1
b/Ganeti/HTools/IAlloc.hs | ||
---|---|---|
82 | 82 |
nlist <- fromObj "nodes" obj |
83 | 83 |
let ndata = fromJSObject nlist |
84 | 84 |
nobj <- (mapM (\(x,y) -> asJSObject y >>= parseNode x)) ndata |
85 |
let (ktn, nl) = assignIndices Node.setIdx nobj
|
|
85 |
let (ktn, nl) = assignIndices nobj |
|
86 | 86 |
-- existing instance parsing |
87 | 87 |
ilist <- fromObj "instances" obj |
88 | 88 |
let idata = fromJSObject ilist |
89 | 89 |
iobj <- (mapM (\(x,y) -> asJSObject y >>= parseInstance ktn x)) idata |
90 |
let (kti, il) = assignIndices Instance.setIdx iobj
|
|
90 |
let (kti, il) = assignIndices iobj |
|
91 | 91 |
optype <- fromObj "type" request |
92 | 92 |
rqtype <- |
93 | 93 |
case optype of |
b/Ganeti/HTools/Instance.hs | ||
---|---|---|
62 | 62 |
-> Int -- ^ new index |
63 | 63 |
-> Instance -- ^ the modified instance |
64 | 64 |
setIdx t i = t { idx = i } |
65 |
|
|
66 |
-- | Changes the name |
|
67 |
-- This is used only during the building of the data structures. |
|
68 |
setName t s = t {name = s} |
b/Ganeti/HTools/Loader.hs | ||
---|---|---|
28 | 28 |
Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst |
29 | 29 |
Just idx -> return idx |
30 | 30 |
|
31 |
assignIndices :: (a -> Int -> a)
|
|
32 |
-> [(String, a)]
|
|
31 |
assignIndices :: (Element a) =>
|
|
32 |
[(String, a)]
|
|
33 | 33 |
-> (NameAssoc, [(Int, a)]) |
34 |
assignIndices set_fn =
|
|
35 |
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, set_fn v idx)))
|
|
34 |
assignIndices = |
|
35 |
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx)))
|
|
36 | 36 |
. zip [0..] |
37 | 37 |
|
38 | 38 |
-- | For each instance, add its index to its primary and secondary nodes |
b/Ganeti/HTools/Node.hs | ||
---|---|---|
14 | 14 |
-- ** Finalization after data loading |
15 | 15 |
, buildPeers |
16 | 16 |
, setIdx |
17 |
, setName |
|
17 | 18 |
, setOffline |
18 | 19 |
, setXmem |
19 | 20 |
, setFmem |
... | ... | |
102 | 103 |
setIdx :: Node -> Int -> Node |
103 | 104 |
setIdx t i = t {idx = i} |
104 | 105 |
|
106 |
-- | Changes the name |
|
107 |
-- This is used only during the building of the data structures. |
|
108 |
setName t s = t {name = s} |
|
109 |
|
|
105 | 110 |
-- | Sets the offline attribute |
106 | 111 |
setOffline :: Node -> Bool -> Node |
107 | 112 |
setOffline t val = t { offline = val } |
b/Ganeti/HTools/Rapi.hs | ||
---|---|---|
92 | 92 |
inst_body <- getUrl $ printf "%s/2/instances?bulk=1" url |
93 | 93 |
return $ do -- Result monad |
94 | 94 |
node_data <- node_body >>= getNodes |
95 |
let (node_names, node_idx) = assignIndices Node.setIdx node_data
|
|
95 |
let (node_names, node_idx) = assignIndices node_data |
|
96 | 96 |
inst_data <- inst_body >>= getInstances node_names |
97 |
let (inst_names, inst_idx) = assignIndices Instance.setIdx inst_data
|
|
97 |
let (inst_names, inst_idx) = assignIndices inst_data |
|
98 | 98 |
return (node_names, node_idx, inst_names, inst_idx) |
b/Ganeti/HTools/Text.hs | ||
---|---|---|
64 | 64 |
supplied conversion function. |
65 | 65 |
|
66 | 66 |
-} |
67 |
loadTabular :: (Monad m) => String -> ([String] -> m (String, a)) |
|
68 |
-> (a -> Int -> a) -> m ([(String, Int)], [(Int, a)]) |
|
69 |
loadTabular text_data convert_fn set_fn = do |
|
67 |
loadTabular :: (Monad m, Element a) => |
|
68 |
String -> ([String] -> m (String, a)) |
|
69 |
-> m ([(String, Int)], [(Int, a)]) |
|
70 |
loadTabular text_data convert_fn = do |
|
70 | 71 |
let lines_data = lines text_data |
71 | 72 |
rows = map (sepSplit '|') lines_data |
72 | 73 |
kerows <- mapM convert_fn rows |
73 |
return $ assignIndices set_fn kerows
|
|
74 |
return $ assignIndices kerows |
|
74 | 75 |
|
75 | 76 |
loadData :: String -- ^ Node data in string format |
76 | 77 |
-> String -- ^ Instance data in string format |
... | ... | |
81 | 82 |
idata <- readFile ifile |
82 | 83 |
return $ do |
83 | 84 |
{- node file: name t_mem n_mem f_mem t_disk f_disk -} |
84 |
(ktn, nl) <- loadTabular ndata loadNode Node.setIdx
|
|
85 |
(ktn, nl) <- loadTabular ndata loadNode |
|
85 | 86 |
{- instance file: name mem disk status pnode snode -} |
86 |
(kti, il) <- loadTabular idata (loadInst ktn) Instance.setIdx
|
|
87 |
(kti, il) <- loadTabular idata (loadInst ktn) |
|
87 | 88 |
return (ktn, nl, kti, il) |
b/Ganeti/HTools/Types.hs | ||
---|---|---|
39 | 39 |
(>>=) (Ok x) fn = fn x |
40 | 40 |
return = Ok |
41 | 41 |
fail = Bad |
42 |
|
|
43 |
-- | A generic class for nodes and instances |
|
44 |
class Element a where |
|
45 |
name :: a -> String |
|
46 |
idx :: a -> Int |
|
47 |
setName :: a -> String -> a |
|
48 |
setIdx :: a -> Int -> a |
|
49 |
|
|
50 |
-- Let's make nodes elements of the cluster |
|
51 |
instance Element Node.Node where |
|
52 |
name = Node.name |
|
53 |
idx = Node.idx |
|
54 |
setName = Node.setName |
|
55 |
setIdx = Node.setIdx |
|
56 |
|
|
57 |
-- And instances too |
|
58 |
instance Element Instance.Instance where |
|
59 |
name = Instance.name |
|
60 |
idx = Instance.idx |
|
61 |
setName = Instance.setName |
|
62 |
setIdx = Instance.setIdx |
Also available in: Unified diff