Revision 668c03b3 Ganeti/HTools/Cluster.hs

b/Ganeti/HTools/Cluster.hs
565 565
-- | Given the original and final nodes, computes the relocation description.
566 566
computeMoves :: Instance.Instance -- ^ The instance to be moved
567 567
             -> String -- ^ The instance name
568
             -> String -- ^ Original primary
569
             -> String -- ^ Original secondary
568
             -> IMove  -- ^ The move being performed
570 569
             -> String -- ^ New primary
571 570
             -> String -- ^ New secondary
572 571
             -> (String, [String])
......
574 573
                -- either @/f/@ for failover or @/r:name/@ for replace
575 574
                -- secondary, while the command list holds gnt-instance
576 575
                -- commands (without that prefix), e.g \"@failover instance1@\"
577
computeMoves i inam a b c d
578
    -- same primary
579
    | c == a =
580
        if d == b
581
        then {- Same sec??! -} ("-", [])
582
        else {- Change of secondary -}
583
            (printf "r:%s" d, [rep d])
584
    -- failover and ...
585
    | c == b =
586
        if d == a
587
        then {- that's all -} ("f", [mig])
588
        else (printf "f r:%s" d, [mig, rep d])
589
    -- ... and keep primary as secondary
590
    | d == a =
591
        (printf "r:%s f" c, [rep c, mig])
592
    -- ... keep same secondary
593
    | d == b =
594
        (printf "f r:%s f" c, [mig, rep c, mig])
595
    -- nothing in common -
596
    | otherwise =
597
        (printf "r:%s f r:%s" c d, [rep c, mig, rep d])
576
computeMoves i inam mv c d =
577
    case mv of
578
      Failover -> ("f", [mig])
579
      FailoverAndReplace _ -> (printf "f r:%s" d, [mig, rep d])
580
      ReplaceSecondary _ -> (printf "r:%s" d, [rep d])
581
      ReplaceAndFailover _ -> (printf "r:%s f" c, [rep c, mig])
582
      ReplacePrimary _ -> (printf "f r:%s f" c, [mig, rep c, mig])
598 583
    where morf = if Instance.running i then "migrate" else "failover"
599 584
          mig = printf "%s -f %s" morf inam::String
600 585
          rep n = printf "replace-disks -n %s %s" n inam
......
611 596
printSolutionLine nl il nmlen imlen plc pos =
612 597
    let
613 598
        pmlen = (2*nmlen + 1)
614
        (i, p, s, _, c) = plc
599
        (i, p, s, mv, c) = plc
615 600
        inst = Container.find i il
616 601
        inam = Instance.name inst
617 602
        npri = Container.nameOf nl p
618 603
        nsec = Container.nameOf nl s
619 604
        opri = Container.nameOf nl $ Instance.pNode inst
620 605
        osec = Container.nameOf nl $ Instance.sNode inst
621
        (moves, cmds) =  computeMoves inst inam opri osec npri nsec
606
        (moves, cmds) =  computeMoves inst inam mv npri nsec
622 607
        ostr = printf "%s:%s" opri osec::String
623 608
        nstr = printf "%s:%s" npri nsec::String
624 609
    in

Also available in: Unified diff