At the IAlloc backend of htools we do not get the actual
state of the instance (as everything is state-of-record only).
However, we do get the administrative state. Therefore, by
assuming that for each instance the actual state is the one
corresponding to the administrated one, we can get a much better
description of the cluster than blindly assuming all instances
are running. Do so, whenever the admin_state is provided.

Signed-off-by: Klaus Aehlig <[email protected]>
---
 src/Ganeti/HTools/Backend/IAlloc.hs | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/Ganeti/HTools/Backend/IAlloc.hs 
b/src/Ganeti/HTools/Backend/IAlloc.hs
index 9cf66a2..da547b0 100644
--- a/src/Ganeti/HTools/Backend/IAlloc.hs
+++ b/src/Ganeti/HTools/Backend/IAlloc.hs
@@ -59,7 +59,8 @@ import Ganeti.HTools.CLI
 import Ganeti.HTools.Loader
 import Ganeti.HTools.Types
 import Ganeti.JSON
-import Ganeti.Types (EvacMode(ChangePrimary, ChangeSecondary))
+import Ganeti.Types ( EvacMode(ChangePrimary, ChangeSecondary)
+                    , adminStateFromRaw, AdminState(..))
 import Ganeti.Utils
 
 {-# ANN module "HLint: ignore Eta reduce" #-}
@@ -107,9 +108,13 @@ parseBaseInstance n a = do
   su    <- extract "spindle_use"
   nics  <- extract "nics" >>= toArray >>= asObjectList >>=
            mapM (parseNic n . fromJSObject)
-  return
-    (n,
-     Instance.create n mem disk disks vcpus Running tags True 0 0 dt su nics)
+  state <- (tryFromObj errorMessage a "admin_state" >>= adminStateFromRaw)
+           `mplus` Ok AdminUp
+  let getRunSt AdminOffline = StatusOffline
+      getRunSt AdminDown = StatusDown
+      getRunSt AdminUp = Running
+  return (n, Instance.create n mem disk disks vcpus (getRunSt state) tags
+             True 0 0 dt su nics)
 
 -- | Parses an instance as found in the cluster instance list.
 parseInstance :: NameAssoc -- ^ The node name-to-index association list
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to