Commit a64cc96b authored by Helga Velroyen's avatar Helga Velroyen
Browse files

Convert Maybe results to RSUnavail

When displaying query results of type Maybe, one could use the
function rsMaybe. Unfortunately, this function maps 'Nothing'
values to RSNoData which gets displayed as '?' in the list of
query results. These semantics do not fit if the result is of
a Maybe type, because it is an optional field, because in this
case 'Nothing' is not an error (like for example the consequence
of an RPC error), but a legitimate result and as such should
be displayed as '-' in the result list. For this purpose,
this patch introduces another version of rsMaybe, which is
called rsMaybeUnavail to be used for optional fields.
For consistency, rsMaybe gets renamed to rsMaybeNoData.
Signed-off-by: default avatarHelga Velroyen <>
Reviewed-by: default avatarIustin Pop <>
parent b43064d0
......@@ -27,7 +27,8 @@ module Ganeti.Query.Common
( rsNoData
, rsUnavail
, rsNormal
, rsMaybe
, rsMaybeNoData
, rsMaybeUnavail
, rsUnknown
, missingRuntime
, rpcErrorToStatus
......@@ -79,9 +80,17 @@ rsNormal a = ResultEntry RSNormal $ Just (showJSON a)
-- missing, in which case we return no data). Note that there's some
-- ambiguity here: in some cases, we mean 'RSNoData', but in other
-- 'RSUnavail'; this is easy to solve in simple cases, but not in
-- nested dicts.
rsMaybe :: (JSON a) => Maybe a -> ResultEntry
rsMaybe = maybe rsNoData rsNormal
-- nested dicts. If you want to return 'RSUnavail' in case of 'Nothing'
-- use the function 'rsMaybeUnavail'.
rsMaybeNoData :: (JSON a) => Maybe a -> ResultEntry
rsMaybeNoData = maybe rsNoData rsNormal
-- | Helper to declare a result from a 'Maybe'. This version returns
-- a 'RSUnavail' in case of 'Nothing'. It should be used for optional
-- fields that are not set. For cases where 'Nothing' means that there
-- was an error, consider using 'rsMaybe' instead.
rsMaybeUnavail :: (JSON a) => Maybe a -> ResultEntry
rsMaybeUnavail = maybe rsUnavail rsNormal
-- | Helper for unknown field result.
rsUnknown :: ResultEntry
......@@ -135,7 +144,7 @@ tagsFields =
-- levels of maybe: the top level dict might be missing, or one key in
-- the dictionary might be.
dictFieldGetter :: (DictObject a) => String -> Maybe a -> ResultEntry
dictFieldGetter k = maybe rsNoData (rsMaybe . lookup k . toDict)
dictFieldGetter k = maybe rsNoData (rsMaybeNoData . lookup k . toDict)
-- | Build an optimised lookup map from a Python _PARAMETER_TYPES
-- association list.
......@@ -158,13 +158,13 @@ nodeFields =
, (FieldDefinition "group" "Group" QFTText "Node group",
FieldConfig (\cfg node ->
rsMaybe (groupName <$> getGroupOfNode cfg node)),
rsMaybeNoData (groupName <$> getGroupOfNode cfg node)),
, (FieldDefinition "group.uuid" "GroupUUID" QFTText "UUID of node group",
FieldSimple (rsNormal . nodeGroup), QffNormal)
, (FieldDefinition "ndparams" "NodeParameters" QFTOther
"Merged node parameters",
FieldConfig ((rsMaybe .) . getNodeNdParams), QffNormal)
FieldConfig ((rsMaybeNoData .) . getNodeNdParams), QffNormal)
, (FieldDefinition "custom_ndparams" "CustomNodeParameters" QFTOther
"Custom node parameters",
FieldSimple (rsNormal . nodeNdparams), QffNormal)
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