Пример #1
0
 def _refresh_connections(cls):
     cmap = network.connections()
     defer_master_updates = []
     for nco in NetworkConnection.objects.all():
         if (nco.uuid not in cmap):
             nco.delete()
             continue
         config = cmap[nco.uuid]
         if ('ctype' in config):
             ctype = config['ctype']
             cls._update_or_create_ctype(nco, ctype, config[ctype])
             del (config[ctype])
             del (config['ctype'])
         cls._update_master(nco, config, defer_master_updates)
         NetworkConnection.objects.filter(uuid=nco.uuid).update(**config)
         del cmap[nco.uuid]
     for uuid in cmap:
         #new connections not yet in administrative state.
         config = cmap[uuid]
         config['uuid'] = uuid
         ctype = ctype_d = None
         if ('ctype' in config):
             ctype = config['ctype']
             ctype_d = config[ctype]
             del (config[ctype])
             del (config['ctype'])
         if ('master' in config):
             defer_master_updates.append({
                 'uuid': uuid,
                 'master': config['master']
             })
             del (config['master'])
         nco = NetworkConnection.objects.create(**config)
         if (ctype is not None):
             cls._update_or_create_ctype(nco, ctype, ctype_d)
     for e in defer_master_updates:
         slave_co = NetworkConnection.objects.get(uuid=e['uuid'])
         try:
             slave_co.master = NetworkConnection.objects.get(
                 name=e['master'])
         except (NetworkConnection.DoesNotExist,
                 NetworkConnection.MultipleObjectsReturned), e:
             logger.exception(e)
         slave_co.save()
Пример #2
0
 def _refresh_connections(cls):
     cmap = network.connections()
     defer_master_updates = []
     for nco in NetworkConnection.objects.all():
         if (nco.uuid not in cmap):
             nco.delete()
             continue
         config = cmap[nco.uuid]
         if ('ctype' in config):
             ctype = config['ctype']
             cls._update_or_create_ctype(nco, ctype, config[ctype])
             del(config[ctype])
             del(config['ctype'])
         cls._update_master(nco, config, defer_master_updates)
         NetworkConnection.objects.filter(uuid=nco.uuid).update(**config)
         del cmap[nco.uuid]
     for uuid in cmap:
         # new connections not yet in administrative state.
         config = cmap[uuid]
         config['uuid'] = uuid
         ctype = ctype_d = None
         if ('ctype' in config):
             ctype = config['ctype']
             ctype_d = config[ctype]
             del(config[ctype])
             del(config['ctype'])
         if ('master' in config):
             defer_master_updates.append({'uuid': uuid, 'master':
                                          config['master']})
             del(config['master'])
         nco = NetworkConnection.objects.create(**config)
         if (ctype is not None):
             cls._update_or_create_ctype(nco, ctype, ctype_d)
     for e in defer_master_updates:
         slave_co = NetworkConnection.objects.get(uuid=e['uuid'])
         try:
             slave_co.master = NetworkConnection.objects.get(name=e['master'])  # noqa E501
         except (NetworkConnection.DoesNotExist,
                 NetworkConnection.MultipleObjectsReturned) as e:
             logger.exception(e)
         slave_co.save()