node_hierarchy/cloud/Link.py

32 lines
957 B
Python
Raw Permalink Normal View History

2016-05-29 18:56:50 +02:00
class Link(object):
def __init__(self, LinkJsonObject, nodes):
self.__jsonObject = LinkJsonObject
self.linkType, self.isVpn = self.__getLinkType__()
self.__nodes = nodes
2016-05-29 18:56:50 +02:00
def __getLinkType__(self):
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
2016-05-29 18:56:50 +02:00
def getEndpointNodes(self, getGateways = False):
return self.__nodes
2016-05-29 18:56:50 +02:00
def getEndpointNodeIDs(self, getGateways = True):
return [x.nodeID for x in self.__nodes]
2016-05-29 18:56:50 +02:00
def isNodeIDinLink(self, nodeID):
for x in self.__nodes:
if nodeID == x.nodeID:
2016-05-29 18:56:50 +02:00
return True
return False
2016-05-29 18:56:50 +02:00
def isNodeInLink(self, node):
return self.isNodeIDinLink(node.nodeID)