diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs index 37af920b50cdeb19617b181314b03c683a8929d5..cb49ffc6a1eaf1743c5ac53ebbb2120ea911f5f5 100644 --- a/htools/Ganeti/HTools/Cluster.hs +++ b/htools/Ganeti/HTools/Cluster.hs @@ -1208,7 +1208,7 @@ computeMoves i inam mv c d = ReplaceSecondary _ -> (printf "r:%s" d, [rep d]) ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig]) ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig]) - where morf = if Instance.instanceRunning i then "migrate" else "failover" + where morf = if Instance.isRunning i then "migrate" else "failover" mig = printf "%s -f %s" morf inam::String rep n = printf "replace-disks -n %s %s" n inam @@ -1306,7 +1306,7 @@ printNodes nl fs = printInsts :: Node.List -> Instance.List -> String printInsts nl il = let sil = sortBy (comparing Instance.idx) (Container.elems il) - helper inst = [ if Instance.instanceRunning inst then "R" else " " + helper inst = [ if Instance.isRunning inst then "R" else " " , Instance.name inst , Container.nameOf nl (Instance.pNode inst) , let sdx = Instance.sNode inst diff --git a/htools/Ganeti/HTools/Instance.hs b/htools/Ganeti/HTools/Instance.hs index 0f320801d26b7f3aac1e3ca9e9be9282183b7584..4b5924e15af8d768d4c2231c1d1486c2044c6c41 100644 --- a/htools/Ganeti/HTools/Instance.hs +++ b/htools/Ganeti/HTools/Instance.hs @@ -31,9 +31,9 @@ module Ganeti.HTools.Instance , AssocList , List , create - , instanceRunning - , instanceOffline - , instanceNotOffline + , isRunning + , isOffline + , notOffline , instanceDown , usesSecMem , applyIfOnline @@ -89,36 +89,36 @@ instance T.Element Instance where allNames n = [name n, alias n] -- | Check if instance is running. -instanceRunning :: Instance -> Bool -instanceRunning (Instance {runSt = T.Running}) = True -instanceRunning (Instance {runSt = T.ErrorUp}) = True -instanceRunning _ = False +isRunning :: Instance -> Bool +isRunning (Instance {runSt = T.Running}) = True +isRunning (Instance {runSt = T.ErrorUp}) = True +isRunning _ = False -- | Check if instance is offline. -instanceOffline :: Instance -> Bool -instanceOffline (Instance {runSt = T.AdminOffline}) = True -instanceOffline _ = False +isOffline :: Instance -> Bool +isOffline (Instance {runSt = T.AdminOffline}) = True +isOffline _ = False -- | Helper to check if the instance is not offline. -instanceNotOffline :: Instance -> Bool -instanceNotOffline = not . instanceOffline +notOffline :: Instance -> Bool +notOffline = not . isOffline -- | Check if instance is down. instanceDown :: Instance -> Bool -instanceDown inst | instanceRunning inst = False -instanceDown inst | instanceOffline inst = False -instanceDown _ = True +instanceDown inst | isRunning inst = False +instanceDown inst | isOffline inst = False +instanceDown _ = True -- | Apply the function if the instance is online. Otherwise use -- the initial value applyIfOnline :: Instance -> (a -> a) -> a -> a -applyIfOnline = applyIf . instanceNotOffline +applyIfOnline = applyIf . notOffline -- | Helper for determining whether an instance's memory needs to be -- taken into account for secondary memory reservation. usesSecMem :: Instance -> Bool -usesSecMem inst = instanceNotOffline inst && autoBalance inst +usesSecMem inst = notOffline inst && autoBalance inst -- | Constant holding the local storage templates. -- diff --git a/htools/Ganeti/HTools/Loader.hs b/htools/Ganeti/HTools/Loader.hs index d7f40bfe48fb196b7e48934e059f28d21cc32caa..169dd48e126b40ed9a9709a46add0bb057189c47 100644 --- a/htools/Ganeti/HTools/Loader.hs +++ b/htools/Ganeti/HTools/Loader.hs @@ -341,7 +341,7 @@ nodeImem :: Node.Node -> Instance.List -> Int nodeImem node il = let rfind = flip Container.find il il' = map rfind $ Node.pList node - oil' = filter Instance.instanceNotOffline il' + oil' = filter Instance.notOffline il' in sum . map Instance.mem $ oil' diff --git a/htools/Ganeti/HTools/Node.hs b/htools/Ganeti/HTools/Node.hs index 2f5de9bfda70de1909ab7b71d7716e34d45e0ca3..128a3f596db721b3c9d34e2fb4cb8ae949b220d7 100644 --- a/htools/Ganeti/HTools/Node.hs +++ b/htools/Ganeti/HTools/Node.hs @@ -348,7 +348,7 @@ setFmem t new_mem = removePri :: Node -> Instance.Instance -> Node removePri t inst = let iname = Instance.idx inst - i_online = Instance.instanceNotOffline inst + i_online = Instance.notOffline inst uses_disk = Instance.usesLocalStorage inst new_plist = delete iname (pList t) new_mem = incIf i_online (fMem t) (Instance.mem inst) @@ -409,7 +409,7 @@ addPriEx :: Bool -- ^ Whether to override the N+1 and -- or a failure mode addPriEx force t inst = let iname = Instance.idx inst - i_online = Instance.instanceNotOffline inst + i_online = Instance.notOffline inst uses_disk = Instance.usesLocalStorage inst cur_dsk = fDsk t new_mem = decIf i_online (fMem t) (Instance.mem inst) diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs index df1f5521e3d7bb87095df10aa4e28fb6728345fa..7b3d25369e28c8c20c5a61d71a86c0a994c35760 100644 --- a/htools/Ganeti/HTools/QC.hs +++ b/htools/Ganeti/HTools/QC.hs @@ -960,7 +960,7 @@ prop_Node_setMcpu node mc = -- rejected. prop_Node_addPriFM node inst = Instance.mem inst >= Node.fMem node && not (Node.failN1 node) && - not (Instance.instanceOffline inst) ==> + not (Instance.isOffline inst) ==> case Node.addPri node inst'' of Types.OpFail Types.FailMem -> True _ -> False @@ -980,7 +980,7 @@ prop_Node_addPriFD node inst = prop_Node_addPriFC = forAll (choose (1, maxCpu)) $ \extra -> forAll genOnlineNode $ \node -> - forAll (arbitrary `suchThat` Instance.instanceNotOffline) $ \inst -> + forAll (arbitrary `suchThat` Instance.notOffline) $ \inst -> let inst' = setInstanceSmallerThanNode node inst inst'' = inst' { Instance.vcpus = Node.availCpu node + extra } in case Node.addPri node inst'' of @@ -991,7 +991,7 @@ prop_Node_addPriFC = -- rejected. prop_Node_addSec node inst pdx = ((Instance.mem inst >= (Node.fMem node - Node.rMem node) && - not (Instance.instanceOffline inst)) || + not (Instance.isOffline inst)) || Instance.dsk inst >= Node.fDsk node) && not (Node.failN1 node) ==> isFailure (Node.addSec node inst pdx) @@ -1011,7 +1011,7 @@ prop_Node_addOffline (NonNegative extra_mem) (NonNegative extra_cpu) pdx = -- | Checks for memory reservation changes. prop_Node_rMem inst = - not (Instance.instanceOffline inst) ==> + not (Instance.isOffline inst) ==> forAll (arbitrary `suchThat` ((> Types.unitMem) . Node.fMem)) $ \node -> -- ab = auto_balance, nb = non-auto_balance -- we use -1 as the primary node of the instance