Revision a1baa42b snf-cyclades-app/synnefo/logic/reconciliation.py

b/snf-cyclades-app/synnefo/logic/reconciliation.py
288 288
        db_nics = db_server.nics.order_by("index")
289 289
        gnt_nics = gnt_server["nics"]
290 290
        gnt_nics_parsed = backend_mod.process_ganeti_nics(gnt_nics)
291
        if backend_mod.nics_changed(db_nics, gnt_nics_parsed):
292
            msg = "Found unsynced NICs for server '%s'.\n\t"\
293
                  "DB: %s\n\tGaneti: %s"
294
            db_nics_str = ", ".join(map(format_db_nic, db_nics))
295
            gnt_nics_str = ", ".join(map(format_gnt_nic, gnt_nics_parsed))
291
        nics_changed = len(db_nics) != len(gnt_nics)
292
        for db_nic, gnt_nic in zip(db_nics, sorted(gnt_nics_parsed.items())):
293
            gnt_nic_id, gnt_nic = gnt_nic
294
            if (db_nic.id == gnt_nic_id) and\
295
               backend_mod.nics_are_equal(db_nic, gnt_nic):
296
                continue
297
            else:
298
                nics_changed = True
299
                break
300
        if nics_changed:
301
            msg = "Found unsynced NICs for server '%s'.\n"\
302
                  "\tDB:\n\t\t%s\n\tGaneti:\n\t\t%s"
303
            db_nics_str = "\n\t\t".join(map(format_db_nic, db_nics))
304
            gnt_nics_str = "\n\t\t".join(map(format_gnt_nic,
305
                                         gnt_nics_parsed.items()))
296 306
            self.log.info(msg, server_id, db_nics_str, gnt_nics_str)
297 307
            if self.options["fix_unsynced_nics"]:
298 308
                backend_mod.process_net_status(vm=db_server,
......
322 332
                self.log.info("Cleared pending task for server '%s", server_id)
323 333

  
324 334

  
335
NIC_MSG = ": %s\t".join(["ID", "State", "IP", "Network", "MAC", "Firewall"])\
336
    + ": %s"
337

  
338

  
325 339
def format_db_nic(nic):
326
    return "Index: %s, IP: %s Network: %s MAC: %s Firewall: %s" % (nic.index,
327
           nic.ipv4, nic.network_id, nic.mac, nic.firewall_profile)
340
    return NIC_MSG % (nic.id, nic.state, nic.ipv4, nic.network_id, nic.mac,
341
                      nic.firewall_profile)
328 342

  
329 343

  
330 344
def format_gnt_nic(nic):
331
    return "Index: %s IP: %s Network: %s MAC: %s Firewall: %s" %\
332
           (nic["index"], nic["ipv4"], nic["network"], nic["mac"],
333
            nic["firewall_profile"])
345
    nic_name, nic = nic
346
    return NIC_MSG % (nic_name, nic["state"], nic["ipv4"], nic["network"],
347
                      nic["mac"], nic["firewall_profile"])
334 348

  
335 349

  
336 350
#
......
420 434

  
421 435
def nics_from_instance(i):
422 436
    ips = zip(itertools.repeat('ip'), i['nic.ips'])
437
    names = zip(itertools.repeat('name'), i['nic.names'])
423 438
    macs = zip(itertools.repeat('mac'), i['nic.macs'])
424
    networks = zip(itertools.repeat('network'), i['nic.networks'])
439
    networks = zip(itertools.repeat('network'), i['nic.networks.names'])
425 440
    # modes = zip(itertools.repeat('mode'), i['nic.modes'])
426 441
    # links = zip(itertools.repeat('link'), i['nic.links'])
427 442
    # nics = zip(ips,macs,modes,networks,links)
428
    nics = zip(ips, macs, networks)
443
    nics = zip(ips, names, macs, networks)
429 444
    nics = map(lambda x: dict(x), nics)
430 445
    #nics = dict(enumerate(nics))
431 446
    tags = i["tags"]

Also available in: Unified diff