Wokring on support for hopglass server (raw.json).
This commit is contained in:
parent
1a01718538
commit
cce68e8da6
|
@ -50,18 +50,10 @@ class NodeHierarchy(object):
|
||||||
|
|
||||||
def __createLinkObjects__(self):
|
def __createLinkObjects__(self):
|
||||||
links = []
|
links = []
|
||||||
for link in self.__hopglass.links:
|
for linkParID, linkPar in self.__hopglass.links.items():
|
||||||
try:
|
for linkID, link in linkPar.items():
|
||||||
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 = '')
|
print('Create Link object #',len(links), '\r',end = '')
|
||||||
links.append(Link(link, srcNode, dstNode))
|
links.append(Link(link, (self.nodes[linkParID[0]], self.nodes[linkParID[1]])))
|
||||||
print('')
|
print('')
|
||||||
return links
|
return links
|
||||||
|
|
||||||
|
|
|
@ -1,67 +1,29 @@
|
||||||
class Link(object):
|
class Link(object):
|
||||||
def __init__(self, LinkJsonObject, srcNode, dstNode):
|
def __init__(self, LinkJsonObject, nodes):
|
||||||
self.__jsonObject__ = LinkJsonObject
|
self.__jsonObject = LinkJsonObject
|
||||||
self.__srcNode__ = srcNode
|
self.linkType, self.isVpn = self.__getLinkType__()
|
||||||
self.__dstNode__ = dstNode
|
self.__nodes = nodes
|
||||||
self.linkType = self.__getLinkType__()
|
|
||||||
self.isVpn = self.__getLinkVpnState__()
|
|
||||||
|
|
||||||
|
|
||||||
def __getLinkType__(self):
|
def __getLinkType__(self):
|
||||||
type_src = None
|
types = [x['type'] for x in self.__jsonObject]
|
||||||
type_dst = None
|
ltype = types[0]
|
||||||
if self.__srcNode__ != None:
|
lvpn = False
|
||||||
for k, v in self.__srcNode__.interfaces.items():
|
for x in types:
|
||||||
if self.__jsonObject__['source']['interface_mac'] in v:
|
if x != 'unknown' and x != 'other':
|
||||||
type_src = k
|
if x == 'l2tp' or x == 'tunnel':
|
||||||
if self.__dstNode__ != None:
|
lvpn = True
|
||||||
for k, v in self.__dstNode__.interfaces.items():
|
val = x
|
||||||
if self.__jsonObject__['target']['interface_mac'] in v:
|
return ltype, lvpn
|
||||||
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
|
|
||||||
|
|
||||||
def getEndpointNodes(self, getGateways = False):
|
def getEndpointNodes(self, getGateways = False):
|
||||||
nodes = []
|
return self.__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
|
|
||||||
|
|
||||||
def getEndpointNodeIDs(self, getGateways = True):
|
def getEndpointNodeIDs(self, getGateways = True):
|
||||||
nodeIDs = []
|
return [x.nodeID for x in self.__nodes]
|
||||||
for node in self.getEndpointNodes(getGateways):
|
|
||||||
nodeIDs.append(node.nodeID)
|
|
||||||
return nodeIDs
|
|
||||||
|
|
||||||
def isNodeIDinLink(self, nodeID):
|
def isNodeIDinLink(self, nodeID):
|
||||||
for endpoint in self.getEndpointNodes():
|
for x in self.__nodes:
|
||||||
if endpoint.nodeID == nodeID:
|
if nodeID == x.nodeID:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -125,6 +125,9 @@ class LocalGraph(Graph):
|
||||||
print('BranchesThatExistsInCloud:', self.getBranchesThatExistsInCloud())
|
print('BranchesThatExistsInCloud:', self.getBranchesThatExistsInCloud())
|
||||||
print('lan links in cloud:')
|
print('lan links in cloud:')
|
||||||
for link in self.getLanLinksInCloud():
|
for link in self.getLanLinksInCloud():
|
||||||
if link.__srcNode__ != None and link.__dstNode__ != None:
|
hosts = link.getEndpointNodes()
|
||||||
print(' ', link.__srcNode__.hostname, '<--->', link.__dstNode__.hostname)
|
if len(hosts) == 1:
|
||||||
|
print(' ', hosts.hostname, 'has unknown neighbour.')
|
||||||
|
else:
|
||||||
|
print(' ', hosts[0].hostname, '<--->', hosts[1].hostname)
|
||||||
print('=====')
|
print('=====')
|
||||||
|
|
|
@ -12,8 +12,8 @@ class Hopglass(JsonParser):
|
||||||
self.gateways = []
|
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():
|
||||||
print(k,v,'\n')
|
# print(k,v,'\n')
|
||||||
|
|
||||||
def __aggregateData__(self):
|
def __aggregateData__(self):
|
||||||
for nodeID, nodeData in self.__jsonData__.items():
|
for nodeID, nodeData in self.__jsonData__.items():
|
||||||
|
|
Loading…
Reference in a new issue