def __reduceComponentList(self, componentList): """ Only keep the most restrictive components """ for i in range(len(componentList)): component = componentList[i] for j in range(len(componentList)): if i == j or componentList[j] == False: continue potentiallyMoreRestrictiveComponent = componentList[j] match = True for key in component: if key not in potentiallyMoreRestrictiveComponent: match = False break if key == 'Host': result = Network.checkHostsMatch( component[key], potentiallyMoreRestrictiveComponent[key]) if not result['OK'] or not result['Value']: match = False break else: if component[ key] != potentiallyMoreRestrictiveComponent[ key]: match = False break if match: componentList[i] = False break return [comp for comp in componentList if comp != False]
def __reduceComponentList( self, componentList ): """ Only keep the most restrictive components """ for i in range( len( componentList ) ): component = componentList[i] for j in range( len( componentList ) ): if i == j or componentList[j] == False : continue potentiallyMoreRestrictiveComponent = componentList[j] match = True for key in component: if key not in potentiallyMoreRestrictiveComponent: match = False break if key == 'Host': result = Network.checkHostsMatch( component[key], potentiallyMoreRestrictiveComponent[key] ) if not result[ 'OK' ] or not result[ 'Value' ]: match = False break else: if component[key] != potentiallyMoreRestrictiveComponent[key]: match = False break if match: componentList[i] = False break return [ comp for comp in componentList if comp != False ]
def __reduceComponentList(self, componentList): """ Only keep the most restrictive components. :type componentList: list :param componentList: A list of components. :return: A list of reduced components. """ for i in range(len(componentList)): component = componentList[i] for j in range(len(componentList)): if i == j or componentList[j] is False: continue potentiallyMoreRestrictiveComponent = componentList[j] match = True for key in component: if key not in potentiallyMoreRestrictiveComponent: match = False break if key == "Host": result = Network.checkHostsMatch(component[key], potentiallyMoreRestrictiveComponent[key]) if not result["OK"] or not result["Value"]: match = False break else: if component[key] != potentiallyMoreRestrictiveComponent[key]: match = False break if match: componentList[i] = False break return [comp for comp in componentList if comp]
def __addFoundDefinedComponent(self, compDictList): cD = self.walkSet(self.__requiredSet, compDictList[0]) dbD = self.walkSet(self.__dbSet, compDictList[0]) now = datetime.datetime.utcnow() unmatched = compDictList for dbComp in dbD: if "Status" not in dbComp: self.__setStatus(dbComp, "OK") if dbComp["Type"] == "service": if "Port" not in dbComp: self.__setStatus(dbComp, "Error", "Port is not defined") elif dbComp["Port"] not in [ compDict["Port"] for compDict in compDictList if "Port" in compDict ]: self.__setStatus( compDictList[-1], "Error", "Port (%s) is different that specified in the CS" % dbComp["Port"], ) elapsed = now - dbComp["LastHeartbeat"] elapsed = elapsed.days * 86400 + elapsed.seconds if elapsed > self.__maxSecsSinceHeartbeat: self.__setStatus( dbComp, "Error", "Last heartbeat was received at %s (%s secs ago)" % (dbComp["LastHeartbeat"], elapsed), ) cD.append(dbComp) # See if we have a perfect match newUnmatched = [] for unmatchedComp in unmatched: perfectMatch = True for field in unmatchedComp: if field in ("Status", "Message"): continue if field not in dbComp: perfectMatch = False continue if field == "Host": result = Network.checkHostsMatch( unmatchedComp[field], dbComp[field]) if not result["OK"] or not result["Value"]: perfectMatch = False else: if unmatchedComp[field] != dbComp[field]: perfectMatch = False if not perfectMatch: newUnmatched.append(unmatchedComp) unmatched = newUnmatched for unmatchedComp in unmatched: self.__setStatus(unmatchedComp, "Error", "There is no component up with this properties") cD.append(unmatchedComp)
def __addFoundDefinedComponent(self, compDictList): cD = self.walkSet(self.__requiredSet, compDictList[0]) dbD = self.walkSet(self.__dbSet, compDictList[0]) now = Time.dateTime() unmatched = compDictList for dbComp in dbD: if 'Status' not in dbComp: self.__setStatus(dbComp, 'OK') if dbComp['Type'] == "service": if 'Port' not in dbComp: self.__setStatus(dbComp, 'Error', "Port is not defined") elif dbComp['Port'] not in [ compDict['Port'] for compDict in compDictList if 'Port' in compDict ]: self.__setStatus( compDict, 'Error', "Port (%s) is different that specified in the CS" % dbComp['Port']) elapsed = now - dbComp['LastHeartbeat'] elapsed = elapsed.days * 86400 + elapsed.seconds if elapsed > self.__maxSecsSinceHeartbeat: self.__setStatus( dbComp, "Error", "Last heartbeat was received at %s (%s secs ago)" % (dbComp['LastHeartbeat'], elapsed)) cD.append(dbComp) #See if we have a perfect match newUnmatched = [] for unmatchedComp in unmatched: perfectMatch = True for field in unmatchedComp: if field in ('Status', 'Message'): continue if field not in dbComp: perfectMatch = False continue if field == 'Host': result = Network.checkHostsMatch( unmatchedComp[field], dbComp[field]) if not result['OK'] or not result['Value']: perfectMatch = False else: if unmatchedComp[field] != dbComp[field]: perfectMatch = False if not perfectMatch: newUnmatched.append(unmatchedComp) unmatched = newUnmatched for unmatchedComp in unmatched: self.__setStatus(unmatchedComp, "Error", "There is no component up with this properties") cD.append(unmatchedComp)
def __addFoundDefinedComponent( self, compDictList ): cD = self.walkSet( self.__requiredSet, compDictList[0] ) dbD = self.walkSet( self.__dbSet, compDictList[0] ) now = Time.dateTime() unmatched = compDictList for dbComp in dbD: if 'Status' not in dbComp: self.__setStatus( dbComp, 'OK' ) if dbComp[ 'Type' ] == "service": if 'Port' not in dbComp: self.__setStatus( dbComp, 'Error', "Port is not defined" ) elif dbComp[ 'Port' ] not in [ compDict[ 'Port' ] for compDict in compDictList if 'Port' in compDict ]: self.__setStatus( compDict, 'Error', "Port (%s) is different that specified in the CS" % dbComp[ 'Port' ] ) elapsed = now - dbComp[ 'LastHeartbeat' ] elapsed = elapsed.days * 86400 + elapsed.seconds if elapsed > self.__maxSecsSinceHeartbeat: self.__setStatus( dbComp, "Error", "Last heartbeat was received at %s (%s secs ago)" % ( dbComp[ 'LastHeartbeat' ], elapsed ) ) cD.append( dbComp ) #See if we have a perfect match newUnmatched = [] for unmatchedComp in unmatched: perfectMatch = True for field in unmatchedComp: if field in ( 'Status', 'Message' ): continue if field not in dbComp: perfectMatch = False continue if field == 'Host': result = Network.checkHostsMatch( unmatchedComp[ field ], dbComp[ field ] ) if not result[ 'OK' ] or not result[ 'Value' ]: perfectMatch = False else: if unmatchedComp[ field ] != dbComp[ field ]: perfectMatch = False if not perfectMatch: newUnmatched.append( unmatchedComp ) unmatched = newUnmatched for unmatchedComp in unmatched: self.__setStatus( unmatchedComp, "Error", "There is no component up with this properties" ) cD.append( unmatchedComp )