Revision cd67e337 htools/Ganeti/Query/Query.hs

b/htools/Ganeti/Query/Query.hs
45 45
-}
46 46

  
47 47
module Ganeti.Query.Query
48

  
49 48
    ( query
50 49
    , queryFields
50
    , queryCompat
51 51
    , getRequestedNames
52
    , nameField
52 53
    ) where
53 54

  
54 55
import Control.Monad (filterM)
55 56
import Control.Monad.Trans (lift)
57
import Data.List (intercalate)
56 58
import Data.Maybe (fromMaybe)
57 59
import qualified Data.Map as Map
60
import qualified Text.JSON as J
58 61

  
59 62
import Ganeti.BasicTypes
60 63
import Ganeti.Config
......
209 212

  
210 213
queryFields (QueryFields qkind _) =
211 214
  Bad $ "QueryFields '" ++ show qkind ++ "' not supported"
215

  
216
-- | Classic query converter. It gets a standard query result on input
217
-- and computes the classic style results.
218
queryCompat :: QueryResult -> Result [[J.JSValue]]
219
queryCompat (QueryResult fields qrdata) =
220
  case map fdefName $ filter ((== QFTUnknown) . fdefKind) fields of
221
    [] -> Ok $ map (map (maybe J.JSNull J.showJSON . rentryValue)) qrdata
222
    unknown -> Bad $ "Unknown output fields selected: " ++
223
                     intercalate ", " unknown

Also available in: Unified diff