Commit 5227de56 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix the node powered field



When initially implementing the node query, I thought the 'powered'
field is a representation of the run-time powered status, which would
make its query complex.

In reality, it's a simple config query, which we can support
easily. We also add a small helper, so that we don't hardcode the
RSUnavail case in many places.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarAgata Murawska <agatamurawska@google.com>
parent b04dc242
......@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Ganeti.Query.Common
( rsNoData
, rsUnavail
, rsNormal
, rsMaybe
, rsUnknown
......@@ -66,6 +67,10 @@ vTypeToQFT VTypeInt = QFTNumber
rsNoData :: ResultEntry
rsNoData = ResultEntry RSNoData Nothing
-- | Helper for result for an entity which supports no such field.
rsUnavail :: ResultEntry
rsUnavail = ResultEntry RSUnavail Nothing
-- | Helper to declare a normal result.
rsNormal :: (JSON a) => a -> ResultEntry
rsNormal a = ResultEntry RSNormal $ Just (showJSON a)
......
......@@ -117,6 +117,15 @@ nodeRoleDoc =
"\"" ++ nodeRoleToRaw role ++ "\" for " ++ roleDescription role)
(reverse [minBound..maxBound]))
-- | Get node powered status.
getNodePower :: ConfigData -> Node -> ResultEntry
getNodePower cfg node =
case getNodeNdParams cfg node of
Nothing -> rsNoData
Just ndp -> if null (ndpOobProgram ndp)
then rsUnavail
else rsNormal (nodePowered node)
-- | List of all node fields.
nodeFields :: FieldList Node NodeRuntime
nodeFields =
......@@ -174,11 +183,9 @@ nodeFields =
getNodeInstances cfg . nodeName))
, (FieldDefinition "role" "Role" QFTText nodeRoleDoc,
FieldConfig ((rsNormal .) . getNodeRole))
-- FIXME: the powered state is special (has an different context,
-- not runtime) in Python
, (FieldDefinition "powered" "Powered" QFTBool
"Whether node is thought to be powered on",
missingRuntime)
FieldConfig getNodePower)
-- FIXME: the two fields below are incomplete in Python, part of the
-- non-implemented node resource model; they are declared just for
-- parity, but are not functional
......
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