From ccf4c96ae0680f2e4586f3475bcb5197ab526ed4 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Mon, 4 Jun 2012 17:33:23 +0200 Subject: [PATCH] use primary mac as node id --- d3mapbuilder.py | 2 +- node.py | 1 + nodedb.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/d3mapbuilder.py b/d3mapbuilder.py index fc1f255..9148961 100644 --- a/d3mapbuilder.py +++ b/d3mapbuilder.py @@ -7,7 +7,7 @@ class D3MapBuilder: def build(self): output = dict() - output['nodes'] = [{'group': x.group, 'name': x.name, + output['nodes'] = [{'group': x.group, 'name': x.name, 'id': x.id, 'macs': ', '.join(x.macs) } for x in self._db.get_nodes() if x.online] output['links'] = [{'source': x.pair[0], 'target': x.pair[1], diff --git a/node.py b/node.py index d6a2366..077d399 100644 --- a/node.py +++ b/node.py @@ -1,6 +1,7 @@ class Node(): def __init__(self): self.name = "" + self.id = "" self.macs = set() self.group = 0 self.online = False diff --git a/nodedb.py b/nodedb.py index 483545d..87a0c27 100644 --- a/nodedb.py +++ b/nodedb.py @@ -98,6 +98,17 @@ class NodeDB: self._links.add(tuple(sorted((a,b)))) + for line in lines: + x = json.loads(line) + + if 'primary' in x: + try: + node = self.maybe_node_by_mac((x['primary'], )) + except: + continue + + node.id = x['primary'] + def import_aliases(self, aliases): for mac, alias in aliases.items(): try: