Revision 5183e8be htools/Ganeti/Query/Server.hs

b/htools/Ganeti/Query/Server.hs
42 42
import System.Info (arch)
43 43

  
44 44
import qualified Ganeti.Constants as C
45
import Ganeti.Errors
45 46
import qualified Ganeti.Path as Path
46 47
import Ganeti.Daemon
47 48
import Ganeti.Objects
......
63 64
                   -> [String]        -- ^ Requested names (empty means all)
64 65
                   -> [String]        -- ^ Requested fields
65 66
                   -> Bool            -- ^ Whether to do sync queries or not
66
                   -> IO (Result JSValue)
67
handleClassicQuery _ _ _ _ True = return . Bad $ "Sync queries are not allowed"
67
                   -> IO (GenericResult GanetiException JSValue)
68
handleClassicQuery _ _ _ _ True =
69
  return . Bad $ OpPrereqError "Sync queries are not allowed" ECodeInval
68 70
handleClassicQuery cfg qkind names fields _ = do
69 71
  let flt = makeSimpleFilter (nameField qkind) names
70 72
  qr <- query cfg True (Qlang.Query qkind fields flt)
71 73
  return $ showJSON <$> (qr >>= queryCompat)
72 74

  
73 75
-- | Minimal wrapper to handle the missing config case.
74
handleCallWrapper :: Result ConfigData -> LuxiOp -> IO (Result JSValue)
76
handleCallWrapper :: Result ConfigData -> LuxiOp -> IO (ErrorResult JSValue)
75 77
handleCallWrapper (Bad msg) _ =
76
  return . Bad $ "I do not have access to a valid configuration, cannot\
77
                 \ process queries: " ++ msg
78
  return . Bad . ConfigurationError $
79
           "I do not have access to a valid configuration, cannot\
80
           \ process queries: " ++ msg
78 81
handleCallWrapper (Ok config) op = handleCall config op
79 82

  
80 83
-- | Actual luxi operation handler.
81
handleCall :: ConfigData -> LuxiOp -> IO (Result JSValue)
84
handleCall :: ConfigData -> LuxiOp -> IO (ErrorResult JSValue)
82 85
handleCall cdata QueryClusterInfo =
83 86
  let cluster = configCluster cdata
84 87
      hypervisors = clusterEnabledHypervisors cluster
......
157 160
  handleClassicQuery cfg Qlang.QRGroup names fields lock
158 161

  
159 162
handleCall _ op =
160
  return . Bad $ "Luxi call '" ++ strOfOp op ++ "' not implemented"
163
  return . Bad $
164
    GenericError ("Luxi call '" ++ strOfOp op ++ "' not implemented")
161 165

  
162 166

  
163 167
-- | Given a decoded luxi request, executes it and sends the luxi
......
170 174
  (!status, !rval) <-
171 175
    case call_result of
172 176
      Bad err -> do
173
        let errmsg = "Failed to execute request: " ++ err
174
        logWarning errmsg
175
        return (False, showJSON errmsg)
177
        logWarning $ "Failed to execute request: " ++ show err
178
        return (False, showJSON err)
176 179
      Ok result -> do
177 180
        logDebug $ "Result " ++ show (pp_value result)
178 181
        return (True, result)

Also available in: Unified diff