Created
June 25, 2012 09:39
-
-
Save norrs/2987656 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _get_datasource_lookup(graph): | |
edges_iter = graph.edges_iter(data=True) | |
interfaces = set() | |
for _, _, w in edges_iter: | |
w = w['metadata'] | |
if 'uplink' in w: | |
if w['uplink']['thiss']['interface']: | |
interfaces.add(w['uplink']['thiss']['interface'].pk) | |
if w['uplink']['other']['interface']: | |
interfaces.add(w['uplink']['other']['interface'].pk) | |
_LOGGER.debug( | |
"netmap:attach_rrd_data_to_edges() datasource id filter list done") | |
from nav.models.rrd import RrdDataSource | |
datasources = RrdDataSource.objects.filter( | |
rrd_file__key='interface').select_related('rrd_file').filter( | |
rrd_file__value__in=interfaces) | |
_LOGGER.debug("netmap:attach_rrd_data_to_edges() Datasources fetched done") | |
lookup_dict = {} | |
for data in datasources: | |
interface = int(data.rrd_file.value) | |
if interface in lookup_dict: | |
lookup_dict[interface].append(data) | |
else: | |
lookup_dict.update({interface: [data]}) | |
_LOGGER.debug( | |
"netmap:attach_rrd_data_to_edges() Datasources rearranged in dict") | |
return lookup_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment