Revision b6dd32db lib/objects.py

b/lib/objects.py
1108 1108
    "serial_no",
1109 1109
    ] + _TIMESTAMPS + _UUID
1110 1110

  
1111
  def MapLVsByNode(self, lvmap=None, devs=None, node_uuid=None):
1112
    """Provide a mapping of nodes to LVs this instance owns.
1113

  
1114
    This function figures out what logical volumes should belong on
1115
    which nodes, recursing through a device tree.
1116

  
1117
    @type lvmap: dict
1118
    @param lvmap: optional dictionary to receive the
1119
        'node' : ['lv', ...] data.
1120
    @type devs: list of L{Disk}
1121
    @param devs: disks to get the LV name for. If None, all disk of this
1122
        instance are used.
1123
    @type node_uuid: string
1124
    @param node_uuid: UUID of the node to get the LV names for. If None, the
1125
        primary node of this instance is used.
1126
    @return: None if lvmap arg is given, otherwise, a dictionary of
1127
        the form { 'node_uuid' : ['volume1', 'volume2', ...], ... };
1128
        volumeN is of the form "vg_name/lv_name", compatible with
1129
        GetVolumeList()
1130

  
1131
    """
1132
    if node_uuid is None:
1133
      node_uuid = self.primary_node
1134

  
1135
    if lvmap is None:
1136
      lvmap = {
1137
        node_uuid: [],
1138
        }
1139
      ret = lvmap
1140
    else:
1141
      if not node_uuid in lvmap:
1142
        lvmap[node_uuid] = []
1143
      ret = None
1144

  
1145
    if not devs:
1146
      devs = self.disks
1147

  
1148
    for dev in devs:
1149
      if dev.dev_type == constants.DT_PLAIN:
1150
        lvmap[node_uuid].append(dev.logical_id[0] + "/" + dev.logical_id[1])
1151

  
1152
      elif dev.dev_type in constants.DTS_DRBD:
1153
        if dev.children:
1154
          self.MapLVsByNode(lvmap, dev.children, dev.logical_id[0])
1155
          self.MapLVsByNode(lvmap, dev.children, dev.logical_id[1])
1156

  
1157
      elif dev.children:
1158
        self.MapLVsByNode(lvmap, dev.children, node_uuid)
1159

  
1160
    return ret
1161

  
1162 1111
  def FindDisk(self, idx):
1163 1112
    """Find a disk given having a specified index.
1164 1113

  

Also available in: Unified diff