Revision 0402302c lib/objects.py

b/lib/objects.py
390 390
      raise errors.ProgrammerError("Disk.RecordGrow called for unsupported"
391 391
                                   " disk type %s" % self.dev_type)
392 392

  
393
  def SetPhysicalID(self, target_node, nodes_ip):
394
    """Convert the logical ID to the physical ID.
395

  
396
    This is used only for drbd, which needs ip/port configuration.
397

  
398
    The routine descends down and updates its children also, because
399
    this helps when the only the top device is passed to the remote
400
    node.
401

  
402
    Arguments:
403
      - target_node: the node we wish to configure for
404
      - nodes_ip: a mapping of node name to ip
405

  
406
    The target_node must exist in in nodes_ip, and must be one of the
407
    nodes in the logical ID for each of the DRBD devices encountered
408
    in the disk tree.
409

  
410
    """
411
    if self.children:
412
      for child in self.children:
413
        child.SetPhysicalID(target_node, nodes_ip)
414

  
415
    if self.logical_id is None and self.physical_id is not None:
416
      return
417
    if self.dev_type in constants.LDS_DRBD:
418
      pnode, snode, port = self.logical_id
419
      if target_node not in (pnode, snode):
420
        raise errors.ConfigurationError("DRBD device not knowing node %s" %
421
                                        target_node)
422
      pnode_ip = nodes_ip.get(pnode, None)
423
      snode_ip = nodes_ip.get(snode, None)
424
      if pnode_ip is None or snode_ip is None:
425
        raise errors.ConfigurationError("Can't find primary or secondary node"
426
                                        " for %s" % str(self))
427
      if pnode == target_node:
428
        self.physical_id = (pnode_ip, port,
429
                            snode_ip, port)
430
      else: # it must be secondary, we tested above
431
        self.physical_id = (snode_ip, port,
432
                            pnode_ip, port)
433
    else:
434
      self.physical_id = self.logical_id
435
    return
436

  
393 437
  def ToDict(self):
394 438
    """Disk-specific conversion to standard python types.
395 439

  

Also available in: Unified diff