Revision f3f76ccc
b/htools/Ganeti/BasicTypes.hs | ||
---|---|---|
24 | 24 |
, isOk |
25 | 25 |
, isBad |
26 | 26 |
, eitherToResult |
27 |
, annotateResult |
|
27 | 28 |
) where |
28 | 29 |
|
29 | 30 |
import Control.Monad |
... | ... | |
65 | 66 |
eitherToResult :: Either String a -> Result a |
66 | 67 |
eitherToResult (Left s) = Bad s |
67 | 68 |
eitherToResult (Right v) = Ok v |
69 |
|
|
70 |
-- | Annotate a Result with an ownership information. |
|
71 |
annotateResult :: String -> Result a -> Result a |
|
72 |
annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s |
|
73 |
annotateResult _ v = v |
b/htools/Ganeti/HTools/JSON.hs | ||
---|---|---|
33 | 33 |
, fromJVal |
34 | 34 |
, asJSObject |
35 | 35 |
, asObjectList |
36 |
, tryFromObj |
|
36 | 37 |
) |
37 | 38 |
where |
38 | 39 |
|
... | ... | |
42 | 43 |
|
43 | 44 |
import qualified Text.JSON as J |
44 | 45 |
|
46 |
import Ganeti.BasicTypes |
|
47 |
|
|
45 | 48 |
-- * JSON-related functions |
46 | 49 |
|
47 | 50 |
-- | A type alias for the list-based representation of J.JSObject. |
... | ... | |
114 | 117 |
-- | Coneverts a list of JSON values into a list of JSON objects. |
115 | 118 |
asObjectList :: (Monad m) => [J.JSValue] -> m [J.JSObject J.JSValue] |
116 | 119 |
asObjectList = mapM asJSObject |
120 |
|
|
121 |
-- | Try to extract a key from a object with better error reporting |
|
122 |
-- than fromObj. |
|
123 |
tryFromObj :: (J.JSON a) => |
|
124 |
String -- ^ Textual "owner" in error messages |
|
125 |
-> JSRecord -- ^ The object array |
|
126 |
-> String -- ^ The desired key from the object |
|
127 |
-> Result a |
|
128 |
tryFromObj t o = annotateResult t . fromObj o |
b/htools/Ganeti/HTools/Luxi.hs | ||
---|---|---|
38 | 38 |
import qualified Ganeti.HTools.Group as Group |
39 | 39 |
import qualified Ganeti.HTools.Node as Node |
40 | 40 |
import qualified Ganeti.HTools.Instance as Instance |
41 |
import Ganeti.HTools.Utils (fromJVal, annotateResult, tryFromObj, asJSObject,
|
|
41 |
import Ganeti.HTools.Utils (fromJVal, tryFromObj, asJSObject, |
|
42 | 42 |
fromObj) |
43 | 43 |
|
44 | 44 |
{-# ANN module "HLint: ignore Eta reduce" #-} |
b/htools/Ganeti/HTools/QC.hs | ||
---|---|---|
91 | 91 |
|
92 | 92 |
defGroup :: Group.Group |
93 | 93 |
defGroup = flip Group.setIdx 0 $ |
94 |
Group.create "default" Utils.defaultGroupID Types.AllocPreferred
|
|
94 |
Group.create "default" Types.defaultGroupID Types.AllocPreferred
|
|
95 | 95 |
|
96 | 96 |
defGroupList :: Group.List |
97 | 97 |
defGroupList = Container.fromList [(Group.idx defGroup, defGroup)] |
b/htools/Ganeti/HTools/Types.hs | ||
---|---|---|
33 | 33 |
, Score |
34 | 34 |
, Weight |
35 | 35 |
, GroupID |
36 |
, defaultGroupID |
|
36 | 37 |
, AllocPolicy(..) |
37 | 38 |
, allocPolicyFromRaw |
38 | 39 |
, allocPolicyToRaw |
... | ... | |
62 | 63 |
, isOk |
63 | 64 |
, isBad |
64 | 65 |
, eitherToResult |
66 |
, annotateResult |
|
65 | 67 |
, Element(..) |
66 | 68 |
, FailMode(..) |
67 | 69 |
, FailStats |
... | ... | |
100 | 102 |
-- | The Group UUID type. |
101 | 103 |
type GroupID = String |
102 | 104 |
|
105 |
-- | Default group UUID (just a string, not a real UUID). |
|
106 |
defaultGroupID :: GroupID |
|
107 |
defaultGroupID = "00000000-0000-0000-0000-000000000000" |
|
108 |
|
|
103 | 109 |
-- | The Group allocation policy type. |
104 | 110 |
-- |
105 | 111 |
-- Note that the order of constructors is important as the automatic |
b/htools/Ganeti/HTools/Utils.hs | ||
---|---|---|
44 | 44 |
, fromJResult |
45 | 45 |
, tryRead |
46 | 46 |
, formatTable |
47 |
, annotateResult |
|
48 |
, defaultGroupID |
|
49 | 47 |
, parseUnit |
50 | 48 |
) where |
51 | 49 |
|
52 | 50 |
import Data.Char (toUpper) |
53 | 51 |
import Data.List |
54 |
import qualified Text.JSON as J |
|
55 | 52 |
|
56 | 53 |
import Debug.Trace |
57 | 54 |
|
58 |
import Ganeti.HTools.Types |
|
59 | 55 |
-- we will re-export these for our existing users |
60 | 56 |
import Ganeti.HTools.JSON |
61 | 57 |
|
... | ... | |
134 | 130 |
-> a -- ^ first result which has a True condition, or default |
135 | 131 |
select def = maybe def snd . find fst |
136 | 132 |
|
137 |
-- | Annotate a Result with an ownership information. |
|
138 |
annotateResult :: String -> Result a -> Result a |
|
139 |
annotateResult owner (Bad s) = Bad $ owner ++ ": " ++ s |
|
140 |
annotateResult _ v = v |
|
141 |
|
|
142 |
-- | Try to extract a key from a object with better error reporting |
|
143 |
-- than fromObj. |
|
144 |
tryFromObj :: (J.JSON a) => |
|
145 |
String -- ^ Textual "owner" in error messages |
|
146 |
-> JSRecord -- ^ The object array |
|
147 |
-> String -- ^ The desired key from the object |
|
148 |
-> Result a |
|
149 |
tryFromObj t o = annotateResult t . fromObj o |
|
150 |
|
|
151 | 133 |
|
152 | 134 |
-- * Parsing utility functions |
153 | 135 |
|
... | ... | |
182 | 164 |
) (zip3 vtrans numpos mlens) |
183 | 165 |
in transpose expnd |
184 | 166 |
|
185 |
-- | Default group UUID (just a string, not a real UUID). |
|
186 |
defaultGroupID :: GroupID |
|
187 |
defaultGroupID = "00000000-0000-0000-0000-000000000000" |
|
188 |
|
|
189 | 167 |
-- | Tries to extract number and scale from the given string. |
190 | 168 |
-- |
191 | 169 |
-- Input must be in the format NUMBER+ SPACE* [UNIT]. If no unit is |
Also available in: Unified diff