def detach_volume(server_id, volume_id, credentials): user_id = credentials.userid vm = util.get_vm(server_id, credentials, for_update=True, non_deleted=True) volume = get_volume(credentials, volume_id, for_update=True, non_deleted=True, exception=faults.BadRequest) server_attachments.detach_volume(vm, volume) log.info("User %s detached volume %s to VM %s", user_id, volume.id, vm.id)
def detach(volume_id): """Detach a Volume""" volume = get_volume(volume_id) server_id = volume.machine_id if server_id is not None: server = get_vm(server_id) server_attachments.detach_volume(server, volume) log.info("Detaching volume '%s' from server '%s', job: %s", volume.id, server_id, volume.backendjobid) else: raise faults.BadRequest("Volume is already detached") return volume
def delete(volume): """Delete a Volume""" # A volume is deleted by detaching it from the server that is attached. # Deleting a detached volume is not implemented. server_id = volume.machine_id if server_id is not None: server = util.get_server(volume.userid, server_id, for_update=True, non_deleted=True, exception=faults.BadRequest) server_attachments.detach_volume(server, volume) log.info("Detach volume '%s' from server '%s', job: %s", volume.id, server_id, volume.backendjobid) else: raise faults.BadRequest("Cannot delete a detached volume") return volume
def detach_volume(request, server_id, volume_id): log.debug("detach_volume server_id %s volume_id", server_id, volume_id) user_id = request.user_uniq vm = util.get_vm(server_id, user_id, for_update=True, non_deleted=True) volume = get_volume(user_id, volume_id, for_update=True, non_deleted=True, exception=faults.BadRequest) vm = server_attachments.detach_volume(vm, volume) # TODO: Check volume state, send job to detach volume return HttpResponse(status=202)
def detach(volume_id, credentials, atomic_context=None): """Detach a Volume""" volume = util.get_volume(credentials, volume_id, for_update=False, non_deleted=True, exception=faults.BadRequest) server_id = volume.machine_id if server_id is None: raise faults.BadRequest("Volume is already detached") vm = util.get_vm(server_id, credentials, for_update=True, non_deleted=True) volume = util.get_volume(credentials, volume_id, for_update=True, non_deleted=True, exception=faults.BadRequest) server_id = volume.machine_id if server_id is None: raise faults.BadRequest("Volume is already detached") server_attachments.detach_volume(vm, volume) log.info("Detaching volume '%s' from server '%s', job: %s", volume.id, server_id, volume.backendjobid) return volume
def detach_volume(request, server_id, volume_id): log.debug("User %s, VM: %s, Action: detach_volume, Volume: %s", request.user_uniq, server_id, volume_id) user_id = request.user_uniq vm = util.get_vm(server_id, user_id, request.user_projects, for_update=True, non_deleted=True) volume = get_volume(user_id, request.user_projects, volume_id, for_update=True, non_deleted=True, exception=faults.BadRequest) vm = server_attachments.detach_volume(vm, volume) log.info("User %s detached volume %s to VM %s", user_id, volume.id, vm.id) # TODO: Check volume state, send job to detach volume return HttpResponse(status=202)