Revision 253f0c82

b/api/handlers.py
5 5

  
6 6
from piston.handler import BaseHandler, AnonymousBaseHandler
7 7
from synnefo.api.faults import fault, noContent, accepted, created
8
from synnefo.api.helpers import instance_to_server
9
from synnefo.util.rapi import GanetiRapiClient
10
from django.conf import settings
11

  
12
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
8 13

  
9 14
VERSIONS = [
10 15
    {
......
38 43
    def read(self, request, id=None):
39 44
        if id is None:
40 45
            return self.read_all(request)
41
        elif id is "detail":
46
        elif id == "detail":
42 47
            return self.read_all(request, detail=True)
43 48
        else:
44 49
            return self.read_one(request, id)
45 50

  
46 51
    def read_one(self, request, id):
47
        print ("server info %s" % id)
48
        return {}
52
        instance = rapi.GetInstance(id)
53
        return { "server": instance_to_server(instance) }
49 54

  
50 55
    def read_all(self, request, detail=False):
51 56
        if not detail:
52
            print "server info all"
57
            instances = rapi.GetInstances(bulk=False)
58
            servers = [ { "id": id, "name": id } for id in instances ]
53 59
        else:
54
            print "server info all detail"
55
        return {}
60
            instances = rapi.GetInstances(bulk=True)
61
            servers = []
62
            for instance in instances:
63
                servers.append(instance_to_server(instance))
64
        return { "servers": servers }
56 65

  
57 66
    def create(self, request):
58 67
        return accepted
b/api/helpers.py
1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

  
6
# XXX: most of the keys below are dummy
7
def instance_to_server(instance):
8
    server = {
9
            "id": instance["name"],
10
            "name": instance["name"],
11
            "hostId": instance["pnode"],
12
            "imageId": 1,
13
            "flavorId": 1,
14
            "addresses": {
15
                "public": [ ],
16
                "private": [ ],
17
                },
18
            "metadata": { }
19
    }
20
    if instance["status"] == "running":
21
        server["status"] = "ACTIVE"
22
    elif instance["status"] == "ADMIN_down":
23
        server["status"] = "SUSPENDED"
24
    else:
25
        server["status"] = "UNKNOWN"
26

  
27
    return server
b/settings.py.dist
98 98
    'synnefo.auth',
99 99
    'synnefo.api',
100 100
)
101

  
102
GANETI_CLUSTER_INFO = ('ganeti.example.org', 5080)

Also available in: Unified diff