Revision 5abebfaa api/handlers.py

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)

Also available in: Unified diff