Revision 0d66ea67

b/Ganeti/HTools/Cluster.hs
109 109
-- For a one-node allocation, this will be a @Left ['Node.Node']@,
110 110
-- whereas for a two-node allocation, this will be a @Right
111 111
-- [('Node.Node', 'Node.Node')]@.
112
type AllocNodes = Either [Node.Node] [(Node.Node, Node.Node)]
112
type AllocNodes = Either [Ndx] [(Ndx, Ndx)]
113 113

  
114 114
-- | The empty solution we start with when computing allocations
115 115
emptySolution :: AllocSolution
......
415 415
    in new_nl
416 416

  
417 417
-- | Tries to allocate an instance on one given node.
418
allocateOnSingle :: Node.List -> Instance.Instance -> Node.Node
418
allocateOnSingle :: Node.List -> Instance.Instance -> Ndx
419 419
                 -> OpResult Node.AllocElement
420
allocateOnSingle nl inst p =
421
    let new_pdx = Node.idx p
420
allocateOnSingle nl inst new_pdx =
421
    let p = Container.find new_pdx nl
422 422
        new_inst = Instance.setBoth inst new_pdx Node.noSecondary
423 423
    in  Node.addPri p inst >>= \new_p -> do
424 424
      let new_nl = Container.add new_pdx new_p nl
......
426 426
      return (new_nl, new_inst, [new_p], new_score)
427 427

  
428 428
-- | Tries to allocate an instance on a given pair of nodes.
429
allocateOnPair :: Node.List -> Instance.Instance -> Node.Node -> Node.Node
429
allocateOnPair :: Node.List -> Instance.Instance -> Ndx -> Ndx
430 430
               -> OpResult Node.AllocElement
431
allocateOnPair nl inst tgt_p tgt_s =
432
    let new_pdx = Node.idx tgt_p
433
        new_sdx = Node.idx tgt_s
431
allocateOnPair nl inst new_pdx new_sdx =
432
    let tgt_p = Container.find new_pdx nl
433
        tgt_s = Container.find new_sdx nl
434 434
    in do
435 435
      new_p <- Node.addPri tgt_p inst
436 436
      new_s <- Node.addSec tgt_s inst new_pdx
......
632 632
        ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y &&
633 633
                                      Node.group x == Node.group y) all_pairs
634 634
    in case count of
635
         1 -> Ok (Left all_nodes)
636
         2 -> Ok (Right ok_pairs)
635
         1 -> Ok (Left (map Node.idx all_nodes))
636
         2 -> Ok (Right (map (\(p, s) -> (Node.idx p, Node.idx s)) ok_pairs))
637 637
         _ -> Bad "Unsupported number of nodes, only one or two  supported"
638 638

  
639 639
-- | Try to allocate an instance on the cluster.

Also available in: Unified diff