use primary mac as node id

This commit is contained in:
Nils Schneider 2012-06-04 17:33:23 +02:00
parent cc3b69d6be
commit ccf4c96ae0
3 changed files with 13 additions and 1 deletions

View file

@ -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],

View file

@ -1,6 +1,7 @@
class Node():
def __init__(self):
self.name = ""
self.id = ""
self.macs = set()
self.group = 0
self.online = False

View file

@ -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: