コード例 #1
0
ファイル: networks.py プロジェクト: cstavr/synnefo
def list_networks(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug('list_networks detail=%s', detail)
    since = utils.isoparse(request.GET.get('changes-since'))
    user_networks = Network.objects.filter(Q(userid=request.user_uniq) |
                                           Q(public=True))

    if since:
        user_networks = user_networks.filter(updated__gte=since)
        if not user_networks:
            return HttpResponse(status=304)
    else:
        user_networks = user_networks.filter(deleted=False)

    networks = [network_to_dict(network, request.user_uniq, detail)
                for network in user_networks.order_by('id')]

    if request.serialization == 'xml':
        data = render_to_string('list_networks.xml', {
            'networks': networks,
            'detail': detail})
    else:
        data = json.dumps({'networks': networks})

    return HttpResponse(data, status=200)
コード例 #2
0
def list_images(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug('list_images detail=%s', detail)
    since = utils.isoparse(request.GET.get('changes-since'))
    with backend.PlanktonBackend(request.user_uniq) as b:
        images = b.list_images()
        if since:
            updated_since = lambda img: date_parse(img["updated_at"]) >= since
            images = ifilter(updated_since, images)
            if not images:
                return HttpResponse(status=304)

    images = sorted(images, key=lambda x: x['id'])
    reply = [image_to_dict(image, detail) for image in images]

    if request.serialization == 'xml':
        data = render_to_string('list_images.xml',
                                dict(images=reply, detail=detail))
    else:
        data = json.dumps(dict(images=reply))

    return HttpResponse(data, status=200)
コード例 #3
0
ファイル: servers.py プロジェクト: cstavr/synnefo
def list_servers(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug('list_servers detail=%s', detail)
    user_vms = VirtualMachine.objects.filter(userid=request.user_uniq)

    since = utils.isoparse(request.GET.get('changes-since'))

    if since:
        user_vms = user_vms.filter(updated__gte=since)
        if not user_vms:
            return HttpResponse(status=304)
    else:
        user_vms = user_vms.filter(deleted=False)

    servers = [vm_to_dict(server, detail)
               for server in user_vms.order_by('id')]

    if request.serialization == 'xml':
        data = render_to_string('list_servers.xml', {
            'servers': servers,
            'detail': detail})
    else:
        data = json.dumps({'servers': servers})

    return HttpResponse(data, status=200)
コード例 #4
0
def list_networks(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug('list_networks detail=%s', detail)
    since = utils.isoparse(request.GET.get('changes-since'))
    user_networks = Network.objects.filter(Q(userid=request.user_uniq) |
                                           Q(public=True))

    if since:
        user_networks = user_networks.filter(updated__gte=since)
        if not user_networks:
            return HttpResponse(status=304)
    else:
        user_networks = user_networks.filter(deleted=False)

    networks = [network_to_dict(network, request.user_uniq, detail)
                for network in user_networks.order_by('id')]

    if request.serialization == 'xml':
        data = render_to_string('list_networks.xml', {
            'networks': networks,
            'detail': detail})
    else:
        data = json.dumps({'networks': networks})

    return HttpResponse(data, status=200)
コード例 #5
0
ファイル: images.py プロジェクト: vkoukis/synnefo
def list_images(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug("list_images detail=%s", detail)
    since = utils.isoparse(request.GET.get("changes-since"))
    with image_backend(request.user_uniq) as backend:
        images = backend.list_images()
        if since:
            updated_since = lambda img: date_parse(img["updated_at"]) >= since
            images = ifilter(updated_since, images)
            if not images:
                return HttpResponse(status=304)

    images = sorted(images, key=lambda x: x["id"])
    reply = [image_to_dict(image, detail) for image in images]

    if request.serialization == "xml":
        data = render_to_string("list_images.xml", dict(images=reply, detail=detail))
    else:
        data = json.dumps(dict(images=reply))

    return HttpResponse(data, status=200)
コード例 #6
0
def list_servers(request, detail=False):
    # Normal Response Codes: 200, 203
    # Error Response Codes: computeFault (400, 500),
    #                       serviceUnavailable (503),
    #                       unauthorized (401),
    #                       badRequest (400),
    #                       overLimit (413)

    log.debug('list_servers detail=%s', detail)
    user_vms = VirtualMachine.objects.filter(userid=request.user_uniq)

    since = utils.isoparse(request.GET.get('changes-since'))

    if since:
        user_vms = user_vms.filter(updated__gte=since)
        if not user_vms:
            return HttpResponse(status=304)
    else:
        user_vms = user_vms.filter(deleted=False)

    servers = [
        vm_to_dict(server, detail) for server in user_vms.order_by('id')
    ]

    if request.serialization == 'xml':
        data = render_to_string('list_servers.xml', {
            'servers': servers,
            'detail': detail
        })
    else:
        data = json.dumps({'servers': servers})

    return HttpResponse(data, status=200)
コード例 #7
0
ファイル: views.py プロジェクト: AthinaB/synnefo
def list_snapshots(request, detail=False):
    log.debug('list_snapshots detail=%s', detail)
    since = utils.isoparse(request.GET.get('changes-since'))
    with backend.PlanktonBackend(request.user_uniq) as b:
        snapshots = b.list_snapshots()
        if since:
            updated_since = lambda snap:\
                date_parse(snap["updated_at"]) >= since
            snapshots = ifilter(updated_since, snapshots)
            if not snapshots:
                return HttpResponse(status=304)

    snapshots = sorted(snapshots, key=lambda x: x['id'])
    snapshots_dict = [snapshot_to_dict(snapshot, detail)
                      for snapshot in snapshots]

    data = json.dumps(dict(snapshots=snapshots_dict))

    return HttpResponse(data, status=200)
コード例 #8
0
ファイル: views.py プロジェクト: kpelelis/synnefo
def list_snapshots(request, detail=False):
    util.assert_snapshots_enabled(request)
    since = utils.isoparse(request.GET.get('changes-since'))
    with backend.PlanktonBackend(request.user_uniq) as b:
        snapshots = b.list_snapshots()
        if since:
            updated_since = lambda snap:\
                date_parse(snap["updated_at"]) >= since
            snapshots = ifilter(updated_since, snapshots)
            if not snapshots:
                return HttpResponse(status=304)

    snapshots = sorted(snapshots, key=lambda x: x['id'])
    snapshots_dict = [
        snapshot_to_dict(snapshot, detail) for snapshot in snapshots
    ]

    data = json.dumps(dict(snapshots=snapshots_dict))

    return HttpResponse(data, status=200)