That is, make the luxi backend not ask for the operational memory,
but only for the backend parameter, if this option is given.

Signed-off-by: Klaus Aehlig <[email protected]>
---
 src/Ganeti/HTools/Backend/Luxi.hs  | 33 ++++++++++++++++++---------------
 src/Ganeti/HTools/ExtLoader.hs     |  2 +-
 src/Ganeti/HTools/Program/Hscan.hs |  2 +-
 src/Ganeti/MaintD/Server.hs        |  2 +-
 4 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/src/Ganeti/HTools/Backend/Luxi.hs 
b/src/Ganeti/HTools/Backend/Luxi.hs
index aeb3fe9..215fd5c 100644
--- a/src/Ganeti/HTools/Backend/Luxi.hs
+++ b/src/Ganeti/HTools/Backend/Luxi.hs
@@ -135,24 +135,25 @@ queryGroups :: L.Client -> IO (Result JSValue)
 queryGroups = liftM errToResult . L.callMethod queryGroupsMsg
 
 -- | Parse a instance list in JSON format.
-getInstances :: NameAssoc
+getInstances :: Bool
+             -> NameAssoc
              -> JSValue
              -> Result [(String, Instance.Instance)]
-getInstances ktn arr = L.extractArray arr >>= mapM (parseInstance ktn)
+getInstances sor ktn arr = L.extractArray arr >>= mapM (parseInstance sor ktn)
 
 -- | Construct an instance from a JSON object.
-parseInstance :: NameAssoc
+parseInstance :: Bool
+              -> NameAssoc
               -> [(JSValue, JSValue)]
               -> Result (String, Instance.Instance)
-parseInstance ktn [ name, disk, mem, vcpus
-                  , status, pnode, snodes, tags, oram
-                  , auto_balance, disk_template, su
-                  , dsizes, dspindles, forthcoming ] = do
+parseInstance sor ktn
+  [ name, disk, mem, vcpus, status, pnode, snodes, tags, oram
+  , auto_balance, disk_template, su, dsizes, dspindles, forthcoming ] = do
   xname <- annotateResult "Parsing new instance" (L.fromJValWithStatus name)
   let convert a = genericConvert "Instance" xname a
   xdisk <- convert "disk_usage" disk
-  xmem <- case oram of -- FIXME: remove the "guessing"
-            (_, JSRational _ _) -> convert "oper_ram" oram
+  xmem <- case (sor, oram) of -- FIXME: remove the "guessing"
+            (False, (_, JSRational _ _)) -> convert "oper_ram" oram
             _ -> convert "be/memory" mem
   xvcpus <- convert "be/vcpus" vcpus
   xpnode <- convert "pnode" pnode >>= lookupNode ktn xname
@@ -174,7 +175,7 @@ parseInstance ktn [ name, disk, mem, vcpus
              xforthcoming
   return (xname, inst)
 
-parseInstance _ v = fail ("Invalid instance query result: " ++ show v)
+parseInstance _ _ v = fail ("Invalid instance query result: " ++ show v)
 
 -- | Parse a node list in JSON format.
 getNodes :: NameAssoc -> JSValue -> Result [(String, Node.Node)]
@@ -276,20 +277,22 @@ readData master =
 
 -- | Converts the output of 'readData' into the internal cluster
 -- representation.
-parseData :: (Result JSValue, Result JSValue, Result JSValue, Result JSValue)
+parseData :: Bool
+          -> (Result JSValue, Result JSValue, Result JSValue, Result JSValue)
           -> Result ClusterData
-parseData (groups, nodes, instances, cinfo) = do
+parseData sor (groups, nodes, instances, cinfo) = do
   group_data <- groups >>= getGroups
   let (group_names, group_idx) = assignIndices group_data
   node_data <- nodes >>= getNodes group_names
   let (node_names, node_idx) = assignIndices node_data
-  inst_data <- instances >>= getInstances node_names
+  inst_data <- instances >>= getInstances sor node_names
   let (_, inst_idx) = assignIndices inst_data
   (ctags, cpol, master) <- cinfo >>= getClusterData
   node_idx' <- setMaster node_names node_idx master
   return (ClusterData group_idx node_idx' inst_idx ctags cpol)
 
 -- | Top level function for data loading.
-loadData :: String -- ^ Unix socket to use as source
+loadData :: Bool -- ^ use only state-of-record data
+         -> String -- ^ Unix socket to use as source
          -> IO (Result ClusterData)
-loadData = fmap parseData . readData
+loadData sor = fmap (parseData sor) . readData
diff --git a/src/Ganeti/HTools/ExtLoader.hs b/src/Ganeti/HTools/ExtLoader.hs
index 56e2e80..0cd4a23 100644
--- a/src/Ganeti/HTools/ExtLoader.hs
+++ b/src/Ganeti/HTools/ExtLoader.hs
@@ -114,7 +114,7 @@ loadExternalData opts = do
   input_data <-
     case () of
       _ | setRapi -> wrapIO $ Rapi.loadData mhost
-        | setLuxi -> wrapIO . Luxi.loadData $ fromJust lsock
+        | setLuxi -> wrapIO . Luxi.loadData (optSoR opts) $ fromJust lsock
         | setSim -> Simu.loadData simdata
         | setFile -> wrapIO . Text.loadData $ fromJust tfile
         | setIAllocSrc -> wrapIO . IAlloc.loadData $ fromJust iallocsrc
diff --git a/src/Ganeti/HTools/Program/Hscan.hs 
b/src/Ganeti/HTools/Program/Hscan.hs
index 1fb6a55..f7fdaf3 100644
--- a/src/Ganeti/HTools/Program/Hscan.hs
+++ b/src/Ganeti/HTools/Program/Hscan.hs
@@ -163,7 +163,7 @@ main opts clusters = do
          def_socket <- Path.defaultQuerySocket
          let lsock = fromMaybe def_socket (optLuxi opts)
          let name = local
-         input_data <- Luxi.loadData lsock
+         input_data <- Luxi.loadData (optSoR opts) lsock
          result <- writeData nlen name opts input_data
          unless result . exitWith $ ExitFailure 2
 
diff --git a/src/Ganeti/MaintD/Server.hs b/src/Ganeti/MaintD/Server.hs
index 670d2bb..313b924 100644
--- a/src/Ganeti/MaintD/Server.hs
+++ b/src/Ganeti/MaintD/Server.hs
@@ -107,7 +107,7 @@ loadClusterData :: ResultT String IO ClusterData
 loadClusterData = do
   now <- liftIO getClockTime
   socket <- liftIO Path.defaultQuerySocket
-  either_inp <-  liftIO . tryIOError $ Luxi.loadData socket
+  either_inp <-  liftIO . tryIOError $ Luxi.loadData False socket
   input_data <- mkResultT $ case either_inp of
                   Left e -> do
                     let msg = show e
-- 
2.6.0.rc2.230.g3dd15c0

Reply via email to