Revision 9188aeef Ganeti/HTools/Loader.hs
b/Ganeti/HTools/Loader.hs | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import Ganeti.HTools.Types |
25 | 25 |
|
26 |
-- | Lookups a node into an assoc list |
|
26 |
-- | Lookups a node into an assoc list.
|
|
27 | 27 |
lookupNode :: (Monad m) => [(String, Ndx)] -> String -> String -> m Ndx |
28 | 28 |
lookupNode ktn inst node = |
29 | 29 |
case lookup node ktn of |
30 | 30 |
Nothing -> fail $ "Unknown node '" ++ node ++ "' for instance " ++ inst |
31 | 31 |
Just idx -> return idx |
32 | 32 |
|
33 |
-- | Lookups an instance into an assoc list |
|
33 |
-- | Lookups an instance into an assoc list.
|
|
34 | 34 |
lookupInstance :: (Monad m) => [(String, Idx)] -> String -> m Idx |
35 | 35 |
lookupInstance kti inst = |
36 | 36 |
case lookup inst kti of |
37 | 37 |
Nothing -> fail $ "Unknown instance '" ++ inst ++ "'" |
38 | 38 |
Just idx -> return idx |
39 | 39 |
|
40 |
-- | Given a list of elements (and their names), assign indices to them |
|
40 |
-- | Given a list of elements (and their names), assign indices to them.
|
|
41 | 41 |
assignIndices :: (Element a) => |
42 | 42 |
[(String, a)] |
43 | 43 |
-> (NameAssoc, [(Int, a)]) |
... | ... | |
45 | 45 |
unzip . map (\ (idx, (k, v)) -> ((k, idx), (idx, setIdx v idx))) |
46 | 46 |
. zip [0..] |
47 | 47 |
|
48 |
-- | For each instance, add its index to its primary and secondary nodes |
|
48 |
-- | For each instance, add its index to its primary and secondary nodes.
|
|
49 | 49 |
fixNodes :: [(Ndx, Node.Node)] |
50 | 50 |
-> [(Idx, Instance.Instance)] |
51 | 51 |
-> [(Ndx, Node.Node)] |
... | ... | |
72 | 72 |
) nl il |
73 | 73 |
|
74 | 74 |
-- | Compute the longest common suffix of a list of strings that |
75 |
-- | starts with a dot |
|
75 |
-- | starts with a dot.
|
|
76 | 76 |
longestDomain :: [String] -> String |
77 | 77 |
longestDomain [] = "" |
78 | 78 |
longestDomain (x:xs) = |
... | ... | |
81 | 81 |
else accu) |
82 | 82 |
"" $ filter (isPrefixOf ".") (tails x) |
83 | 83 |
|
84 |
-- | Remove tail suffix from a string |
|
84 |
-- | Remove tail suffix from a string.
|
|
85 | 85 |
stripSuffix :: Int -> String -> String |
86 | 86 |
stripSuffix sflen name = take ((length name) - sflen) name |
87 | 87 |
|
88 |
{-| Initializer function that loads the data from a node and list file
|
|
89 |
and massages it into the correct format. -}
|
|
88 |
-- | Initializer function that loads the data from a node and instance
|
|
89 |
-- list and massages it into the correct format.
|
|
90 | 90 |
mergeData :: (Node.AssocList, |
91 | 91 |
Instance.AssocList) -- ^ Data from either Text.loadData |
92 | 92 |
-- or Rapi.loadData |
... | ... | |
105 | 105 |
sil = Container.map (\i -> setName i (stripSuffix csl $ nameOf i)) il3 |
106 | 106 |
return (snl, sil, common_suffix) |
107 | 107 |
|
108 |
-- | Check cluster data for consistency
|
|
108 |
-- | Checks the cluster data for consistency.
|
|
109 | 109 |
checkData :: Node.List -> Instance.List |
110 | 110 |
-> ([String], Node.List) |
111 | 111 |
checkData nl il = |
Also available in: Unified diff