Revision 9071888e api/handlers.py

b/api/handlers.py
1 1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2 2
#
3
# Copyright ??? 2010 Greek Research and Technology Network
3
# Copyright ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? 2010 Greek Research and Technology Network
4 4
#
5 5

  
6 6
from django.conf import settings
......
29 29
        "docURL" : "http://docs.rackspacecloud.com/servers/api/v1.0/cs-devguide-20090714.pdf ",
30 30
        "wadl" : "http://docs.rackspacecloud.com/servers/api/v1.0/application.wadl"
31 31
    },
32
    {
33
        "status": "CURRENT",
34
        "id": "v1.0grnet1",
35
        "docURL" : "None yet",
36
        "wad1" : "None yet"
37
    }
32 38
]
33 39

  
34 40

  
......
325 331
        return noContent
326 332

  
327 333

  
328

  
329 334
class LimitHandler(BaseHandler):
330 335
    allowed_methods = ('GET',)
331 336

  
......
391 396
                "absolute": self.absolute,
392 397
               }
393 398
            }
399

  
400

  
401
class DiskHandler(BaseHandler):
402
    allowed_methods = ('GET', 'POST', 'PUT', 'DELETE')
403

  
404
    def read(self, request, id=None):
405
        """List Disks"""
406
        if id is None:
407
            return self.read_all(request)
408
        elif id == "detail":
409
            return self.read_all(request, detail=True)
410
        else:
411
            return self.read_one(request, id)
412

  
413
    def read_one(self, request, id):
414
        """List one Disk with the specified id with all details"""
415
        # FIXME Get detailed info from the DB 
416
        # for the Disk with the specified id
417
        try:
418
            disk = Disk.objects.get(pk=id)
419
            disk_details = {
420
                "id" : disk.id, 
421
                "name" : disk.name, 
422
                "size" : disk.size,
423
                "created" : disk.created, 
424
                "serverId" : disk.vm.id
425
            }
426
            return { "disks" : disk_details }
427
        except:
428
            raise fault.itemNotFound
429

  
430
    @paginator
431
    def read_all(self, request, detail=False):
432
        """List all Disks. If -detail- is set list them with all details"""
433
        if not detail:
434
            disks = Disk.objects.filter(owner=SynnefoUser.objects.all()[0])
435
            return { "disks": [ { "id": disk.id, "name": disk.name } for disk in disks ] }
436
        else:
437
            disks = Disk.objects.filter(owner=SynnefoUser.objects.all()[0])
438
            disks_details = [ {
439
                "id" : disk.id, 
440
                "name" : disk.name,
441
                "size" : disk.size,
442
                "created" : disk.created, 
443
                "serverId" : disk.vm.id,
444
            } for disk in disks ]
445
            return { "disks":  disks_details }                
446

  
447
    def create(self, request):
448
        """Create a new Disk"""
449
        # FIXME Create a partial DB entry, 
450
        # then call the backend for actual creation
451
        pass
452

  
453
    def update(self, request, id):
454
        """Rename the Disk with the specified id"""
455
        # FIXME Change the Disk's name in the DB
456
        pass
457

  
458
    def delete(self, request, id):
459
        """Destroy the Disk with the specified id"""
460
        # Call the backend for actual destruction
461
        pass

Also available in: Unified diff