Revision 9188aeef Ganeti/HTools/Text.hs
b/Ganeti/HTools/Text.hs | ||
---|---|---|
16 | 16 |
import qualified Ganeti.HTools.Node as Node |
17 | 17 |
import qualified Ganeti.HTools.Instance as Instance |
18 | 18 |
|
19 |
-- | Safe 'read' function returning data encapsulated in a Result |
|
19 |
-- | Safe 'read' function returning data encapsulated in a Result.
|
|
20 | 20 |
tryRead :: (Monad m, Read a) => String -> String -> m a |
21 | 21 |
tryRead name s = |
22 | 22 |
let sols = readsPrec 0 s |
... | ... | |
26 | 26 |
++ s ++ "': '" ++ e ++ "'" |
27 | 27 |
_ -> fail $ name ++ ": cannot parse string '" ++ s ++ "'" |
28 | 28 |
|
29 |
-- | Load a node from a field list |
|
29 |
-- | Load a node from a field list.
|
|
30 | 30 |
loadNode :: (Monad m) => [String] -> m (String, Node.Node) |
31 | 31 |
loadNode (name:tm:nm:fm:td:fd:fo:[]) = do |
32 | 32 |
new_node <- |
... | ... | |
42 | 42 |
return (name, new_node) |
43 | 43 |
loadNode s = fail $ "Invalid/incomplete node data: '" ++ (show s) ++ "'" |
44 | 44 |
|
45 |
-- | Load an instance from a field list |
|
45 |
-- | Load an instance from a field list.
|
|
46 | 46 |
loadInst :: (Monad m) => |
47 | 47 |
[(String, Ndx)] -> [String] -> m (String, Instance.Instance) |
48 | 48 |
loadInst ktn (name:mem:dsk:status:pnode:snode:[]) = do |
... | ... | |
57 | 57 |
return (name, newinst) |
58 | 58 |
loadInst _ s = fail $ "Invalid/incomplete instance data: '" ++ (show s) ++ "'" |
59 | 59 |
|
60 |
{- | Convert newline and delimiter-separated text. |
|
61 |
|
|
62 |
This function converts a text in tabular format as generated by |
|
63 |
@gnt-instance list@ and @gnt-node list@ to a list of objects using a |
|
64 |
supplied conversion function. |
|
65 |
|
|
66 |
-} |
|
60 |
-- | Convert newline and delimiter-separated text. |
|
61 |
-- |
|
62 |
-- This function converts a text in tabular format as generated by |
|
63 |
-- @gnt-instance list@ and @gnt-node list@ to a list of objects using |
|
64 |
-- a supplied conversion function. |
|
67 | 65 |
loadTabular :: (Monad m, Element a) => |
68 | 66 |
String -> ([String] -> m (String, a)) |
69 | 67 |
-> m ([(String, Int)], [(Int, a)]) |
... | ... | |
73 | 71 |
kerows <- mapM convert_fn rows |
74 | 72 |
return $ assignIndices kerows |
75 | 73 |
|
74 |
-- | Builds the cluster data from node\/instance files. |
|
76 | 75 |
loadData :: String -- ^ Node data in string format |
77 | 76 |
-> String -- ^ Instance data in string format |
78 | 77 |
-> IO (Result (Node.AssocList, Instance.AssocList)) |
Also available in: Unified diff