Revision 260d0bda htools/Ganeti/Luxi.hs

b/htools/Ganeti/Luxi.hs
28 28
module Ganeti.Luxi
29 29
    ( LuxiOp(..)
30 30
    , QrViaLuxi(..)
31
    , ResultStatus(..)
31 32
    , Client
33
    , checkRS
32 34
    , getClient
33 35
    , closeClient
34 36
    , callMethod
......
145 147
-- | The serialisation of LuxiOps into strings in messages.
146 148
$(genStrOfOp ''LuxiOp "strOfOp")
147 149

  
150
$(declareIADT "ResultStatus"
151
     [ ("RSNormal", 'rsNormal)
152
     , ("RSUnknown", 'rsUnknown)
153
     , ("RSNoData", 'rsNodata)
154
     , ("RSUnavailable", 'rsUnavail)
155
     , ("RSOffline", 'rsOffline)
156
     ])
157
$(makeJSONInstanceInt ''ResultStatus)
158

  
159
-- | Check that ResultStatus is success or fail with descriptive message.
160
checkRS :: (Monad m) => ResultStatus -> a -> m a
161
checkRS RSNormal val    = return val
162
checkRS RSUnknown _     = fail "Unknown field"
163
checkRS RSNoData _      = fail "No data for a field"
164
checkRS RSUnavailable _ = fail "Ganeti reports unavailable data"
165
checkRS RSOffline _     = fail "Ganeti reports resource as offline"
166

  
148 167
-- | The end-of-message separator.
149 168
eOM :: Char
150 169
eOM = '\3'

Also available in: Unified diff