Add cpu-count-related attributes to nodes
[ganeti-local] / Ganeti / HTools / Cluster.hs
index e7910e9..dc316e4 100644 (file)
@@ -467,8 +467,12 @@ applyMove nl inst (ReplacePrimary new_pdx) =
         int_p = Node.removePri old_p inst
         int_s = Node.removeSec old_s inst
         new_nl = do -- Maybe monad
+          -- check that the current secondary can host the instance
+          -- during the migration
+          tmp_s <- Node.addPri int_s inst
+          let tmp_s' = Node.removePri tmp_s inst
           new_p <- Node.addPri tgt_n inst
-          new_s <- Node.addSec int_s inst new_pdx
+          new_s <- Node.addSec tmp_s' inst new_pdx
           return $ Container.add new_pdx new_p $
                  Container.addTwo old_pdx int_p old_sdx new_s nl
     in (new_nl, Instance.setPri inst new_pdx, new_pdx, old_sdx)
@@ -624,19 +628,21 @@ tryAlloc :: (Monad m) =>
          -> Instance.List     -- ^ The instance list
          -> Instance.Instance -- ^ The instance to allocate
          -> Int               -- ^ Required number of nodes
-         -> m [(Maybe Node.List, [Node.Node])] -- ^ Possible solution list
+         -> m [(Maybe Node.List, Instance.Instance, [Node.Node])]
+                              -- ^ Possible solution list
 tryAlloc nl _ inst 2 =
     let all_nodes = getOnline nl
         all_pairs = liftM2 (,) all_nodes all_nodes
         ok_pairs = filter (\(x, y) -> Node.idx x /= Node.idx y) all_pairs
-        sols = map (\(p, s) ->
-                        (fst $ allocateOnPair nl inst p s, [p, s]))
+        sols = map (\(p, s) -> let (mnl, i) = allocateOnPair nl inst p s
+                               in (mnl, i, [p, s]))
                ok_pairs
     in return sols
 
 tryAlloc nl _ inst 1 =
     let all_nodes = getOnline nl
-        sols = map (\p -> (fst $ allocateOnSingle nl inst p, [p]))
+        sols = map (\p -> let (mnl, i) = allocateOnSingle nl inst p
+                          in (mnl, i, [p]))
                all_nodes
     in return sols
 
@@ -651,16 +657,17 @@ tryReloc :: (Monad m) =>
          -> Idx           -- ^ The index of the instance to move
          -> Int           -- ^ The numver of nodes required
          -> [Ndx]         -- ^ Nodes which should not be used
-         -> m [(Maybe Node.List, [Node.Node])] -- ^ Solution list
+         -> m [(Maybe Node.List, Instance.Instance, [Node.Node])]
+                          -- ^ Solution list
 tryReloc nl il xid 1 ex_idx =
     let all_nodes = getOnline nl
         inst = Container.find xid il
         ex_idx' = (Instance.pnode inst):ex_idx
         valid_nodes = filter (not . flip elem ex_idx' . Node.idx) all_nodes
         valid_idxes = map Node.idx valid_nodes
-        sols1 = map (\x -> let (mnl, _, _, _) =
-                                    applyMove nl inst (ReplaceSecondary x)
-                           in (mnl, [Container.find x nl])
+        sols1 = map (\x -> let (mnl, i, _, _) =
+                                   applyMove nl inst (ReplaceSecondary x)
+                           in (mnl, i, [Container.find x nl])
                      ) valid_idxes
     in return sols1
 
@@ -773,11 +780,11 @@ printNodes nl =
         m_name = maximum . map (length . Node.name) $ snl
         helper = Node.list m_name
         header = printf
-                 "%2s %-*s %5s %5s %5s %5s %5s %5s %5s %5s %3s %3s %7s %7s"
+                 "%2s %-*s %5s %5s %5s %5s %5s %5s %5s %5s %3s %3s %7s %7s %7s"
                  " F" m_name "Name"
                  "t_mem" "n_mem" "i_mem" "x_mem" "f_mem" "r_mem"
                  "t_dsk" "f_dsk"
-                 "pri" "sec" "p_fmem" "p_fdsk"
+                 "pri" "sec" "p_fmem" "p_fdsk" "r_cpu"
     in unlines $ (header:map helper snl)
 
 -- | Shows statistics for a given node list.