Add a new instance field denoting run status
authorIustin Pop <iustin@google.com>
Sun, 22 Mar 2009 10:24:23 +0000 (11:24 +0100)
committerIustin Pop <iustin@google.com>
Sun, 22 Mar 2009 10:24:23 +0000 (11:24 +0100)
This patch modifies Rapi, the Cluster.loadData and hscan serialization to load
and save the instance run status. At instance level, we add both a boolean
field denoting the true/false run status, and a string field which holds the
original value (since we don't have a 1-to-1 mapping) for use in hscan
serialization.

The run status is not yet used.

Ganeti/HTools/Cluster.hs
Ganeti/HTools/Instance.hs
Ganeti/HTools/Rapi.hs
hscan.hs

index 5bba46e..07d7c8e 100644 (file)
@@ -760,11 +760,12 @@ loadData ndata idata =
                           Node.create (read tm) (read nm)
                                   (read fm) (read td) (read fd)))
                     Node.setIdx
-    {- instance file: name mem disk pnode snode -}
+    {- instance file: name mem disk status pnode snode -}
         (kti, il) = loadTabular idata
-                    (\ (name:mem:dsk:pnode:snode:[]) ->
+                    (\ (name:mem:dsk:status:pnode:snode:[]) ->
                          (name,
                           Instance.create (read mem) (read dsk)
+                              status
                               (fromJust $ lookup pnode ktn)
                               (fromJust $ lookup snode ktn)))
                     Instance.setIdx
index 4dcb28d..d115742 100644 (file)
@@ -6,18 +6,27 @@ intelligence is in the "Node" and "Cluster" modules.
 -}
 module Ganeti.HTools.Instance where
 
-data Instance = Instance { mem :: Int   -- ^ memory of the instance
-                         , dsk :: Int   -- ^ disk size of instance
-                         , pnode :: Int -- ^ original primary node
-                         , snode :: Int -- ^ original secondary node
-                         , idx :: Int   -- ^ internal index for book-keeping
+data Instance = Instance { mem :: Int       -- ^ memory of the instance
+                         , dsk :: Int       -- ^ disk size of instance
+                         , running :: Bool  -- ^ whether the instance
+                                            -- is running
+                         , run_st :: String -- ^ original (text) run status
+                         , pnode :: Int     -- ^ original primary node
+                         , snode :: Int     -- ^ original secondary node
+                         , idx :: Int       -- ^ internal index for
+                                            -- book-keeping
                          } deriving (Show)
 
-create :: Int -> Int -> Int -> Int -> Instance
-create mem_init dsk_init pn sn =
+create :: Int -> Int -> String -> Int -> Int -> Instance
+create mem_init dsk_init run_init pn sn =
     Instance {
           mem = mem_init,
           dsk = dsk_init,
+          running = case run_init of
+                      "running" -> True
+                      "ERROR_up" -> True
+                      _ -> False,
+          run_st = run_init,
           pnode = pn,
           snode = sn,
           idx = -1
index ba1b577..c5e4df2 100644 (file)
@@ -151,10 +151,12 @@ parseInstance a =
         mem = case bep of
                 Left _ -> getIntElement "admin_ram" a
                 Right o -> getIntElement "memory" o
+        running = getStringElement "status" a
     in
       concatElems name $
                   concatElems (show `apply1` mem) $
                   concatElems (show `apply1` disk) $
+                  concatElems running $
                   concatElems pnode snode
 
 parseNode :: JSObject JSValue -> Either String String
index 634cbe5..37f72b0 100644 (file)
--- a/hscan.hs
+++ b/hscan.hs
@@ -99,8 +99,9 @@ serializeInstances il csf ktn kti =
                           pnode = fromJust $ lookup (Instance.pnode inst) etn
                           snode = fromJust $ lookup (Instance.snode inst) etn
                       in
-                        printf "%s|%d|%d|%s|%s"
+                        printf "%s|%d|%d|%s|%s|%s"
                                iname (Instance.mem inst) (Instance.dsk inst)
+                               (Instance.run_st inst)
                                pnode snode
                  )
                  instances