Revision 0ac34c90 lib/masterd/iallocator.py

b/lib/masterd/iallocator.py
581 581
      total_spindles = free_spindles = 0
582 582
    return (total_disk, free_disk, total_spindles, free_spindles)
583 583

  
584
  @staticmethod
585
  def _ComputeInstanceMemory(instance_list, node_instances_info, node_uuid,
586
                             input_mem_free):
587
    """Compute memory used by primary instances.
588

  
589
    @rtype: tuple (int, int, int)
590
    @returns: A tuple of three integers: 1. the sum of memory used by primary
591
      instances on the node (including the ones that are currently down), 2.
592
      the sum of memory used by primary instances of the node that are up, 3.
593
      the amount of memory that is free on the node considering the current
594
      usage of the instances.
595

  
596
    """
597
    i_p_mem = i_p_up_mem = 0
598
    mem_free = input_mem_free
599
    for iinfo, beinfo in instance_list:
600
      if iinfo.primary_node == node_uuid:
601
        i_p_mem += beinfo[constants.BE_MAXMEM]
602
        if iinfo.name not in node_instances_info[node_uuid].payload:
603
          i_used_mem = 0
604
        else:
605
          i_used_mem = int(node_instances_info[node_uuid]
606
                           .payload[iinfo.name]["memory"])
607
        i_mem_diff = beinfo[constants.BE_MAXMEM] - i_used_mem
608
        mem_free -= max(0, i_mem_diff)
609

  
610
        if iinfo.admin_state == constants.ADMINST_UP:
611
          i_p_up_mem += beinfo[constants.BE_MAXMEM]
612
    return (i_p_mem, i_p_up_mem, mem_free)
613

  
584 614
  def _ComputeDynamicNodeData(self, node_cfg, node_data, node_iinfo, i_list,
585 615
                              node_results, has_lvm):
586 616
    """Compute global node data.
......
606 636
        mem_free = self._GetAttributeFromNodeData(remote_info, ninfo.name,
607 637
                                                  "memory_free")
608 638

  
609
        # compute memory used by primary instances
610
        i_p_mem = i_p_up_mem = 0
611
        for iinfo, beinfo in i_list:
612
          if iinfo.primary_node == nuuid:
613
            i_p_mem += beinfo[constants.BE_MAXMEM]
614
            if iinfo.name not in node_iinfo[nuuid].payload:
615
              i_used_mem = 0
616
            else:
617
              i_used_mem = int(node_iinfo[nuuid].payload[iinfo.name]["memory"])
618
            i_mem_diff = beinfo[constants.BE_MAXMEM] - i_used_mem
619
            mem_free -= max(0, i_mem_diff)
620

  
621
            if iinfo.admin_state == constants.ADMINST_UP:
622
              i_p_up_mem += beinfo[constants.BE_MAXMEM]
623

  
639
        (i_p_mem, i_p_up_mem, mem_free) = self._ComputeInstanceMemory(
640
             i_list, node_iinfo, nuuid, mem_free)
624 641
        (total_disk, free_disk, total_spindles, free_spindles) = \
625 642
            self._ComputeStorageDataFromNodeInfo(nresult.payload, ninfo.name,
626 643
                                                 has_lvm)

Also available in: Unified diff