Ejemplo n.º 1
0
def delete_volumes(request):
    """
    :param request: request object
    :return view<'get_volume_list'>: the view get_volume_list
    """
    _status_code = UI_RESPONSE_DWZ_ERROR
    _msg = 'Delete Volumes Failed!'
    data = request.POST.getlist("delete_volume")
    if data:
        for volume_id in data:
            try:
                volume = api.volume_get(request, volume_id)
                if volume.status in DELETABLE_STATES:
                    try:
                        api.volume_delete(request, volume.id)
                        _msg = "Delete Volumes Successfully"
                        _status_code = UI_RESPONSE_DWZ_SUCCESS
                    except Unauthorized:
                        raise
                    except Exception, ex:
                        if ex.code != UI_RESPONSE_BADREQUEST:
                            LOG.error("delete volumes failed error is %s" % ex)
                        else:
                            LOG.error('BadRequest %s' % ex)
            except Unauthorized:
                raise
            except Exception, ex:
                LOG.error("Volume is not found error is %s" % ex)
Ejemplo n.º 2
0
def volume_detail(request, volume_id):
    """
    :param request: request object
    :param volume_id: the volume's id
    :return view<'volume_manage/detail.html'>: view get_volume_detail
    """
    try:
        volume = api.volume_get(request, volume_id)
        #        create_time = (dateutil.parser.parse(volume.created_at) + abs(
        #            datetime.now() - datetime.utcnow())).strftime(
        #            "%Y-%m-%d %H:%M:%S")
        #        setattr(volume, "create_time", create_time)

        try:
            tenant_id = getattr(volume, 'os-vol-tenant-attr:tenant_id', None)
            tenant = api.tenant_get(
                request, tenant_id, getattr(request.user, "is_superuser",
                                            True))
        except Exception, ex:
            LOG.error("no tenant id,the error is %s" % ex)
            tenant = None

            pass

        if volume is None:
            return HttpResponse(
                {
                    "message": "The volume does not exist",
                    "statusCode": UI_RESPONSE_DWZ_ERROR
                },
                status=UI_RESPONSE_ERROR)
Ejemplo n.º 3
0
def delete_single_volume(request):
    status_code = UI_RESPONSE_DWZ_ERROR
    object_name = ''

    if vu.volume_id:
        try:
            volume = api.volume_get(request, vu.volume_id)

            if volume and volume.status != "deleting":
                vu.volume_id = None
        except Unauthorized:
            raise
        except Exception, ex:
            vu.volume_id = None
            LOG.error("the error is %s" % ex)
Ejemplo n.º 4
0
def volume_status(request, volume_id):
    if request.is_ajax():
        instance_id = None
        other_error = False
        try:
            volume = api.volume_get(request, volume_id)
            att = volume.attachments
            if len(att) > 0:
                instance_id = att[0]['server_id']
        except Unauthorized:
            raise
        except exceptions.NotFound, enf:
            volume = None
            LOG.error("the volume not found the error is %s" % enf)
        except Exception, ex:
            other_error = True
            volume = None
            LOG.error("the volume not found the error is %s" % ex)
Ejemplo n.º 5
0
def get_snapshot_detail(request, snapshot_id):
    _status_code = UI_RESPONSE_DWZ_ERROR
    _msg = None
    if snapshot_id:
        try:
            snapshot = api.volume_snapshot_get(request, snapshot_id)

            if snapshot:
                volume = api.volume_get(request, snapshot.volume_id)
                volume_name = None
                if volume:
                    volume_name = volume.display_name

                setattr(snapshot, 'volume_name', volume_name)
        except Unauthorized:
            raise
        except Exception, ex:
            LOG.error("Get Snapshot detail failed,the error is %s" % ex)
            _msg = 'Get Snapshot detail failed'
Ejemplo n.º 6
0
            if ex.message.count('dependent snapshots') > 0:
                msg = "Please delete Volume Snapshot corresponding to the Volume!"

            LOG.error(ex)
            return HttpResponse(
                {
                    "message": get_text(msg),
                    "statusCode": status_code
                },
                status=UI_RESPONSE_ERROR)

        vu.volume_id = volume_id

        try:
            volume = api.volume_get(request, volume_id)
            object_name = volume.display_name
        except Exception, ex:
            LOG.error("the error is %s" % ex)
    else:
        msg = 'Existing volume is deleted,please wait...'
        object_name = ''

    return HttpResponse(
        {
            "message": get_text(msg),
            "statusCode": status_code,
            "object_name": object_name
        },
        status=status_code)