From f82f1f39f71bf31479f4a3e0a85f0e25f5e582a4 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sun, 22 Mar 2009 11:24:23 +0100 Subject: [PATCH] Add a new instance field denoting run status 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 | 5 +++-- Ganeti/HTools/Instance.hs | 23 ++++++++++++++++------- Ganeti/HTools/Rapi.hs | 2 ++ hscan.hs | 3 ++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Ganeti/HTools/Cluster.hs b/Ganeti/HTools/Cluster.hs index 5bba46e14..07d7c8e74 100644 --- a/Ganeti/HTools/Cluster.hs +++ b/Ganeti/HTools/Cluster.hs @@ -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 diff --git a/Ganeti/HTools/Instance.hs b/Ganeti/HTools/Instance.hs index 4dcb28d4d..d115742e0 100644 --- a/Ganeti/HTools/Instance.hs +++ b/Ganeti/HTools/Instance.hs @@ -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 diff --git a/Ganeti/HTools/Rapi.hs b/Ganeti/HTools/Rapi.hs index ba1b57749..c5e4df28f 100644 --- a/Ganeti/HTools/Rapi.hs +++ b/Ganeti/HTools/Rapi.hs @@ -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 diff --git a/hscan.hs b/hscan.hs index 634cbe52c..37f72b068 100644 --- 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 -- GitLab