def addLink(self, link): """adds a link to the graph""" (node1, node2) = link.getNodes() linkName = link.getName() # adds the link into the graph self.add_edge(node1.getName(), node2.getName(), key=linkName, obj=link) self.createLinkLabels() # creates new labels for links
def addLink(self, link): """adds a link to the graph""" (node1, node2) = link.getNodes() linkName = link.getName() # adds the link into the graph self.add_edge(node1.getName(), node2.getName(), key = linkName, obj = link) self.createLinkLabels() # creates new labels for links
def removeLink(self, linkName): """removes a link from the graph""" for linkData in self.edges(data=True): link = linkData[2]['obj'] if link.getName() == linkName: # finds the correct link (node1, node2) = link.getNodes() # removes the link from the graph self.remove_edge(node1.getName(), node2.getName()) self.createLinkLabels() # creates the new link labels return
def removeLink(self, linkName): """removes a link from the graph""" for linkData in self.edges(data = True): link = linkData[2]['obj'] if link.getName() == linkName: # finds the correct link (node1, node2) = link.getNodes() # removes the link from the graph self.remove_edge(node1.getName(), node2.getName()) self.createLinkLabels() # creates the new link labels return
def displayLink(self): """creates a graphical dialog to select an edge and display its information""" currEdges = self.graph.edges(data = True) link, ok = dialogs.DisplayLink.getDataDialog(currEdges) if ok: # gets the user selected edge (node1, node2) = link.getNodes() nodeName1 = node1.getName() nodeName2 = node2.getName() protocol = link.getProtocol() risk = link.getRisk() # display the data for the edge in a message box message = QtGui.QMessageBox.information(self, "View Edge", "Name: {0}\nNode 1: {1}\nNode 2: {2}\nProtocol: {3}\nRisk: {4}".format(link.getName(), nodeName1, nodeName2, protocol, risk))
def getNewLink(self): """creates a graphical dialog to create a new edge and ensures that the edge is between two compatible nodes""" currNodes = self.graph.nodes(data = True) if len(currNodes) < 2: # ensures that 2 or more nodes are present in order ot make an edge message = QtGui.QMessageBox.warning(self, "Black Hat Risk", "Not enough nodes to create an edge!") return link, ok = dialogs.AddLink.getDataDialog(currNodes) if ok: (n1, n2) = link.getNodes() proto = link.getProtocol() if self.checkLinkCompat(n1, n2, proto): # checks compatability of the nodes and protocol and adds the edge if possible self.addLink(link) else: message = QtGui.QMessageBox.warning(self, "Black Hat Risk", "Incompatible Link between storage devices!")
def createLinkLabels(self): """creates the labels for all links in the graph""" links = self.edges(data=True) # get all links self._linkLabels = {} # clear the link lables for linkData in links: # get all data for the link link = linkData[2]['obj'] linkName = link.getName() (node1, node2) = link.getNodes() node1Name = node1.getName() node2Name = node2.getName() # creates the link labels ensuring that multiple can be listed # to account for multiple links between a single node if (node1Name, node2Name) in self._linkLabels.keys(): self._linkLabels[(node1Name, node2Name)] += ",\n" + linkName elif (node2Name, node1Name) in self._linkLabels.keys(): self._linkLabels[(node2Name, node1Name)] += ",\n" + linkName else: self._linkLabels[(node1Name, node2Name)] = linkName
def createLinkLabels(self): """creates the labels for all links in the graph""" links = self.edges(data = True) # get all links self._linkLabels = {} # clear the link lables for linkData in links: # get all data for the link link = linkData[2]['obj'] linkName = link.getName() (node1, node2) = link.getNodes() node1Name = node1.getName() node2Name = node2.getName() # creates the link labels ensuring that multiple can be listed # to account for multiple links between a single node if (node1Name, node2Name) in self._linkLabels.keys(): self._linkLabels[(node1Name, node2Name)] += ",\n" + linkName elif (node2Name, node1Name) in self._linkLabels.keys(): self._linkLabels[(node2Name, node1Name)] += ",\n" + linkName else: self._linkLabels[(node1Name, node2Name)] = linkName