Ejemplo n.º 1
0
def delete_volume_from_helper(volume, helper_vm):
    """Delete a volume that has been attached to a helper VM.

    This special-purpose function should be called only by the dispatcher, when
    we are notified that a detached volume has been attached to a helper VM.
    """
    if not helper_vm.helper:
        raise faults.BadRequest("Server %s is not a helper server" %
                                helper_vm.backend_vm_id)
    log.debug("Attempting to delete volume '%s' from helper server '%s'",
              volume.id, helper_vm.id)
    server_attachments.delete_volume(helper_vm, volume)
    log.info("Deleting volume '%s' from server '%s', job: %s",
             volume.id, helper_vm.id, volume.backendjobid)
Ejemplo n.º 2
0
def delete_volume_from_helper(volume, helper_vm):
    """Delete a volume that has been attached to a helper VM.

    This special-purpose function should be called only by the dispatcher, when
    we are notified that a detached volume has been attached to a helper VM.
    """
    if not helper_vm.helper:
        raise faults.BadRequest("Server %s is not a helper server" %
                                helper_vm.backend_vm_id)
    log.debug("Attempting to delete volume '%s' from helper server '%s'",
              volume.id, helper_vm.id)
    server_attachments.delete_volume(helper_vm, volume)
    log.info("Deleting volume '%s' from server '%s', job: %s",
             volume.id, helper_vm.id, volume.backendjobid)
Ejemplo n.º 3
0
def delete_volume_from_helper(volume, helper_vm, atomic_context=None):
    """Delete a volume that has been attached to a helper VM.

    This special-purpose function should be called only by the dispatcher, when
    we are notified that a detached volume has been attached to a helper VM.
    """
    if not helper_vm.helper:
        raise faults.BadRequest("Server %s is not a helper server" %
                                helper_vm.backend_vm_id)
    log.debug("Attempting to delete volume '%s' from helper server '%s'",
              volume.id, helper_vm.id)
    # XXX: If another delete is already served, the helper_vm has a pending
    # task which prohibits the code in server_command to issue another action
    server_attachments.delete_volume(helper_vm, volume, atomic_context)
    log.info("Deleting volume '%s' from server '%s', job: %s",
             volume.id, helper_vm.id, volume.backendjobid)
Ejemplo n.º 4
0
def delete(volume_id, credentials, atomic_context=None):
    """Delete a Volume.

    The canonical way of deleting a volume is to send a command to Ganeti to
    remove the volume from a specific server. There are two cases however when
    a volume may not be attached to a server:

    * Case 1: The volume has been created only in DB and was never attached to
    a server. In this case, we can simply mark the volume as deleted without
    using Ganeti to do so.
    * Case 2: The volume has been detached from a VM. This means that there are
    still data in the storage backend. Thus, in order to delete the volume
    safely, we must attach it to a helper VM, thereby handing the delete action
    to the dispatcher.
    """
    volume = util.get_volume(credentials,
                             volume_id, for_update=True, non_deleted=True)

    server_id = volume.machine_id
    if server_id is not None:
        server = get_vm(server_id)
        server_attachments.delete_volume(server, volume, atomic_context)
        log.info("Deleting volume '%s' from server '%s', job: %s",
                 volume.id, server_id, volume.backendjobid)
    elif volume.backendjobid is None:
        # Case 1: Uninitialized volume
        if volume.status not in ("AVAILABLE", "ERROR"):
            raise faults.BadRequest("Volume is in invalid state: %s" %
                                    volume.status)
        log.debug("Attempting to delete uninitialized volume %s.", volume)
        util.mark_volume_as_deleted(volume, immediate=True)
        quotas.issue_and_accept_commission(volume, action="DESTROY",
                                           atomic_context=atomic_context)
        log.info("Deleting uninitialized volume '%s'", volume.id)
    else:
        # Case 2: Detached volume
        log.debug("Attempting to delete detached volume %s", volume)
        delete_detached_volume(volume, atomic_context)
        log.info("Deleting volume '%s' from helper server '%s', job: %s",
                 volume.id, volume.machine.id, volume.backendjobid)

    return volume