Revision b867e218

b/lib/cmdlib.py
9688 9688
                        " failed", idx, instance.name)
9689 9689

  
9690 9690

  
9691
def _WipeOrCleanupDisks(lu, instance, disks=None, cleanup=None):
9692
  """Wrapper for L{_WipeDisks} that handles errors.
9693

  
9694
  @type lu: L{LogicalUnit}
9695
  @param lu: the logical unit on whose behalf we execute
9696
  @type instance: L{objects.Instance}
9697
  @param instance: the instance whose disks we should wipe
9698
  @param disks: see L{_WipeDisks}
9699
  @param cleanup: the result returned by L{_CreateDisks}, used for cleanup in
9700
      case of error
9701
  @raise errors.OpPrereqError: in case of failure
9702

  
9703
  """
9704
  try:
9705
    _WipeDisks(lu, instance, disks=disks)
9706
  except errors.OpExecError:
9707
    logging.warning("Wiping disks for instance '%s' failed",
9708
                    instance.name)
9709
    _UndoCreateDisks(lu, cleanup)
9710
    raise
9711

  
9712

  
9713
def _UndoCreateDisks(lu, disks_created):
9714
  """Undo the work performed by L{_CreateDisks}.
9715

  
9716
  This function is called in case of an error to undo the work of
9717
  L{_CreateDisks}.
9718

  
9719
  @type lu: L{LogicalUnit}
9720
  @param lu: the logical unit on whose behalf we execute
9721
  @param disks_created: the result returned by L{_CreateDisks}
9722

  
9723
  """
9724
  for (node, disk) in disks_created:
9725
    lu.cfg.SetDiskID(disk, node)
9726
    result = lu.rpc.call_blockdev_remove(node, disk)
9727
    if result.fail_msg:
9728
      logging.warning("Failed to remove newly-created disk %s on node %s:"
9729
                      " %s", disk, node, result.fail_msg)
9730

  
9731

  
9691 9732
def _CreateDisks(lu, instance, to_skip=None, target_node=None):
9692 9733
  """Create all disks for an instance.
9693 9734

  
......
9701 9742
  @param to_skip: list of indices to skip
9702 9743
  @type target_node: string
9703 9744
  @param target_node: if passed, overrides the target node for creation
9704
  @rtype: boolean
9705
  @return: the success of the creation
9745
  @return: information about the created disks, to be used to call
9746
      L{_UndoCreateDisks}
9747
  @raise errors.OpPrereqError: in case of error
9706 9748

  
9707 9749
  """
9708 9750
  info = _GetInstanceInfoText(instance)
......
9737 9779
        logging.warning("Creating disk %s for instance '%s' failed",
9738 9780
                        idx, instance.name)
9739 9781
        disks_created.extend(e.created_devices)
9740
        for (node, disk) in disks_created:
9741
          lu.cfg.SetDiskID(disk, node)
9742
          result = lu.rpc.call_blockdev_remove(node, disk)
9743
          if result.fail_msg:
9744
            logging.warning("Failed to remove newly-created disk %s on node %s:"
9745
                            " %s", device, node, result.fail_msg)
9782
        _UndoCreateDisks(lu, disks_created)
9746 9783
        raise errors.OpExecError(e.message)
9784
  return disks_created
9747 9785

  
9748 9786

  
9749 9787
def _RemoveDisks(lu, instance, target_node=None, ignore_failures=False):

Also available in: Unified diff