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

This commit is contained in:
Simon Wüllhorst 2017-04-24 11:13:00 +02:00
parent 1a01718538
commit cce68e8da6
4 changed files with 34 additions and 77 deletions

View file

@ -50,18 +50,10 @@ class NodeHierarchy(object):
def __createLinkObjects__(self):
links = []
for link in self.__hopglass.links:
try:
srcNode = self.nodes[link['source']['node_id']]
except:
srcNode = None
try:
dstNode = self.nodes[link['target']['node_id']]
except:
dstNode = None
print('Create Link object #',len(links), '\r',end = '')
links.append(Link(link, srcNode, dstNode))
for linkParID, linkPar in self.__hopglass.links.items():
for linkID, link in linkPar.items():
print('Create Link object #',len(links), '\r',end = '')
links.append(Link(link, (self.nodes[linkParID[0]], self.nodes[linkParID[1]])))
print('')
return links

View file

@ -1,69 +1,31 @@
class Link(object):
def __init__(self, LinkJsonObject, srcNode, dstNode):
self.__jsonObject__ = LinkJsonObject
self.__srcNode__ = srcNode
self.__dstNode__ = dstNode
self.linkType = self.__getLinkType__()
self.isVpn = self.__getLinkVpnState__()
def __init__(self, LinkJsonObject, nodes):
self.__jsonObject = LinkJsonObject
self.linkType, self.isVpn = self.__getLinkType__()
self.__nodes = nodes
def __getLinkType__(self):
type_src = None
type_dst = None
if self.__srcNode__ != None:
for k, v in self.__srcNode__.interfaces.items():
if self.__jsonObject__['source']['interface_mac'] in v:
type_src = k
if self.__dstNode__ != None:
for k, v in self.__dstNode__.interfaces.items():
if self.__jsonObject__['target']['interface_mac'] in v:
type_dst = k
if type_src == type_dst:
if type_src == None:
return 'unknown'
return type_src
else:
if type_src == None:
return type_dst
elif type_dst == None:
return type_src
else:
#print(self.__srcNode__.hostname, type_src, '<-->', self.__dstNode__.hostname, type_dst)
if type_src == 'wireless':
return type_dst
else:
return type_src
def __getLinkVpnState__(self):
if self.__jsonObject__['vpn'] == True:
return True
for node in self.getEndpointNodes(getGateways = True):
if node.isGateway == True:
return True
return False
types = [x['type'] for x in self.__jsonObject]
ltype = types[0]
lvpn = False
for x in types:
if x != 'unknown' and x != 'other':
if x == 'l2tp' or x == 'tunnel':
lvpn = True
val = x
return ltype, lvpn
def getEndpointNodes(self, getGateways = False):
nodes = []
if self.__srcNode__ != None:
if getGateways == True or self.__srcNode__.isGateway == False:
nodes.append(self.__srcNode__)
if self.__dstNode__ != None:
if getGateways == True or self.__dstNode__.isGateway == False:
nodes.append(self.__dstNode__)
return nodes
return self.__nodes
def getEndpointNodeIDs(self, getGateways = True):
nodeIDs = []
for node in self.getEndpointNodes(getGateways):
nodeIDs.append(node.nodeID)
return nodeIDs
return [x.nodeID for x in self.__nodes]
def isNodeIDinLink(self, nodeID):
for endpoint in self.getEndpointNodes():
if endpoint.nodeID == nodeID:
for x in self.__nodes:
if nodeID == x.nodeID:
return True
return False
def isNodeInLink(self, node):
return self.isNodeIDinLink(node.nodeID)

View file

@ -125,6 +125,9 @@ class LocalGraph(Graph):
print('BranchesThatExistsInCloud:', self.getBranchesThatExistsInCloud())
print('lan links in cloud:')
for link in self.getLanLinksInCloud():
if link.__srcNode__ != None and link.__dstNode__ != None:
print(' ', link.__srcNode__.hostname, '<--->', link.__dstNode__.hostname)
hosts = link.getEndpointNodes()
if len(hosts) == 1:
print(' ', hosts.hostname, 'has unknown neighbour.')
else:
print(' ', hosts[0].hostname, '<--->', hosts[1].hostname)
print('=====')

View file

@ -11,9 +11,9 @@ class Hopglass(JsonParser):
self.gatewayMacs = []
self.gateways = []
self.__aggregateData__()
#print(self.ifIDs)
for k, v in self.links.items():
print(k,v,'\n')
# print(self.ifIDs)
# for k, v in self.links.items():
# print(k,v,'\n')
def __aggregateData__(self):
for nodeID, nodeData in self.__jsonData__.items():