Revision 7959cbb9

b/htools/Ganeti/HTools/Cluster.hs
1208 1208
    ReplaceSecondary _ -> (printf "r:%s" d, [rep d])
1209 1209
    ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig])
1210 1210
    ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig])
1211
  where morf = if Instance.instanceRunning i then "migrate" else "failover"
1211
  where morf = if Instance.isRunning i then "migrate" else "failover"
1212 1212
        mig = printf "%s -f %s" morf inam::String
1213 1213
        rep n = printf "replace-disks -n %s %s" n inam
1214 1214

  
......
1306 1306
printInsts :: Node.List -> Instance.List -> String
1307 1307
printInsts nl il =
1308 1308
  let sil = sortBy (comparing Instance.idx) (Container.elems il)
1309
      helper inst = [ if Instance.instanceRunning inst then "R" else " "
1309
      helper inst = [ if Instance.isRunning inst then "R" else " "
1310 1310
                    , Instance.name inst
1311 1311
                    , Container.nameOf nl (Instance.pNode inst)
1312 1312
                    , let sdx = Instance.sNode inst
b/htools/Ganeti/HTools/Instance.hs
31 31
  , AssocList
32 32
  , List
33 33
  , create
34
  , instanceRunning
35
  , instanceOffline
36
  , instanceNotOffline
34
  , isRunning
35
  , isOffline
36
  , notOffline
37 37
  , instanceDown
38 38
  , usesSecMem
39 39
  , applyIfOnline
......
89 89
  allNames n = [name n, alias n]
90 90

  
91 91
-- | Check if instance is running.
92
instanceRunning :: Instance -> Bool
93
instanceRunning (Instance {runSt = T.Running}) = True
94
instanceRunning (Instance {runSt = T.ErrorUp}) = True
95
instanceRunning _                              = False
92
isRunning :: Instance -> Bool
93
isRunning (Instance {runSt = T.Running}) = True
94
isRunning (Instance {runSt = T.ErrorUp}) = True
95
isRunning _                              = False
96 96

  
97 97
-- | Check if instance is offline.
98
instanceOffline :: Instance -> Bool
99
instanceOffline (Instance {runSt = T.AdminOffline}) = True
100
instanceOffline _                                   = False
98
isOffline :: Instance -> Bool
99
isOffline (Instance {runSt = T.AdminOffline}) = True
100
isOffline _                                   = False
101 101

  
102 102

  
103 103
-- | Helper to check if the instance is not offline.
104
instanceNotOffline :: Instance -> Bool
105
instanceNotOffline = not . instanceOffline
104
notOffline :: Instance -> Bool
105
notOffline = not . isOffline
106 106

  
107 107
-- | Check if instance is down.
108 108
instanceDown :: Instance -> Bool
109
instanceDown inst | instanceRunning inst = False
110
instanceDown inst | instanceOffline inst = False
111
instanceDown _                           = True
109
instanceDown inst | isRunning inst = False
110
instanceDown inst | isOffline inst = False
111
instanceDown _                     = True
112 112

  
113 113
-- | Apply the function if the instance is online. Otherwise use
114 114
-- the initial value
115 115
applyIfOnline :: Instance -> (a -> a) -> a -> a
116
applyIfOnline = applyIf . instanceNotOffline
116
applyIfOnline = applyIf . notOffline
117 117

  
118 118
-- | Helper for determining whether an instance's memory needs to be
119 119
-- taken into account for secondary memory reservation.
120 120
usesSecMem :: Instance -> Bool
121
usesSecMem inst = instanceNotOffline inst && autoBalance inst
121
usesSecMem inst = notOffline inst && autoBalance inst
122 122

  
123 123
-- | Constant holding the local storage templates.
124 124
--
b/htools/Ganeti/HTools/Loader.hs
341 341
nodeImem node il =
342 342
  let rfind = flip Container.find il
343 343
      il' = map rfind $ Node.pList node
344
      oil' = filter Instance.instanceNotOffline il'
344
      oil' = filter Instance.notOffline il'
345 345
  in sum . map Instance.mem $ oil'
346 346

  
347 347

  
b/htools/Ganeti/HTools/Node.hs
348 348
removePri :: Node -> Instance.Instance -> Node
349 349
removePri t inst =
350 350
  let iname = Instance.idx inst
351
      i_online = Instance.instanceNotOffline inst
351
      i_online = Instance.notOffline inst
352 352
      uses_disk = Instance.usesLocalStorage inst
353 353
      new_plist = delete iname (pList t)
354 354
      new_mem = incIf i_online (fMem t) (Instance.mem inst)
......
409 409
                               -- or a failure mode
410 410
addPriEx force t inst =
411 411
  let iname = Instance.idx inst
412
      i_online = Instance.instanceNotOffline inst
412
      i_online = Instance.notOffline inst
413 413
      uses_disk = Instance.usesLocalStorage inst
414 414
      cur_dsk = fDsk t
415 415
      new_mem = decIf i_online (fMem t) (Instance.mem inst)
b/htools/Ganeti/HTools/QC.hs
960 960
-- rejected.
961 961
prop_Node_addPriFM node inst =
962 962
  Instance.mem inst >= Node.fMem node && not (Node.failN1 node) &&
963
  not (Instance.instanceOffline inst) ==>
963
  not (Instance.isOffline inst) ==>
964 964
  case Node.addPri node inst'' of
965 965
    Types.OpFail Types.FailMem -> True
966 966
    _ -> False
......
980 980
prop_Node_addPriFC =
981 981
  forAll (choose (1, maxCpu)) $ \extra ->
982 982
  forAll genOnlineNode $ \node ->
983
  forAll (arbitrary `suchThat` Instance.instanceNotOffline) $ \inst ->
983
  forAll (arbitrary `suchThat` Instance.notOffline) $ \inst ->
984 984
  let inst' = setInstanceSmallerThanNode node inst
985 985
      inst'' = inst' { Instance.vcpus = Node.availCpu node + extra }
986 986
  in case Node.addPri node inst'' of
......
991 991
-- rejected.
992 992
prop_Node_addSec node inst pdx =
993 993
  ((Instance.mem inst >= (Node.fMem node - Node.rMem node) &&
994
    not (Instance.instanceOffline inst)) ||
994
    not (Instance.isOffline inst)) ||
995 995
   Instance.dsk inst >= Node.fDsk node) &&
996 996
  not (Node.failN1 node) ==>
997 997
      isFailure (Node.addSec node inst pdx)
......
1011 1011

  
1012 1012
-- | Checks for memory reservation changes.
1013 1013
prop_Node_rMem inst =
1014
  not (Instance.instanceOffline inst) ==>
1014
  not (Instance.isOffline inst) ==>
1015 1015
  forAll (arbitrary `suchThat` ((> Types.unitMem) . Node.fMem)) $ \node ->
1016 1016
  -- ab = auto_balance, nb = non-auto_balance
1017 1017
  -- we use -1 as the primary node of the instance

Also available in: Unified diff