Revision cb4eee84

b/snf-cyclades-app/synnefo/logic/backend.py
42 42
                               pooled_rapi_client, BridgePoolTable,
43 43
                               MacPrefixPoolTable, VirtualMachineDiagnostic)
44 44
from synnefo.logic import utils
45
from synnefo import quotas
45 46

  
46 47
from logging import getLogger
47 48
log = getLogger(__name__)
......
55 56
_reverse_tags = dict((v.split(':')[3], k) for k, v in _firewall_tags.items())
56 57

  
57 58

  
59
@quotas.uses_commission
58 60
@transaction.commit_on_success
59
def process_op_status(vm, etime, jobid, opcode, status, logmsg):
61
def process_op_status(serials, vm, etime, jobid, opcode, status, logmsg):
60 62
    """Process a job progress notification from the backend
61 63

  
62 64
    Process an incoming message from the backend (currently Ganeti).
......
79 81
    if status == 'success' and state_for_success is not None:
80 82
        vm.operstate = state_for_success
81 83

  
82

  
83 84
    # Special case: if OP_INSTANCE_CREATE fails --> ERROR
84
    if status in ('canceled', 'error') and opcode == 'OP_INSTANCE_CREATE':
85
    if opcode == 'OP_INSTANCE_CREATE' and status in ('canceled', 'error'):
85 86
        vm.operstate = 'ERROR'
86 87
        vm.backendtime = etime
87

  
88
    if opcode == 'OP_INSTANCE_REMOVE':
88
    elif opcode == 'OP_INSTANCE_REMOVE':
89 89
        # Set the deleted flag explicitly, cater for admin-initiated removals
90 90
        # Special case: OP_INSTANCE_REMOVE fails for machines in ERROR,
91 91
        # when no instance exists at the Ganeti backend.
......
93 93
        #
94 94
        if status == 'success' or (status == 'error' and
95 95
                                   vm.operstate == 'ERROR'):
96
            # Issue commission
97
            serial = quotas.issue_vm_commission(vm.userid, vm.flavor,
98
                                                delete=True)
99
            serials.append(serial)
100
            vm.serial = serial
101
            serial.accepted = True
102
            serial.save()
96 103
            release_instance_nics(vm)
97 104
            vm.nics.all().delete()
98 105
            vm.deleted = True
......
230 237
    update_network_state(back_network.network)
231 238

  
232 239

  
240
@quotas.uses_commission
241
@transaction.commit_on_success
242
def update_network_state(serials, network):
243
    old_state = network.state
244

  
245
    backend_states = [s.operstate for s in network.backend_networks.all()]
246
    if not backend_states:
247
        network.state = 'PENDING'
248
        network.save()
249
        return
250

  
251
    all_equal = len(set(backend_states)) <= 1
252
    network.state = all_equal and backend_states[0] or 'PENDING'
253

  
254
    # Release the resources on the deletion of the Network
255
    if old_state != 'DELETED' and network.state == 'DELETED':
256
        log.info("Network %r deleted. Releasing link %r mac_prefix %r",
257
                 network.id, network.mac_prefix, network.link)
258
        network.deleted = True
259
        if network.mac_prefix and network.type == 'PRIVATE_MAC_FILTERED':
260
            mac_pool = MacPrefixPoolTable.get_pool()
261
            mac_pool.put(network.mac_prefix)
262
            mac_pool.save()
263

  
264
        if network.link and network.type == 'PRIVATE_VLAN':
265
            bridge_pool = BridgePoolTable.get_pool()
266
            bridge_pool.put(network.link)
267
            bridge_pool.save()
268

  
269
        # Issue commission
270
        serial = quotas.issue_network_commission(network.userid, delete=True)
271
        serials.append(serial)
272
        network.serial = serial
273
        serial.accepted = True
274
        serial.save()
275

  
276
    network.save()
277

  
278

  
233 279
@transaction.commit_on_success
234 280
def process_network_modify(back_network, etime, jobid, opcode, status,
235 281
                           add_reserved_ips, remove_reserved_ips):

Also available in: Unified diff