Revision 9757cc90 lib/cmdlib.py

b/lib/cmdlib.py
8520 8520
    self.success = self.info = self.nodes = None
8521 8521
    if self.mode == constants.IALLOCATOR_MODE_ALLOC:
8522 8522
      keyset = self._ALLO_KEYS
8523
      fn = self._AddNewInstance
8523 8524
    elif self.mode == constants.IALLOCATOR_MODE_RELOC:
8524 8525
      keyset = self._RELO_KEYS
8526
      fn = self._AddRelocateInstance
8525 8527
    else:
8526 8528
      raise errors.ProgrammerError("Unknown mode '%s' passed to the"
8527 8529
                                   " IAllocator" % self.mode)
......
8534 8536
      if key not in kwargs:
8535 8537
        raise errors.ProgrammerError("Missing input parameter '%s' to"
8536 8538
                                     " IAllocator" % key)
8537
    self._BuildInputData()
8539
    self._BuildInputData(fn)
8538 8540

  
8539 8541
  def _ComputeClusterData(self):
8540 8542
    """Compute the generic allocator input data.
......
8673 8675
    done.
8674 8676

  
8675 8677
    """
8676
    data = self.in_data
8677

  
8678 8678
    disk_space = _ComputeDiskSize(self.disk_template, self.disks)
8679 8679

  
8680 8680
    if self.disk_template in constants.DTS_NET_MIRROR:
......
8682 8682
    else:
8683 8683
      self.required_nodes = 1
8684 8684
    request = {
8685
      "type": "allocate",
8686 8685
      "name": self.name,
8687 8686
      "disk_template": self.disk_template,
8688 8687
      "tags": self.tags,
......
8694 8693
      "nics": self.nics,
8695 8694
      "required_nodes": self.required_nodes,
8696 8695
      }
8697
    data["request"] = request
8696
    return request
8698 8697

  
8699 8698
  def _AddRelocateInstance(self):
8700 8699
    """Add relocate instance data to allocator structure.
......
8724 8723
    disk_space = _ComputeDiskSize(instance.disk_template, disk_sizes)
8725 8724

  
8726 8725
    request = {
8727
      "type": "relocate",
8728 8726
      "name": self.name,
8729 8727
      "disk_space_total": disk_space,
8730 8728
      "required_nodes": self.required_nodes,
8731 8729
      "relocate_from": self.relocate_from,
8732 8730
      }
8733
    self.in_data["request"] = request
8731
    return request
8734 8732

  
8735
  def _BuildInputData(self):
8733
  def _BuildInputData(self, fn):
8736 8734
    """Build input data structures.
8737 8735

  
8738 8736
    """
8739 8737
    self._ComputeClusterData()
8740 8738

  
8741
    if self.mode == constants.IALLOCATOR_MODE_ALLOC:
8742
      self._AddNewInstance()
8743
    else:
8744
      self._AddRelocateInstance()
8739
    request = fn()
8740
    request["type"] = self.mode
8741
    self.in_data["request"] = request
8745 8742

  
8746 8743
    self.in_text = serializer.Dump(self.in_data)
8747 8744

  

Also available in: Unified diff