Exemplo n.º 1
0
    def put(self, request, provider_uuid, identity_uuid, volume_id):
        """
        Updates DB values for volume
        """
        user = request.user
        data = request.DATA

        #Ensure volume exists
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        try:
            esh_volume = esh_driver.get_volume(volume_id)
        except ConnectionFailure:
            return connection_failure(provider_uuid, identity_uuid)
        except InvalidCredsError:
            return invalid_creds(provider_uuid, identity_uuid)
        except Exception as exc:
            logger.exception("Encountered a generic exception. "
                             "Returning 409-CONFLICT")
            return failure_response(status.HTTP_409_CONFLICT, str(exc.message))
        if not esh_volume:
            return volume_not_found(volume_id)
        core_volume = convert_esh_volume(esh_volume, provider_uuid,
                                         identity_uuid, user)
        serializer = VolumeSerializer(core_volume,
                                      data=data,
                                      context={'request': request})
        if serializer.is_valid():
            serializer.save()
            update_volume_metadata(esh_driver, esh_volume, data)
            response = Response(serializer.data)
            return response
        else:
            failure_response(status.HTTP_400_BAD_REQUEST, serializer.errors)
Exemplo n.º 2
0
 def update_metadata(self, request, pk=None):
     """
     Until a better method comes about, we will handle Updating metadata here.
     """
     data = request.data
     metadata = data.pop('metadata')
     volume_id = pk
     volume = find_volume(volume_id)
     try:
         update_volume_metadata(volume, metadata)
         return Response(status=status.HTTP_204_NO_CONTENT)
     except Exception as exc:
         logger.exception("Error occurred updating v2 volume metadata")
         return Response(exc.message, status=status.HTTP_409_CONFLICT)
Exemplo n.º 3
0
 def update_metadata(self, request, pk=None):
     """
     Until a better method comes about, we will handle Updating metadata here.
     """
     data = request.data
     metadata = data.pop('metadata')
     volume_id = pk
     volume = find_volume(volume_id)
     try:
         update_volume_metadata(volume, metadata)
         return Response(status=status.HTTP_204_NO_CONTENT)
     except Exception as exc:
         logger.exception("Error occurred updating v2 volume metadata")
         return Response(exc.message, status=status.HTTP_409_CONFLICT)
Exemplo n.º 4
0
def mount_failed(task_uuid,
                 driverCls,
                 provider,
                 identity,
                 volume_id,
                 unmount=False,
                 **celery_task_args):
    try:
        logger.debug("mount_failed task started at %s." % datetime.now())
        logger.info("task_uuid=%s" % task_uuid)
        result = app.AsyncResult(task_uuid)
        with allow_join_result():
            exc = result.get(propagate=False)
        err_str = "Mount Error Traceback:%s" % (result.traceback, )
        logger.error(err_str)
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_id)
        if unmount:
            tmp_status = 'umount_error'
        else:
            tmp_status = 'mount_error'
        return volume_service.update_volume_metadata(
            driver, volume, metadata={'tmp_status': tmp_status})
        logger.debug("mount_failed task finished at %s." % datetime.now())
    except Exception as exc:
        logger.warn(exc)
        mount_failed.retry(exc=exc)
Exemplo n.º 5
0
def update_mount_location(new_mount_location,
                          driverCls, provider, identity,
                          volume_alias):
    """
    """
    from service import volume as volume_service
    try:
        logger.debug(
            "update_mount_location task started at %s." %
            datetime.now())
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_alias)
        if not volume:
            return
        if not new_mount_location:
            return
        volume_metadata = volume.extra['metadata']
        return volume_service.update_volume_metadata(
            driver, volume,
            metadata={'mount_location': new_mount_location})
        logger.debug(
            "update_mount_location task finished at %s." %
            datetime.now())
    except Exception as exc:
        logger.exception(exc)
        update_mount_location.retry(exc=exc)
