Revision e6fbada1

b/snf-cyclades-app/synnefo/logic/backend.py
115 115

  
116 116
@transaction.commit_on_success
117 117
def process_op_status(vm, etime, jobid, opcode, status, logmsg, nics=None,
118
                      beparams=None):
118
                      job_fields=None):
119 119
    """Process a job progress notification from the backend
120 120

  
121 121
    Process an incoming message from the backend (currently Ganeti).
......
137 137
        vm.save()
138 138
        return
139 139

  
140
    if job_fields is None:
141
        job_fields = {}
140 142
    state_for_success = VirtualMachine.OPER_STATE_FROM_OPCODE.get(opcode)
141 143

  
142 144
    # Notifications of success change the operating state
143 145
    if status == "success":
144 146
        if state_for_success is not None:
145 147
            vm.operstate = state_for_success
148
        beparams = job_fields.get("beparams", None)
146 149
        if beparams:
147 150
            # Change the flavor of the VM
148 151
            _process_resize(vm, beparams)
......
180 183

  
181 184
    if status in ["success", "error", "canceled"]:
182 185
        # Job is finalized: Handle quotas/commissioning
183
        job_fields = {"nics": nics, "beparams": beparams}
186
        fields = {"nics": nics, "beparams": beparams}
184 187
        vm = handle_vm_quotas(vm, job_id=jobid, job_opcode=opcode,
185
                              job_status=status, job_fields=job_fields)
188
                              job_status=status, job_fields=fields)
186 189
        # and clear task fields
187 190
        if vm.task_job_id == jobid:
188 191
            vm.task = None
......
424 427

  
425 428
@transaction.commit_on_success
426 429
def process_network_modify(back_network, etime, jobid, opcode, status,
427
                           add_reserved_ips):
430
                           job_fields):
428 431
    assert (opcode == "OP_NETWORK_SET_PARAMS")
429 432
    if status not in [x[0] for x in BACKEND_STATUSES]:
430 433
        raise Network.InvalidBackendMsgError(opcode, status)
......
433 436
    back_network.backendjobstatus = status
434 437
    back_network.opcode = opcode
435 438

  
439
    add_reserved_ips = job_fields.get("add_reserved_ips")
436 440
    if add_reserved_ips:
437 441
        net = back_network.network
438 442
        pool = net.get_pool()
b/snf-cyclades-app/synnefo/logic/callbacks.py
171 171
        log.error("Message is of unknown type %s.", msg['type'])
172 172
        return
173 173

  
174
    nics = msg.get("nics", None)
175
    beparams = msg.get("beparams", None)
174
    nics = msg.get("instance_nics", None)
175
    job_fields = msg.get("job_fields", {})
176 176
    backend_mod.process_op_status(vm, event_time, msg['jobId'],
177 177
                                  msg['operation'], msg['status'],
178 178
                                  msg['logmsg'], nics=nics,
179
                                  beparams=beparams)
179
                                  job_fields=job_fields)
180 180

  
181 181
    log.debug("Done processing ganeti-op-status msg for vm %s.",
182 182
              msg['instance'])
......
195 195
    opcode = msg['operation']
196 196
    status = msg['status']
197 197
    jobid = msg['jobId']
198
    job_fields = msg.get('job_fields', {})
198 199

  
199 200
    if opcode == "OP_NETWORK_SET_PARAMS":
200 201
        backend_mod.process_network_modify(network, event_time, jobid, opcode,
201
                                           status, msg['add_reserved_ips'])
202
                                           status, job_fields)
202 203
    else:
203 204
        backend_mod.process_network_status(network, event_time, jobid, opcode,
204 205
                                           status, msg['logmsg'])
b/snf-cyclades-app/synnefo/logic/reconciliation.py
274 274
                backend_mod.process_op_status(
275 275
                    vm=db_server, etime=self.event_time, jobid=-0,
276 276
                    opcode=opcode, status='success',
277
                    beparams=beparams,
277
                    job_fields={"beparams": beparams},
278 278
                    logmsg='Reconciliation: simulated Ganeti event')
279 279
                # process_op_status with beparams will set the vmstate to
280 280
                # shutdown. Fix this be returning it to old state
b/snf-cyclades-gtools/synnefo/ganeti/eventd.py
282 282
        self.logger.debug("Job: %d: %s(%s) %s", job_id, op_id,
283 283
                          instances, op.status)
284 284

  
285
        job_fields = {}
286
        if op_id in ["OP_INSTANCE_SET_PARAMS", "OP_INSTANCE_CREATE"]:
287
            job_fields = {"nics": get_field(input, "nics"),
288
                          "disks": get_field(input, "disks"),
289
                          "beparams": get_field(input, "beparams")}
290

  
285 291
        msg = {"type": "ganeti-op-status",
286 292
               "instance": instances,
287
               "operation": op_id}
293
               "operation": op_id,
294
               "job_fields": job_fields}
288 295

  
289
        if op_id == "OP_INSTANCE_SET_PARAMS":
290
            beparams = get_field(input, "beparams")
291
            if beparams:
292
                msg["beparams"] = beparams
296
        if op_id in ["OP_INSTANCE_CREATE", "OP_INSTANCE_SET_PARAMS",
297
                     "OP_INSTANCE_STARTUP"]:
298
            if op.status == "success":
299
                nics = get_instance_nics(msg["instance"], self.logger)
300
                msg["instance_nics"] = nics
293 301

  
294 302
        routekey = "ganeti.%s.event.op" % prefix_from_name(instances)
295 303

  
......
310 318
        self.logger.debug("Job: %d: %s(%s) %s", job_id, op_id,
311 319
                          network_name, op.status)
312 320

  
321
        job_fields = {
322
            'subnet': get_field(input, 'network'),
323
            'gateway': get_field(input, 'gateway'),
324
            "add_reserved_ips": get_field(input, "add_reserved_ips"),
325
            "remove_reserved_ips": get_field(input, "remove_reserved_ips"),
326
            # 'network_mode': get_field(input, 'network_mode'),
327
            # 'network_link': get_field(input, 'network_link'),
328
            'group_name': get_field(input, 'group_name')}
329

  
313 330
        msg = {'operation':    op_id,
314 331
               'type':         "ganeti-network-status",
315 332
               'network':      network_name,
316
               'subnet':       get_field(input, 'network'),
317
               # 'network_mode': get_field(input, 'network_mode'),
318
               # 'network_link': get_field(input, 'network_link'),
319
               'gateway':      get_field(input, 'gateway'),
320
               'group_name':   get_field(input, 'group_name')}
321

  
322
        if op_id == "OP_NETWORK_SET_PARAMS":
323
            msg["add_reserved_ips"] = get_field(input, "add_reserved_ips")
324
            msg["remove_reserved_ips"] = get_field(input,
325
                                                   "remove_reserved_ips")
333
               'job_fields':   job_fields}
334

  
326 335
        routekey = "ganeti.%s.event.network" % prefix_from_name(network_name)
327 336

  
328 337
        return msg, routekey

Also available in: Unified diff