Revision f3f76ccc htools/Ganeti/HTools/Utils.hs

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