Revision c85abf30

b/htools/Ganeti/HTools/Cluster.hs
35 35
  , CStats(..)
36 36
  , AllocResult
37 37
  , AllocMethod
38
  , AllocSolutionList
38 39
  -- * Generic functions
39 40
  , totalResources
40 41
  , computeAllocationDelta
......
64 65
  , tryNodeEvac
65 66
  , tryChangeGroup
66 67
  , collapseFailures
68
  , allocList
67 69
  -- * Allocation functions
68 70
  , iterateAlloc
69 71
  , tieredAlloc
......
112 114
type AllocResult = (FailStats, Node.List, Instance.List,
113 115
                    [Instance.Instance], [CStats])
114 116

  
117
-- | Type alias for easier handling.
118
type AllocSolutionList = [(Instance.Instance, AllocSolution)]
119

  
115 120
-- | A type denoting the valid allocation mode/pairs.
116 121
--
117 122
-- For a one-node allocation, this will be a @Left ['Ndx']@, whereas
......
844 849
      selmsg = "Selected group: " ++ group_name
845 850
  return $ solution { asLog = selmsg:all_msgs }
846 851

  
852
-- | Calculate the new instance list after allocation solution.
853
updateIl :: Instance.List           -- ^ The original instance list
854
         -> Maybe Node.AllocElement -- ^ The result of the allocation attempt
855
         -> Instance.List           -- ^ The updated instance list
856
updateIl il Nothing = il
857
updateIl il (Just (_, xi, _, _)) = Container.add (Container.size il) xi il
858

  
859
-- | Extract the the new node list from the allocation solution.
860
extractNl :: Node.List               -- ^ The original node list
861
          -> Maybe Node.AllocElement -- ^ The result of the allocation attempt
862
          -> Node.List               -- ^ The new node list
863
extractNl nl Nothing = nl
864
extractNl _ (Just (xnl, _, _, _)) = xnl
865

  
866
-- | Try to allocate a list of instances on a multi-group cluster.
867
allocList :: Group.List                  -- ^ The group list
868
          -> Node.List                   -- ^ The node list
869
          -> Instance.List               -- ^ The instance list
870
          -> [(Instance.Instance, Int)]  -- ^ The instance to allocate
871
          -> AllocSolutionList           -- ^ Possible solution list
872
          -> Result (Node.List, Instance.List,
873
                     AllocSolutionList)  -- ^ The final solution list
874
allocList _  nl il [] result = Ok (nl, il, result)
875
allocList gl nl il ((xi, xicnt):xies) result = do
876
  ares <- tryMGAlloc gl nl il xi xicnt
877
  let sol = asSolution ares
878
      nl' = extractNl nl sol
879
      il' = updateIl il sol
880
  allocList gl nl' il' xies ((xi, ares):result)
881

  
847 882
-- | Function which fails if the requested mode is change secondary.
848 883
--
849 884
-- This is useful since except DRBD, no other disk template can

Also available in: Unified diff