def buildNeblockTrees(self): tmpArray = [] allObjects = self.levelDisplayObjects; allEffectiveObjects = {}; self.loadBalancerLineIndex = -1; self.instanceLineIndex = -1; self.volumeLineIndex = -1; self.gridColCount = 0 self.gridLineCount = 0 for aFilter in self.filterArray: if aFilter.has_key('vpc_id'): self.vpcuuid = aFilter['vpc_id']; tmpVPC = self.levelDisplayObjects[self.vpcuuid]; modelLogicalRootNode = nep_tree_logical.nepLogicalNode(self.logicalRootUUID); tmpArray.append(modelLogicalRootNode); for idx in range(len(self.levelDisplayIdentifiers) -1): for anObjectUUID in self.levelDisplayObjects.keys(): anObject = self.levelDisplayObjects[anObjectUUID]; if anObject['__class_name'] == 'connection': continue if False == anObject.has_key("logical_level"): continue; if anObject["logical_level"] == idx: aNode = nep_tree_logical.nepLogicalNode(anObjectUUID) if anObject['__class_name'] == 'zone': if anObject['region'] == tmpVPC['region']: modelLogicalRootNode.addChild(aNode) elif anObject['__class_name'] == 'subnet': for pNode in tmpArray: if anObject.has_key('zones') and len(anObject['zones']) > 0: if pNode.representedObject == anObject['zones'][0]: pNode.addChild(aNode); break; elif anObject['__class_name'] == 'volume' or anObject['__class_name'] == 'load_balancer' or anObject['__class_name'] == 'instance' or anObject['__class_name'] == 'database': if '.ec2classic' in self.vpcuuid: for pNode in tmpArray: pass #TOTO implement stuff else: for pNode in tmpArray: if pNode.representedObject == self.levelDisplayObjects[anObjectUUID]["subnet_id"]: pNode.addChild(aNode) tmpArray.append(aNode) self.modelLogicalRootNode = modelLogicalRootNode
def buildTrees(self, vpcID = 'vpc.all', filter = None): """ Build both the logical and graphical tree for a given VPC and filter. Pass vpc.all for all information with no VPC and vpc.classic for the "No VPC" part """ #TODO add code to delete the tree if it already exists as well as the self.modelGraphItemsDatabase print "buildTrees" print vpcID objectsToUse = None if vpcID == 'vpc.all': #compute without taking in account VPC objectsToUse = self.levelDisplayObjects tmpArray = [] modelLogicalRootNode = nep_tree_logical.nepLogicalNode(self.logicalRootUUID); for idx in range(len(self.levelDisplayIdentifiers)): for anObjectUUID in self.levelDisplayObjects.keys(): if self.levelDisplayObjects[anObjectUUID].has_key('logical_level'): # print anObjectUUID+ " " + str(self.levelDisplayObjects[anObjectUUID]["logical_level"]) if self.levelDisplayObjects[anObjectUUID]["logical_level"] == idx: aNode = nep_tree_logical.nepLogicalNode(anObjectUUID) if self.levelDisplayObjects[anObjectUUID].has_key('logical_parent') == False: modelLogicalRootNode.addChild(aNode) else: for oneNode in tmpArray: if oneNode.representedObject == self.levelDisplayObjects[anObjectUUID]['logical_parent']: oneNode.addChild(aNode) tmpArray.append(aNode) self.modelLogicalRootNode = modelLogicalRootNode elif vpcID == 'vpc.classic': #TODO all in the "non vpc land" self.modelLogicalRootNode = None else: #TODO all in the "non vpc land" self.modelLogicalRootNode = None # Now we build the graphical tree if self.modelLogicalRootNode != None: self.modelGraphItemsDatabase["root:"+self.logicalRootUUID] = nep_tree_graphical.nepGraphicalNode("root:"+self.logicalRootUUID,-1); self.modelGraphicalRootNode = self.modelGraphItemsDatabase["root:"+self.logicalRootUUID] # this help does the full job of linking a graph parent to a child, creating the items # and putting the links def _helperEstablishRelationShipParentToChild(graphParentUUID,graphChildUUID): if False == self.modelGraphItemsDatabase.has_key(graphParentUUID): self.modelGraphItemsDatabase[graphParentUUID] = nep_tree_graphical.nepGraphicalNode(graphParentUUID,0) if False == self.modelGraphItemsDatabase.has_key(graphChildUUID): self.modelGraphItemsDatabase[graphChildUUID] = nep_tree_graphical.nepGraphicalNode(graphChildUUID,0) parentItem = self.modelGraphItemsDatabase[graphParentUUID] childItem =self.modelGraphItemsDatabase[graphChildUUID] graphlinkUUUID = "link::"+graphParentUUID+"::"+graphChildUUID if False == self.modelGraphItemsDatabase.has_key(graphlinkUUUID): self.modelGraphItemsDatabase[graphlinkUUUID] = nep_tree_graphical.nepGraphicalNode(graphlinkUUUID,0) linkItem = self.modelGraphItemsDatabase[graphlinkUUUID] linkItem.graphItemLevel = parentItem.graphItemLevel+0.5 childItem.graphItemLevel = parentItem.graphItemLevel+1.0 parentItem.addSubUUID(graphChildUUID) parentItem.addLinkUUID(graphlinkUUUID) childItem.addSuperUUID(graphParentUUID) childItem.addLinkUUID(graphlinkUUUID) linkItem.addNodeUUID(graphChildUUID) linkItem.addNodeUUID(graphParentUUID) # this is the call back used to build the graphical tree when parsing/traversing the logical def _buildGraphTreeForNode(node): graphicalUUID = ("root:"+node.representedObject) if (node == modelLogicalRootNode) else ("item:"+node.representedObject) subLevelRepartition = {}; for aLogicalChildNode in node.childrenNodes: tmpIndex = self.levelDisplayObjects[aLogicalChildNode.representedObject]['logical_level'] if False == subLevelRepartition.has_key(tmpIndex): subLevelRepartition[tmpIndex] = [] subLevelRepartition[tmpIndex].append(aLogicalChildNode.representedObject) for aLevelKey in subLevelRepartition.keys(): levelElements = subLevelRepartition[aLevelKey] if 1 == len(levelElements): childItemGraphicalUUID = "item:"+levelElements[0]; _helperEstablishRelationShipParentToChild(graphicalUUID, childItemGraphicalUUID) else: childGroupGraphicalUUID = "group:"+node.representedObject+":"+str(aLevelKey) _helperEstablishRelationShipParentToChild(graphicalUUID, childGroupGraphicalUUID) childMultiGraphicalUUID = "multi:"+node.representedObject+":"+str(aLevelKey) _helperEstablishRelationShipParentToChild(graphicalUUID, childMultiGraphicalUUID) for anLevelElement in levelElements: subChildGRaphUUID = "item:"+anLevelElement; _helperEstablishRelationShipParentToChild(childGroupGraphicalUUID, subChildGRaphUUID); _helperEstablishRelationShipParentToChild(childMultiGraphicalUUID, subChildGRaphUUID); #build the graphical tree self.modelLogicalRootNode.trasverse(_buildGraphTreeForNode)