Revision ec0292f1 lib/cmdlib.py

b/lib/cmdlib.py
500 500
  return _BuildInstanceHookEnv(**args)
501 501

  
502 502

  
503
def _AdjustCandidatePool(lu):
504
  """Adjust the candidate pool after node operations.
505

  
506
  """
507
  mod_list = lu.cfg.MaintainCandidatePool()
508
  if mod_list:
509
    lu.LogInfo("Promoted nodes to master candidate role: %s",
510
               ", ".join(mod_list))
511
    for name in mod_list:
512
      lu.context.ReaddNode(name)
513
  mc_now, mc_max = lu.cfg.GetMasterCandidateStats()
514
  if mc_now > mc_max:
515
    lu.LogInfo("Note: more nodes are candidates (%d) than desired (%d)" %
516
               (mc_now, mc_max))
517

  
518

  
503 519
def _CheckInstanceBridgesExist(lu, instance):
504 520
  """Check that the brigdes needed by an instance exist.
505 521

  
......
1358 1374
    # we want to update nodes after the cluster so that if any errors
1359 1375
    # happen, we have recorded and saved the cluster info
1360 1376
    if self.op.candidate_pool_size is not None:
1361
      node_info = self.cfg.GetAllNodesInfo().values()
1362
      num_candidates = len([node for node in node_info
1363
                            if node.master_candidate])
1364
      num_nodes = len(node_info)
1365
      if num_candidates < self.op.candidate_pool_size:
1366
        random.shuffle(node_info)
1367
        for node in node_info:
1368
          if num_candidates >= self.op.candidate_pool_size:
1369
            break
1370
          if node.master_candidate:
1371
            continue
1372
          node.master_candidate = True
1373
          self.LogInfo("Promoting node %s to master candidate", node.name)
1374
          self.cfg.Update(node)
1375
          self.context.ReaddNode(node)
1376
          num_candidates += 1
1377
      elif num_candidates > self.op.candidate_pool_size:
1378
        self.LogInfo("Note: more nodes are candidates (%d) than the new value"
1379
                     " of candidate_pool_size (%d)" %
1380
                     (num_candidates, self.op.candidate_pool_size))
1377
      _AdjustCandidatePool(self)
1381 1378

  
1382 1379

  
1383 1380
def _WaitForSync(lu, instance, oneshot=False, unlock=False):
......
1623 1620
    self.rpc.call_node_leave_cluster(node.name)
1624 1621

  
1625 1622
    # Promote nodes to master candidate as needed
1626
    cp_size = self.cfg.GetClusterInfo().candidate_pool_size
1627
    node_info = self.cfg.GetAllNodesInfo().values()
1628
    num_candidates = len([n for n in node_info
1629
                          if n.master_candidate])
1630
    num_nodes = len(node_info)
1631
    random.shuffle(node_info)
1632
    for node in node_info:
1633
      if num_candidates >= cp_size or num_candidates >= num_nodes:
1634
        break
1635
      if node.master_candidate:
1636
        continue
1637
      node.master_candidate = True
1638
      self.LogInfo("Promoting node %s to master candidate", node.name)
1639
      self.cfg.Update(node)
1640
      self.context.ReaddNode(node)
1641
      num_candidates += 1
1623
    _AdjustCandidatePool(self)
1642 1624

  
1643 1625

  
1644 1626
class LUQueryNodes(NoHooksLU):
......
1973 1955

  
1974 1956
    cp_size = self.cfg.GetClusterInfo().candidate_pool_size
1975 1957
    node_info = self.cfg.GetAllNodesInfo().values()
1976
    num_candidates = len([n for n in node_info
1977
                          if n.master_candidate])
1978
    master_candidate = num_candidates < cp_size
1958
    mc_now, _ = self.cfg.GetMasterCandidateStats()
1959
    master_candidate = mc_now < cp_size
1979 1960

  
1980 1961
    self.new_node = objects.Node(name=node,
1981 1962
                                 primary_ip=primary_ip,

Also available in: Unified diff