Revision 8a8ed513

b/htools/Ganeti/HTools/Cluster.hs
1225 1225
      ReplaceSecondary _ -> (printf "r:%s" d, [rep d])
1226 1226
      ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig])
1227 1227
      ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig])
1228
    where morf = if Instance.running i then "migrate" else "failover"
1228
    where morf = if Instance.instanceRunning i then "migrate" else "failover"
1229 1229
          mig = printf "%s -f %s" morf inam::String
1230 1230
          rep n = printf "replace-disks -n %s %s" n inam
1231 1231

  
......
1325 1325
printInsts :: Node.List -> Instance.List -> String
1326 1326
printInsts nl il =
1327 1327
    let sil = sortBy (comparing Instance.idx) (Container.elems il)
1328
        helper inst = [ if Instance.running inst then "R" else " "
1328
        helper inst = [ if Instance.instanceRunning inst then "R" else " "
1329 1329
                      , Instance.name inst
1330 1330
                      , Container.nameOf nl (Instance.pNode inst)
1331 1331
                      , let sdx = Instance.sNode inst
b/htools/Ganeti/HTools/Instance.hs
31 31
    , AssocList
32 32
    , List
33 33
    , create
34
    , instanceRunning
34 35
    , setIdx
35 36
    , setName
36 37
    , setAlias
......
40 41
    , setMovable
41 42
    , specOf
42 43
    , shrinkByType
43
    , runningStates
44 44
    , localStorageTemplates
45 45
    , hasSecondary
46 46
    , requiredNodes
......
61 61
    , mem          :: Int       -- ^ Memory of the instance
62 62
    , dsk          :: Int       -- ^ Disk size of instance
63 63
    , vcpus        :: Int       -- ^ Number of VCPUs
64
    , running      :: Bool      -- ^ Is the instance running?
65 64
    , runSt        :: T.InstanceStatus -- ^ Original run status
66 65
    , pNode        :: T.Ndx     -- ^ Original primary node
67 66
    , sNode        :: T.Ndx     -- ^ Original secondary node
......
80 79
    setIdx   = setIdx
81 80
    allNames n = [name n, alias n]
82 81

  
83
-- | Constant holding the running instance states.
84
runningStates :: [T.InstanceStatus]
85
runningStates = [T.Running, T.ErrorUp]
82
-- | Check if instance is running.
83
instanceRunning :: Instance -> Bool
84
instanceRunning (Instance {runSt = T.Running}) = True
85
instanceRunning (Instance {runSt = T.ErrorUp}) = True
86
instanceRunning _                               = False
86 87

  
87 88
-- | Constant holding the local storage templates.
88 89
--
......
124 125
             , mem = mem_init
125 126
             , dsk = dsk_init
126 127
             , vcpus = vcpus_init
127
             , running = run_init `elem` runningStates
128 128
             , runSt = run_init
129 129
             , pNode = pn
130 130
             , sNode = sn
b/htools/Ganeti/HTools/Loader.hs
306 306
        (\ msgs node ->
307 307
             let nname = Node.name node
308 308
                 nilst = map (`Container.find` il) (Node.pList node)
309
                 dilst = filter (not . Instance.running) nilst
309
                 dilst = filter (not . Instance.instanceRunning) nilst
310 310
                 adj_mem = sum . map Instance.mem $ dilst
311 311
                 delta_mem = truncate (Node.tMem node)
312 312
                             - Node.nMem node
b/htools/Ganeti/HTools/QC.hs
513 513
    where _types = (inst::Instance.Instance, pdx::Types.Ndx, sdx::Types.Ndx)
514 514
          si = Instance.setBoth inst pdx sdx
515 515

  
516
prop_Instance_runStatus_True =
517
    forAll (arbitrary `suchThat`
518
            ((`elem` Instance.runningStates) . Instance.runSt))
519
    Instance.running
520

  
521
prop_Instance_runStatus_False inst =
522
    let run_st = Instance.running inst
523
        run_tx = Instance.runSt inst
524
    in
525
      run_tx `notElem` Instance.runningStates ==> not run_st
526

  
527 516
prop_Instance_shrinkMG inst =
528 517
    Instance.mem inst >= 2 * Types.unitMem ==>
529 518
        case Instance.shrinkByType inst Types.FailMem of
......
572 561
              , 'prop_Instance_setPri
573 562
              , 'prop_Instance_setSec
574 563
              , 'prop_Instance_setBoth
575
              , 'prop_Instance_runStatus_True
576
              , 'prop_Instance_runStatus_False
577 564
              , 'prop_Instance_shrinkMG
578 565
              , 'prop_Instance_shrinkMF
579 566
              , 'prop_Instance_shrinkCG

Also available in: Unified diff