Revision 2b941e94

b/lib/config.py
373 373
    self._UnlockedAttachInstDisk(instance, disk, idx)
374 374
    self._WriteConfig()
375 375

  
376
  def _UnlockedDettachInstDisk(self, disk):
377
    """Dettach a disk from an instance.
378

  
379
    This function is for internal use, when the config lock is already held.
380
    The `_WriteConfig' function has to be called afterwards (so we can
381
    dettach a disk from an instance and remove it from config at once).
382

  
383
    @type disk: L{objects.Disk}
384
    @param disk: the disk object
385

  
386
    """
387
    if not isinstance(disk, objects.Disk):
388
      raise errors.ProgrammerError(
389
        "Invalid type passed to _UnlockedDettachInstDisk")
390

  
391
    if not disk.instance:
392
      raise errors.ProgrammerError("Disk %s is not attached to an instance"
393
                                   % disk.uuid)
394

  
395
    instance = self._UnlockedGetInstanceInfo(disk.instance)
396

  
397
    # Update disk
398
    disk.instance = ""
399
    disk.serial_no += 1
400
    disk.mtime = time.time()
401

  
402
    # Update instance
403
    idx = instance.disks.index(disk.uuid)
404
    instance.disks.remove(disk.uuid)
405
    inst_disks = self._UnlockedGetInstanceDisks(instance)
406
    self._UpdateIvNames(idx, inst_disks)
407
    instance.serial_no += 1
408
    instance.mtime = time.time()
409

  
410
  def _UnlockedRemoveDisk(self, disk_uuid):
411
    """Remove the disk from the configuration.
412

  
413
    This function is for internal use, when the config lock is already held.
414
    The `_WriteConfig' function has to be called afterwards (so we can
415
    remove many disks at once).
416

  
417
    """
418
    if disk_uuid not in self._config_data.disks:
419
      raise errors.ConfigurationError("Unknown disk '%s'" % disk_uuid)
420

  
421
    # Remove disk from config file
422
    del self._config_data.disks[disk_uuid]
423
    self._config_data.cluster.serial_no += 1
424

  
425
  @locking.ssynchronized(_config_lock)
426
  def RemoveInstDisk(self, disk_uuid):
427
    """Dettach a disk from an instance and remove it from the config.
428

  
429
    @type disk_uuid: string
430
    @param disk_uuid: the uuid of the disk we want to remove
431

  
432
    """
433
    if disk_uuid not in self._config_data.disks:
434
      raise errors.ConfigurationError("Unknown disk '%s'" % disk_uuid)
435

  
436
    disk = self._config_data.disks[disk_uuid]
437
    self._UnlockedDettachInstDisk(disk)
438
    self._UnlockedRemoveDisk(disk_uuid)
439
    self._WriteConfig()
440

  
376 441
  def _UnlockedGetDiskInfo(self, disk_uuid):
377 442
    """Returns information about an instance.
378 443

  

Also available in: Unified diff