Revision a64cc96b
b/src/Ganeti/Query/Common.hs | ||
---|---|---|
27 | 27 |
( rsNoData |
28 | 28 |
, rsUnavail |
29 | 29 |
, rsNormal |
30 |
, rsMaybe |
|
30 |
, rsMaybeNoData |
|
31 |
, rsMaybeUnavail |
|
31 | 32 |
, rsUnknown |
32 | 33 |
, missingRuntime |
33 | 34 |
, rpcErrorToStatus |
... | ... | |
79 | 80 |
-- missing, in which case we return no data). Note that there's some |
80 | 81 |
-- ambiguity here: in some cases, we mean 'RSNoData', but in other |
81 | 82 |
-- 'RSUnavail'; this is easy to solve in simple cases, but not in |
82 |
-- nested dicts. |
|
83 |
rsMaybe :: (JSON a) => Maybe a -> ResultEntry |
|
84 |
rsMaybe = maybe rsNoData rsNormal |
|
83 |
-- nested dicts. If you want to return 'RSUnavail' in case of 'Nothing' |
|
84 |
-- use the function 'rsMaybeUnavail'. |
|
85 |
rsMaybeNoData :: (JSON a) => Maybe a -> ResultEntry |
|
86 |
rsMaybeNoData = maybe rsNoData rsNormal |
|
87 |
|
|
88 |
-- | Helper to declare a result from a 'Maybe'. This version returns |
|
89 |
-- a 'RSUnavail' in case of 'Nothing'. It should be used for optional |
|
90 |
-- fields that are not set. For cases where 'Nothing' means that there |
|
91 |
-- was an error, consider using 'rsMaybe' instead. |
|
92 |
rsMaybeUnavail :: (JSON a) => Maybe a -> ResultEntry |
|
93 |
rsMaybeUnavail = maybe rsUnavail rsNormal |
|
85 | 94 |
|
86 | 95 |
-- | Helper for unknown field result. |
87 | 96 |
rsUnknown :: ResultEntry |
... | ... | |
135 | 144 |
-- levels of maybe: the top level dict might be missing, or one key in |
136 | 145 |
-- the dictionary might be. |
137 | 146 |
dictFieldGetter :: (DictObject a) => String -> Maybe a -> ResultEntry |
138 |
dictFieldGetter k = maybe rsNoData (rsMaybe . lookup k . toDict) |
|
147 |
dictFieldGetter k = maybe rsNoData (rsMaybeNoData . lookup k . toDict)
|
|
139 | 148 |
|
140 | 149 |
-- | Build an optimised lookup map from a Python _PARAMETER_TYPES |
141 | 150 |
-- association list. |
b/src/Ganeti/Query/Node.hs | ||
---|---|---|
158 | 158 |
QffNormal) |
159 | 159 |
, (FieldDefinition "group" "Group" QFTText "Node group", |
160 | 160 |
FieldConfig (\cfg node -> |
161 |
rsMaybe (groupName <$> getGroupOfNode cfg node)), |
|
161 |
rsMaybeNoData (groupName <$> getGroupOfNode cfg node)),
|
|
162 | 162 |
QffNormal) |
163 | 163 |
, (FieldDefinition "group.uuid" "GroupUUID" QFTText "UUID of node group", |
164 | 164 |
FieldSimple (rsNormal . nodeGroup), QffNormal) |
165 | 165 |
, (FieldDefinition "ndparams" "NodeParameters" QFTOther |
166 | 166 |
"Merged node parameters", |
167 |
FieldConfig ((rsMaybe .) . getNodeNdParams), QffNormal) |
|
167 |
FieldConfig ((rsMaybeNoData .) . getNodeNdParams), QffNormal)
|
|
168 | 168 |
, (FieldDefinition "custom_ndparams" "CustomNodeParameters" QFTOther |
169 | 169 |
"Custom node parameters", |
170 | 170 |
FieldSimple (rsNormal . nodeNdparams), QffNormal) |
Also available in: Unified diff