Commit 518023a9 authored by Iustin Pop's avatar Iustin Pop
Browse files

Implement QueryFields for Nodes



Since we have all the definitions already, we can easily enable
this. Manual testing shows no difference between the Python and the
Haskell versions of node list-fields.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent 6f1da8b3
......@@ -294,4 +294,6 @@ $(buildObject "QueryResult" "qres"
data QueryFields = QueryFields ItemType Fields
-- | Query2 Fields result.
data QueryFieldsResult = QueryFieldsResult [ FieldDefinition ]
$(buildObject "QueryFieldsResult" "qfieldres"
[ simpleField "fields" [t| [FieldDefinition ] |]
])
......@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.Query.Query
( query
, queryFields
) where
import Data.Maybe (fromMaybe)
......@@ -79,3 +80,14 @@ query cfg (Query QRNode fields _) = return $ do
query _ (Query qkind _ _) =
return . Bad $ "Query '" ++ show qkind ++ "' not supported"
-- | Query fields call.
queryFields :: QueryFields -> Result QueryFieldsResult
queryFields (QueryFields QRNode fields) =
let selected = if null fields
then map snd $ Map.toAscList nodeFieldsMap
else getSelectedFields nodeFieldsMap fields
in Ok $ QueryFieldsResult (map fst selected)
queryFields (QueryFields qkind _) =
Bad $ "QueryFields '" ++ show qkind ++ "' not supported"
......@@ -131,6 +131,10 @@ handleCall cfg (Query qkind qfields qfilter) = do
result <- query cfg (Qlang.Query qkind qfields qfilter)
return $ J.showJSON <$> result
handleCall _ (QueryFields qkind qfields) = do
let result = queryFields (Qlang.QueryFields qkind qfields)
return $ J.showJSON <$> result
handleCall _ op =
return . Bad $ "Luxi call '" ++ strOfOp op ++ "' not implemented"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment