Revision ec06b07c api/handlers.py

b/api/handlers.py
8 8
from synnefo.api.faults import fault, noContent, accepted, created
9 9
from synnefo.api.helpers import instance_to_server, paginator
10 10
from synnefo.util.rapi import GanetiRapiClient, GanetiApiError
11
from synnefo.vocabs import MOCK_SERVERS, MOCK_IMAGES
11 12

  
12
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
13
if settings.GANETI_CLUSTER_INFO:
14
    rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
15
else:
16
    rapi = None
13 17

  
14 18
VERSIONS = [
15 19
    {
......
49 53
            return self.read_one(request, id)
50 54

  
51 55
    def read_one(self, request, id):
56
        if not rapi: # No ganeti backend. Return mock objects
57
            return { "server": MOCK_SERVERS[0] }
52 58
        try:
53 59
            instance = rapi.GetInstance(id)
54 60
            return { "server": instance_to_server(instance) }
......
57 63

  
58 64
    @paginator
59 65
    def read_all(self, request, detail=False):
66
        if not rapi: # No ganeti backend. Return mock objects
67
            if detail:
68
                return { "servers": MOCK_SERVERS }
69
            else:
70
                return { "servers": [ { "id": s['id'], "name": s['name'] } for s in MOCK_SERVERS ] }
71

  
60 72
        if not detail:
61 73
            instances = rapi.GetInstances(bulk=False)
62 74
            servers = [ { "id": id, "name": id } for id in instances ]
......
173 185
        Faults: cloudServersFault, serviceUnavailable, unauthorized,
174 186
                badRequest, itemNotFound
175 187
        """
188
        if not rapi: # No ganeti backend. Return mock objects
189
            if id == "detail":
190
                return { "images": MOCK_IMAGES }
191
            elif id is None:
192
                return { "images": [ { "id": s['id'], "name": s['name'] } for s in MOCK_IMAGES ] }
193
            else:
194
                return { "image": MOCK_IMAGES[0] }
176 195
        if id is None:
177 196
            return {}
178 197
        elif id == "detail":

Also available in: Unified diff