def _refresh_devices(): dmap = network.devices() def update_connection(dconfig): if ('connection' in dconfig): try: dconfig['connection'] = NetworkConnection.objects.get( name=dconfig['connection']) except (NetworkConnection.DoesNotExist, NetworkConnection.MultipleObjectsReturned) as e: logger.exception(e) dconfig['connection'] = None for ndo in NetworkDevice.objects.all(): if (ndo.name not in dmap): ndo.delete() continue dconfig = dmap[ndo.name] update_connection(dconfig) NetworkDevice.objects.filter(name=ndo.name).update(**dconfig) del dmap[ndo.name] for dev in dmap: dconfig = dmap[dev] dconfig['name'] = dev update_connection(dconfig) NetworkDevice.objects.create(**dconfig)
def _refresh_devices(): dmap = network.devices() def update_connection(dconfig): if ('connection' in dconfig): try: dconfig['connection'] = NetworkConnection.objects.get(name=dconfig['connection']) except (NetworkConnection.DoesNotExist, NetworkConnection.MultipleObjectsReturned), e: logger.exception(e) dconfig['connection'] = None