diff --git a/htools/Ganeti/Query/Common.hs b/htools/Ganeti/Query/Common.hs index 014957888a8ca4d4c2ce061c33307eb81a4695d4..b9029bc28be8567a95c9499ca0afed39b2d7caa7 100644 --- a/htools/Ganeti/Query/Common.hs +++ b/htools/Ganeti/Query/Common.hs @@ -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) diff --git a/htools/Ganeti/Query/Node.hs b/htools/Ganeti/Query/Node.hs index 7bb994b75b235663df0a8385cc1c1536304e65e0..1fbc80eacff8baedb86ea52e592b8cf5a1074fdd 100644 --- a/htools/Ganeti/Query/Node.hs +++ b/htools/Ganeti/Query/Node.hs @@ -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