Wokring on support for hopglass server (raw.json).

This commit is contained in:
Simon Wüllhorst 2017-04-23 23:09:31 +02:00
parent 666cd20c04
commit 1a01718538
3 changed files with 15 additions and 8 deletions

View file

@ -42,7 +42,7 @@ class NodeHierarchy(object):
def __createNodeObjects__(self): def __createNodeObjects__(self):
nodes = {} nodes = {}
for nodeID, nodeValue in self.__nodesJson__.nodes.items(): for nodeID, nodeValue in self.__hopglass.nodes.items():
print('Create Node object #',len(nodes), '\r',end = '') print('Create Node object #',len(nodes), '\r',end = '')
nodes[nodeID] = Node(nodeValue) nodes[nodeID] = Node(nodeValue)
print('') print('')

View file

@ -4,11 +4,11 @@ class NodeInit(object):
self.nodeID = self.__jsonObject__['nodeinfo']['node_id'] self.nodeID = self.__jsonObject__['nodeinfo']['node_id']
self.interfaces = self.__getInterfaces__() self.interfaces = self.__getInterfaces__()
self.hostname = self.__jsonObject__['nodeinfo']['hostname'] self.hostname = self.__jsonObject__['nodeinfo']['hostname']
self.isGateway = self.__jsonObject__['flags']['gateway'] self.isGateway = self.__jsonObject__['nodeinfo']['isGateway']
self.geo = self.__getGeo__() self.geo = self.__getGeo__()
self.isAutoupdaterEnabled = self.__getAutoupdaterStatus__() self.isAutoupdaterEnabled = self.__getAutoupdaterStatus__()
self.autoupdaterBranch = self.__getBranch__() self.autoupdaterBranch = self.__getBranch__()
self.isOnline = self.__jsonObject__['flags']['online'] self.isOnline = self.__jsonObject__['nodeinfo']['isOnline']
self.publicIPv6Addresses = self.__getPublicAddresses__() self.publicIPv6Addresses = self.__getPublicAddresses__()
self.domID = self.__getSiteCode__() self.domID = self.__getSiteCode__()
@ -25,10 +25,7 @@ class NodeInit(object):
return False return False
def __getBranch__(self): def __getBranch__(self):
if 'autoupdater' in self.__jsonObject__['nodeinfo']['software']: return self.__jsonObject__.get('nodeinfo', {}).get('software', {}).get('autoupdater', {}).get('branch', None)
return self.__jsonObject__['nodeinfo']['software']['autoupdater']['branch']
else:
return None
def __getGeo__(self): def __getGeo__(self):
geo = {} geo = {}

View file

@ -8,6 +8,8 @@ class Hopglass(JsonParser):
self.ifIDs = {} self.ifIDs = {}
self.links = collections.defaultdict(dict) self.links = collections.defaultdict(dict)
self.nodes = {} self.nodes = {}
self.gatewayMacs = []
self.gateways = []
self.__aggregateData__() self.__aggregateData__()
#print(self.ifIDs) #print(self.ifIDs)
for k, v in self.links.items(): for k, v in self.links.items():
@ -17,11 +19,12 @@ class Hopglass(JsonParser):
for nodeID, nodeData in self.__jsonData__.items(): for nodeID, nodeData in self.__jsonData__.items():
# let pass nodes that provide all required informations only # let pass nodes that provide all required informations only
if not set(('nodeinfo', 'neighbours')) <= set(nodeData): if not set(('nodeinfo', 'neighbours', 'statistics')) <= set(nodeData):
continue continue
nodeInfo = nodeData['nodeinfo'] nodeInfo = nodeData['nodeinfo']
neighbours = nodeData['neighbours'] neighbours = nodeData['neighbours']
statistics = nodeData['statistics']
if not 'batadv' in neighbours: if not 'batadv' in neighbours:
continue continue
@ -29,6 +32,9 @@ class Hopglass(JsonParser):
if not 'mesh' in nodeInfo.get('network', {}): if not 'mesh' in nodeInfo.get('network', {}):
continue continue
if statistics.get('gateway', False):
self.gatewayMacs.append(statistics['gateway'])
for batID, batVal in nodeInfo['network']['mesh'].items(): for batID, batVal in nodeInfo['network']['mesh'].items():
if not 'interfaces' in batVal: if not 'interfaces' in batVal:
continue continue
@ -42,9 +48,13 @@ class Hopglass(JsonParser):
self.nodes[nodeID] = nodeData self.nodes[nodeID] = nodeData
for nodeID, nodeData in self.nodes.items(): for nodeID, nodeData in self.nodes.items():
nodeData['nodeinfo']['isGateway'] = False
nodeData['nodeinfo']['isOnline'] = True # Todo: implement detection
for iname, ivalue in nodeData['neighbours']['batadv'].items(): for iname, ivalue in nodeData['neighbours']['batadv'].items():
if 'neighbours' not in ivalue: if 'neighbours' not in ivalue:
continue continue
if iname in self.gatewayMacs:
nodeData['nodeinfo']['isGateway'] = True
if not iname in self.ifIDs: if not iname in self.ifIDs:
continue continue
for nname, nvalue in ivalue['neighbours'].items(): for nname, nvalue in ivalue['neighbours'].items():