Revision 2f1c2fe6 lib/config.py

b/lib/config.py
260 260
    nodegroup = self._UnlockedGetNodeGroup(node.group)
261 261
    return self._UnlockedGetGroupDiskParams(nodegroup)
262 262

  
263
  # pylint: disable=R0201
264
  def _UnlockedGetInstanceNodes(self, instance, disks=None):
265
    """Get all disk-releated nodes for an instance.
266

  
267
    This function is for internal use, when the config lock is already held.
268

  
269
    """
270
    all_nodes = [instance.primary_node]
271
    inst_disks = instance.disks
272
    if disks is not None:
273
      inst_disks.extend(disks)
274
    for disk in inst_disks:
275
      all_nodes.extend(disk.all_nodes)
276
    return tuple(set(all_nodes))
277

  
278
  @locking.ssynchronized(_config_lock, shared=1)
279
  def GetInstanceNodes(self, instance, disks=None):
280
    """Get all disk-releated nodes for an instance.
281

  
282
    For non-DRBD, this will be empty, for DRBD it will contain both
283
    the primary and the secondaries.
284
    If additional disks are given, include their nodes to the result.
285
    This is done because these disks may not be attached to the instance yet.
286

  
287
    @type instance: L{objects.Instance}
288
    @param instance: The instance we want to get nodes for
289
    @type disks: list of L{objects.Disk}
290
    @param disks: If given, include these disks to the result
291
    @return: A list of names for all the nodes of the instance
292

  
293
    """
294
    return self._UnlockedGetInstanceNodes(instance, disks=disks)
295

  
296
  def _UnlockedGetInstanceSecondaryNodes(self, instance):
297
    """Get the list of secondary nodes.
298

  
299
    This function is for internal use, when the config lock is already held.
300

  
301
    """
302
    all_nodes = set(self._UnlockedGetInstanceNodes(instance))
303
    all_nodes.discard(instance.primary_node)
304
    return tuple(all_nodes)
305

  
306
  @locking.ssynchronized(_config_lock, shared=1)
307
  def GetInstanceSecondaryNodes(self, instance):
308
    """Get the list of secondary nodes.
309

  
310
    This is a simple wrapper over _UnlockedGetInstanceNodes.
311

  
312
    """
313
    return self._UnlockedGetInstanceSecondaryNodes(instance)
314

  
263 315
  @locking.ssynchronized(_config_lock, shared=1)
264 316
  def GetGroupDiskParams(self, group):
265 317
    """Get the disk params populated with inherit chain.

Also available in: Unified diff