Revision 0c3d9c7c lib/objects.py

b/lib/objects.py
506 506

  
507 507
class Disk(ConfigObject):
508 508
  """Config object representing a block device."""
509
  __slots__ = (["name", "dev_type", "logical_id", "physical_id",
510
                "children", "iv_name", "size", "mode", "params", "spindles"] +
511
               _UUID)
509
  __slots__ = (["name", "dev_type", "logical_id", "physical_id", "children", "iv_name",
510
                "size", "mode", "params", "spindles"] + _UUID +
511
               # dynamic_params is special. It depends on the node this instance
512
               # is sent to, and should not be persisted.
513
               ["dynamic_params"])
512 514

  
513 515
  def CreateOnSecondary(self):
514 516
    """Test if this device needs to be created on a secondary node."""
......
696 698
        child.UnsetSize()
697 699
    self.size = 0
698 700

  
699
  def SetPhysicalID(self, target_node_uuid, nodes_ip):
700
    """Convert the logical ID to the physical ID.
701
  def UpdateDynamicDiskParams(self, target_node_uuid, nodes_ip):
702
    """Updates the dynamic disk params for the given node.
701 703

  
702
    This is used only for drbd, which needs ip/port configuration.
703

  
704
    The routine descends down and updates its children also, because
705
    this helps when the only the top device is passed to the remote
706
    node.
704
    This is mainly used for drbd, which needs ip/port configuration.
707 705

  
708 706
    Arguments:
709 707
      - target_node_uuid: the node UUID we wish to configure for
710 708
      - nodes_ip: a mapping of node name to ip
711 709

  
712
    The target_node must exist in in nodes_ip, and must be one of the
713
    nodes in the logical ID for each of the DRBD devices encountered
714
    in the disk tree.
710
    The target_node must exist in nodes_ip, and should be one of the
711
    nodes in the logical ID if this device is a DRBD device.
715 712

  
716 713
    """
717 714
    if self.children:
718 715
      for child in self.children:
719
        child.SetPhysicalID(target_node_uuid, nodes_ip)
716
        child.UpdateDynamicDiskParams(target_node_uuid, nodes_ip)
720 717

  
721
    if self.logical_id is None and self.physical_id is not None:
722
      return
723
    if self.dev_type in constants.LDS_DRBD:
724
      pnode_uuid, snode_uuid, port, pminor, sminor, secret = self.logical_id
718
    dyn_disk_params = {}
719
    if self.logical_id is not None and self.dev_type in constants.LDS_DRBD:
720
      pnode_uuid, snode_uuid, _, pminor, sminor, _ = self.logical_id
725 721
      if target_node_uuid not in (pnode_uuid, snode_uuid):
726
        raise errors.ConfigurationError("DRBD device not knowing node %s" %
727
                                        target_node_uuid)
722
        # disk object is being sent to neither the primary nor the secondary
723
        # node. reset the dynamic parameters, the target node is not
724
        # supposed to use them.
725
        self.dynamic_params = dyn_disk_params
726
        return
727

  
728 728
      pnode_ip = nodes_ip.get(pnode_uuid, None)
729 729
      snode_ip = nodes_ip.get(snode_uuid, None)
730 730
      if pnode_ip is None or snode_ip is None:
731 731
        raise errors.ConfigurationError("Can't find primary or secondary node"
732 732
                                        " for %s" % str(self))
733
      p_data = (pnode_ip, port)
734
      s_data = (snode_ip, port)
735 733
      if pnode_uuid == target_node_uuid:
736
        self.physical_id = p_data + s_data + (pminor, secret)
734
        dyn_disk_params[constants.DDP_LOCAL_IP] = pnode_ip
735
        dyn_disk_params[constants.DDP_REMOTE_IP] = snode_ip
736
        dyn_disk_params[constants.DDP_LOCAL_MINOR] = pminor
737
        dyn_disk_params[constants.DDP_REMOTE_MINOR] = sminor
737 738
      else: # it must be secondary, we tested above
738
        self.physical_id = s_data + p_data + (sminor, secret)
739
    else:
740
      self.physical_id = self.logical_id
741
    return
739
        dyn_disk_params[constants.DDP_LOCAL_IP] = snode_ip
740
        dyn_disk_params[constants.DDP_REMOTE_IP] = pnode_ip
741
        dyn_disk_params[constants.DDP_LOCAL_MINOR] = sminor
742
        dyn_disk_params[constants.DDP_REMOTE_MINOR] = pminor
743

  
744
    self.dynamic_params = dyn_disk_params
742 745

  
743 746
  def ToDict(self):
744 747
    """Disk-specific conversion to standard python types.

Also available in: Unified diff