Commit 13ef1fa5 authored by Hrvoje Ribicic's avatar Hrvoje Ribicic
Browse files

Allow classic queries to use either names or UUIDs

When UUIDs are used in CLI commands, such addressing of objects fails
or succeeds inconsistently across object types. Worse yet, some calls
do not fail, but simply return no result. This is due to the way the
classical queries are handled in the Haskell code - a filter is built,
checking if the names match. If the names do not match, but the object
can still be retrieved through UUID, the query is successful, but there
is nothing to return.

This patch remedies the situation by extending the filter into an or
clause checking for either name or uuid. For objects that have no uuid
field, the name is reused, making the filter equivalent to the old one.

Works towards resolving issue 703.
Signed-off-by: default avatarHrvoje Ribicic <>
Reviewed-by: default avatarKlaus Aehlig <>
parent c02b8f91
......@@ -50,6 +50,7 @@ module Ganeti.Query.Query
, queryCompat
, getRequestedNames
, nameField
, uuidField
) where
import Control.DeepSeq
......@@ -121,6 +122,13 @@ nameField (ItemTypeLuxi QRJob) = "id"
nameField (ItemTypeOpCode QRExport) = "node"
nameField _ = "name"
-- | Computes the uuid field, or the best possible substitute, for different
-- query types.
uuidField :: ItemType -> FilterField
uuidField (ItemTypeLuxi QRJob) = nameField (ItemTypeLuxi QRJob)
uuidField (ItemTypeOpCode QRExport) = nameField (ItemTypeOpCode QRExport)
uuidField _ = "uuid"
-- | Extracts all quoted strings from a list, ignoring the
-- 'NumericValue' entries.
getAllQuotedStrings :: [FilterValue] -> [String]
......@@ -69,7 +69,8 @@ handleClassicQuery :: ConfigData -- ^ Cluster config
handleClassicQuery _ _ _ _ True =
return . Bad $ OpPrereqError "Sync queries are not allowed" ECodeInval
handleClassicQuery cfg qkind names fields _ = do
let flt = makeSimpleFilter (nameField qkind) names
let simpleNameFilter field = makeSimpleFilter (field qkind) names
flt = Qlang.OrFilter $ map simpleNameFilter [nameField, uuidField]
qr <- query cfg True (Qlang.Query qkind fields flt)
return $ showJSON <$> (qr >>= queryCompat)
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