Revision 5abebfaa

b/api/handlers.py
16 16
import logging
17 17
from datetime import datetime, timedelta
18 18

  
19
from logic import backend, utils
20

  
19 21
log = logging.getLogger('synnefo.api.handlers')
20 22

  
21 23
try:
......
101 103
        try:
102 104
            server = VirtualMachine.objects.get(id=id)
103 105

  
104
            server = {'status': server.rsapi_state, 
106
            server = {'status': utils.get_rsapi_state(server),
105 107
                     'flavorRef': server.flavor.id, 
106 108
                     'name': server.name, 
107 109
                     'id': server.id, 
......
109 111
                     'created': server.created, 
110 112
                     'updated': server.updated,
111 113
                     'hostId': server.hostid, 
112
                     'progress': server.rsapi_state == 'ACTIVE' and 100 or 0, 
114
                     'progress': utils.get_rsapi_state(server) == 'ACTIVE' and 100 or 0,
113 115
                     #'metadata': {'Server_Label': server.description },
114 116
                     'metadata':[{'meta': { 'key': {metadata.meta_key: metadata.meta_value}}} for metadata in server.virtualmachinemetadata_set.all()],                                    
115 117
                     'addresses': {'public': { 'ip': {'addr': server.ipfour}, 'ip6': {'addr': server.ipsix}},'private': ''},      
......
146 148
            if not detail:
147 149
                return { "servers": [ { "id": s.id, "name": s.name } for s in virtual_servers ] }
148 150
            else:
149
                virtual_servers_list = [{'status': server.rsapi_state, 
151
                virtual_servers_list = [{'status': utils.get_rsapi_state(server),
150 152
                                         'flavorRef': server.flavor.id, 
151 153
                                         'name': server.name, 
152 154
                                         'id': server.id, 
......
154 156
                                         'updated': server.updated,
155 157
                                         'imageRef': server.sourceimage.id, 
156 158
                                         'hostId': server.hostid, 
157
                                         'progress': server.rsapi_state == 'ACTIVE' and 100 or 0, 
159
                                         'progress': utils.get_rsapi_state(server) == 'ACTIVE' and 100 or 0,
158 160
                                         #'metadata': {'Server_Label': server.description },
159 161
                                         'metadata':[{'meta': { 'key': {metadata.meta_key: metadata.meta_value}}} for metadata in server.virtualmachinemetadata_set.all()],                                    
160 162
                                         'addresses': {'public': { 'ip': {'addr': server.ipfour}, 'ip6': {'addr': server.ipsix}},'private': ''},      
......
235 237
            log.info('created vm with %s cpus, %s ram and %s storage' % (flavor.cpu, flavor.ram, flavor.disk))
236 238
        except (GanetiApiError, CertificateError) as e:
237 239
            log.exception('CreateInstance failed: %s' % e)
240
            # FIX: if the instance creation have failed, why it is saved in the db?
238 241
            vm.deleted = True
239 242
            vm.save()
240 243
            raise fault.serviceUnavailable
......
301 304
        try:
302 305
            vm = VirtualMachine.objects.get(id=id)
303 306
            #TODO: set the status to DESTROYED
304
            vm.start_action('DESTROY')
307
            backend.start_action(vm, 'DESTROY')
305 308
            rapi.DeleteInstance(vm.backend_id)
306 309
            return accepted        
307 310
        except VirtualMachine.DoesNotExist:
......
380 383
                raise fault.notImplemented 
381 384
            #test if we can get the vm
382 385
            vm = VirtualMachine.objects.get(id=id)
383
            vm.start_action(action)
386
            backend.start_action(vm, action)
384 387

  
385 388
            if reboot_request:
386 389
                rapi.RebootInstance(vm.backend_id)
b/api/servers.py
16 16

  
17 17
from logging import getLogger
18 18

  
19
from logic import utils
19 20

  
20 21
log = getLogger('synnefo.api.servers')
21 22
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
......
58 59
def server_to_dict(server, detail=False):
59 60
    d = dict(id=server.id, name=server.name)
60 61
    if detail:
61
        d['status'] = server.rsapi_state
62
        d['progress'] = 100 if server.rsapi_state == 'ACTIVE' else 0
62
        d['status'] = utils.get_rsapi_state(server)
63
        d['progress'] = 100 if utils.get_rsapi_state(server) == 'ACTIVE' else 0
63 64
        d['hostId'] = server.hostid
64 65
        d['updated'] = server.updated.isoformat()
65 66
        d['created'] = server.created.isoformat()

Also available in: Unified diff