Exemplo n.º 6
0
    def put(self, request, provider_uuid, identity_uuid, volume_id):
        """
        Updates DB values for volume
        """
        user = request.user
        data = request.DATA

        #Ensure volume exists
        esh_driver = prepare_driver(request, provider_uuid, identity_uuid)
        if not esh_driver:
            return invalid_creds(provider_uuid, identity_uuid)
        try:
            esh_volume = esh_driver.get_volume(volume_id)
        except ConnectionFailure:
            return connection_failure(provider_uuid, identity_uuid)
        except InvalidCredsError:
            return invalid_creds(provider_uuid, identity_uuid)
        except Exception as exc:
            logger.exception("Encountered a generic exception. "
                             "Returning 409-CONFLICT")
            return failure_response(status.HTTP_409_CONFLICT,
                                    str(exc.message))
        if not esh_volume:
            return volume_not_found(volume_id)
        core_volume = convert_esh_volume(esh_volume, provider_uuid,
                                         identity_uuid, user)
        serializer = VolumeSerializer(core_volume, data=data,
                                      context={'request': request})
        if serializer.is_valid():
            serializer.save()
            update_volume_metadata(
                    esh_driver, esh_volume, data)
            response = Response(serializer.data)
            return response
        else:
            failure_response(
                status.HTTP_400_BAD_REQUEST,
                serializer.errors)
Exemplo n.º 7
0
def update_volume_metadata(driverCls, provider, identity, volume_alias, metadata):
    """
    """
    from service import volume as volume_service

    try:
        celery_logger.debug("update_volume_metadata task started at %s." % datetime.now())
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_alias)
        if not volume:
            return
        return volume_service.update_volume_metadata(driver, volume, metadata=metadata)
        celery_logger.debug("volume_metadata task finished at %s." % datetime.now())
    except Exception as exc:
        celery_logger.exception(exc)
        update_volume_metadata.retry(exc=exc)
Exemplo n.º 8
0
def update_volume_metadata(driverCls, provider, identity, volume_alias,
                           metadata):
    """
    """
    from service import volume as volume_service
    try:
        logger.debug("update_volume_metadata task started at %s." %
                     datetime.now())
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_alias)
        if not volume:
            return
        return volume_service.update_volume_metadata(driver,
                                                     volume,
                                                     metadata=metadata)
        logger.debug("volume_metadata task finished at %s." % datetime.now())
    except Exception as exc:
        logger.exception(exc)
        update_volume_metadata.retry(exc=exc)
Exemplo n.º 9
0
def update_mount_location(new_mount_location, driverCls, provider, identity,
                          volume_alias):
    """
    """
    from service import volume as volume_service
    try:
        logger.debug("update_mount_location task started at %s." %
                     datetime.now())
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_alias)
        if not volume:
            return
        if not new_mount_location:
            return
        volume_metadata = volume.extra['metadata']
        return volume_service.update_volume_metadata(
            driver, volume, metadata={'mount_location': new_mount_location})
        logger.debug("update_mount_location task finished at %s." %
                     datetime.now())
    except Exception as exc:
        logger.exception(exc)
        update_mount_location.retry(exc=exc)
Exemplo n.º 10
0
def mount_failed(task_uuid, driverCls, provider, identity, volume_id, unmount=False, **celery_task_args):
    from service import volume as volume_service

    try:
        celery_logger.debug("mount_failed task started at %s." % datetime.now())
        celery_logger.info("task_uuid=%s" % task_uuid)
        result = app.AsyncResult(task_uuid)
        with allow_join_result():
            exc = result.get(propagate=False)
        err_str = "Mount Error Traceback:%s" % (result.traceback,)
        celery_logger.error(err_str)
        driver = get_driver(driverCls, provider, identity)
        volume = driver.get_volume(volume_id)
        if unmount:
            tmp_status = "umount_error"
        else:
            tmp_status = "mount_error"
        return volume_service.update_volume_metadata(driver, volume, metadata={"tmp_status": tmp_status})
        celery_logger.debug("mount_failed task finished at %s." % datetime.now())
    except Exception as exc:
        celery_logger.warn(exc)
        mount_failed.retry(exc=exc)