def _replyToQuery(self, ctx, query, bool = None): raise "DON'T USE _replyToQuery!!!" ret = self.__recursive_query(ctx, query) values = {} values_neg = {} # TODO does not seems to work... #['AND', [['1', 'dyngroup', 'groupname', 'test']]] for qid, module, criterion, value in query: val, neg = self._getPluginReplyToQuery( ctx, self.queryablePlugins[module], [criterion, value] ) values[str(qid)] = [val, neg] self.logger.debug(values) br = BoolRequest() if bool == None or bool == '' or bool == 0 or bool == '0': bool = 'AND('+','.join(map(lambda a:a[0][0], values))+')' all = ComputerManager().getComputersList(ctx) #all = ComputerManager().getRestrictedComputersList(ctx, 0, 50) # for the moment everything is based on names... should be changed into uuids #all = map(lambda a: a[1]['cn'][0], all.values()) all = all.keys() values['A'] = [all, True] bool = 'AND(A, '+bool+')' br.parse(bool) if bool == None or not br.isValid(): # no bool specified = only AND if len(values.keys()) > 0: retour = values.pop() for val in values: neg = val[1] val = val[0] if neg: retour = filter(lambda a,val=val:a in val, retour) else: retour = filter(lambda a,val=val:a not in val, retour) return retour else: return [] # TODO : when plugged on Machines : should return : Machine - values_neg else: retour = br.merge(values) return retour[0]
def _replyToQueryXML(self, ctx, query, bool = None): values = {} values_neg = {} for qid, module, criterion, value in query: val, neg = self._getPluginReplyToQuery( ctx, self.queryablePlugins[module], [criterion, value] ) values[str(qid)] = [val, neg] self.logger.debug(values) br = BoolRequest() if bool == None or bool == '': bool = "<AND><p>"+('</p><p>'.join(map(lambda a:a[0][0], values)))+"</p></AND>" all = ComputerManager().getComputersList(ctx) # for the moment everything is based on names... should be changed into uuids all = map(lambda a: a[1]['cn'][0], all) values['A'] = [all, True] bool = '<AND><p>A</p><p>'+bool+'</p></AND>' br.parseXML(bool) if bool == None or not br.isValid(): # no bool specified = only AND if len(values.keys()) > 0: retour = values.pop() for val in values: neg = val[1] val = val[0] if neg: retour = filter(lambda a,val=val:a in val, retour) else: retour = filter(lambda a,val=val:a not in val, retour) return retour else: return [] # TODO : when plugged on Machines : should return : Machine - values_neg else: retour = br.merge(values) return retour[0]
def _replyToQuery(self, ctx, query, bool = None): raise "DON'T USE _replyToQuery!!!" self.__recursive_query(ctx, query) values = {} # TODO does not seems to work... #['AND', [['1', 'dyngroup', 'groupname', 'test']]] for qid, module, criterion, value in query: val, neg = self._getPluginReplyToQuery( ctx, self.queryablePlugins[module], [criterion, value] ) values[str(qid)] = [val, neg] self.logger.debug(values) br = BoolRequest() if bool == None or bool == '' or bool == 0 or bool == '0': bool = 'AND('+','.join(map(lambda a:a[0][0], values))+')' all = ComputerManager().getComputersList(ctx) #all = ComputerManager().getRestrictedComputersList(ctx, 0, 50) # for the moment everything is based on names... should be changed into uuids #all = map(lambda a: a[1]['cn'][0], all.values()) all = all.keys() values['A'] = [all, True] bool = 'AND(A, '+bool+')' br.parse(bool) if bool == None or not br.isValid(): # no bool specified = only AND if len(values.keys()) > 0: retour = values.pop() for val in values: neg = val[1] val = val[0] if neg: retour = filter(lambda a,val=val:a in val, retour) else: retour = filter(lambda a,val=val:a not in val, retour) return retour else: return [] # TODO : when plugged on Machines : should return : Machine - values_neg else: retour = br.merge(values) return retour[0]
def getQueryTree(self, query, bool = None): if type(query) != list: query = self.parse(query) values = {} for qid, module, criterion, value in query: values[str(qid)] = [qid, module, criterion, value] br = BoolRequest() if bool == None or bool == '' or bool == 0 or bool == '0': # no bool specified = only AND bool = 'AND('+','.join(map(lambda a:a, values))+')' br.parse(bool) if not br.isValid(): # invalid bool specified = only AND bool = 'AND('+','.join(map(lambda a:a, values))+')' br.parse(bool) try: return br.getTree(values) except KeyError: self.logger.error("Your boolean equation does not match your request (if you are using a group please check it's correct)") return None
def _replyToQueryXML(self, ctx, query, bool = None): values = {} for qid, module, criterion, value in query: val, neg = self._getPluginReplyToQuery( ctx, self.queryablePlugins[module], [criterion, value] ) values[str(qid)] = [val, neg] self.logger.debug(values) br = BoolRequest() if bool == None or bool == '': bool = "<AND><p>"+('</p><p>'.join(map(lambda a:a[0][0], values)))+"</p></AND>" all = ComputerManager().getComputersList(ctx) # for the moment everything is based on names... should be changed into uuids all = map(lambda a: a[1]['cn'][0], all) values['A'] = [all, True] bool = '<AND><p>A</p><p>'+bool+'</p></AND>' br.parseXML(bool) if bool == None or not br.isValid(): # no bool specified = only AND if len(values.keys()) > 0: retour = values.pop() for val in values: neg = val[1] val = val[0] if neg: retour = filter(lambda a,val=val:a in val, retour) else: retour = filter(lambda a,val=val:a not in val, retour) return retour else: return [] # TODO : when plugged on Machines : should return : Machine - values_neg else: retour = br.merge(values) return retour[0]