def getRootMo(self): """Get the Root Mo for this configuration request Returns: None or cobra.mit.mo.Mo: The root Mo for the config request """ def addDescendantMo(rMo, descendantMo): rDn = rMo.dn descendantDn = descendantMo.dn parentDn = descendantDn.getParent() while rDn != parentDn: # This is a descendant. make the parent mo parentMo = ConfigRequest.__getMoForDnInFlatTree( parentDn, flatTreeDict) parentMo._attachChild(descendantMo) descendantMo = parentMo parentDn = parentDn.getParent() rMo._attachChild(descendantMo) if self.__rootMo: return self.__rootMo if not self.__configMos: return None # This dict stores all entries added to the tree. Fast lookups flatTreeDict = {} dns = list(self.__configMos.keys()) rootDn = Dn.findCommonParent(dns) configMos = dict(self.__configMos) # Check if the the root is in the list of MOs to be configure. # If it is there, remove it, else create a new MO, but in any case # add the MO to the flat tree dictionary for further lookups. rootMo = configMos.pop(rootDn) if rootDn in configMos else None rootMo = ConfigRequest.__getMoForDnInFlatTree(rootDn, flatTreeDict, rootMo) # Add the rest of the mos to the root. childMos = sorted(list(configMos.values()), key=lambda x: x.dn) for childMo in childMos: addDescendantMo(rootMo, childMo) self.__rootMo = rootMo return rootMo