Revision cfcc5c6d

b/lib/objects.py
518 518
  def _ComputeSecondaryNodes(self):
519 519
    """Compute the list of secondary nodes.
520 520

  
521
    This is a simple wrapper over _ComputeAllNodes.
522

  
523
    """
524
    all_nodes = set(self._ComputeAllNodes())
525
    all_nodes.discard(self.primary_node)
526
    return tuple(all_nodes)
527

  
528
  secondary_nodes = property(_ComputeSecondaryNodes, None, None,
529
                             "List of secondary nodes")
530

  
531
  def _ComputeAllNodes(self):
532
    """Compute the list of all nodes.
533

  
521 534
    Since the data is already there (in the drbd disks), keeping it as
522 535
    a separate normal attribute is redundant and if not properly
523 536
    synchronised can cause problems. Thus it's better to compute it
524 537
    dynamically.
525 538

  
526 539
    """
527
    def _Helper(primary, sec_nodes, device):
528
      """Recursively computes secondary nodes given a top device."""
540
    def _Helper(nodes, device):
541
      """Recursively computes nodes given a top device."""
529 542
      if device.dev_type in constants.LDS_DRBD:
530
        nodea, nodeb, dummy = device.logical_id[:3]
531
        if nodea == primary:
532
          candidate = nodeb
533
        else:
534
          candidate = nodea
535
        if candidate not in sec_nodes:
536
          sec_nodes.append(candidate)
543
        nodea, nodeb = device.logical_id[:2]
544
        nodes.add(nodea)
545
        nodes.add(nodeb)
537 546
      if device.children:
538 547
        for child in device.children:
539
          _Helper(primary, sec_nodes, child)
548
          _Helper(nodes, child)
540 549

  
541
    secondary_nodes = []
550
    all_nodes = set()
542 551
    for device in self.disks:
543
      _Helper(self.primary_node, secondary_nodes, device)
544
    return tuple(secondary_nodes)
552
      _Helper(all_nodes, device)
553
    return tuple(all_nodes)
545 554

  
546
  secondary_nodes = property(_ComputeSecondaryNodes, None, None,
547
                             "List of secondary nodes")
555
  all_nodes = property(_ComputeAllNodes, None, None,
556
                       "List of all nodes of the instance")
548 557

  
549 558
  def MapLVsByNode(self, lvmap=None, devs=None, node=None):
550 559
    """Provide a mapping of nodes to LVs this instance owns.

Also available in: Unified diff