Exemplo n.º 1
0
    def opget(self, index, selector):
        if not index in self.views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return {'Status': 'Success', 'Message': 'Not supported'}
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) +
                     "...")
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid,
                                              clsName)
        else:
            retval = self.proto.opget(self.views[index], clsName, selector)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr, self.enumid, clsName,
                                       retval)
        if not 'Data' in retval or retval['Data'] is None:
            return retval

        counter = 0
        for i in retval['Data']:
            counter = counter + 1
            retval['Data'][clsName] = retval['Data'][i]
            del retval['Data'][i]
            if counter <= 1:
                break
        return retval
Exemplo n.º 2
0
    def _enumerate_view(self, index, views, bTrue):
        if not index in views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return {'Status': 'Success', 'Message': 'Not supported'}
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) + "...")
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid, clsName)
        else:
            # Changed True to False for having single session
            wsprof = views[index]
            filter = None
            if isinstance(views[index], list) and self.enumid == ProtocolEnum.WSMAN:
                wsprof = views[index][0]
                filter = views[index][1]
            retval = self.proto.enumerate(clsName, wsprof, self.selectors, False, filter)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr, self.enumid, clsName, retval)
        if not 'Data' in retval or retval['Data'] is None or len(retval['Data']) <= 0:
            return retval
        if index in self.classifier_cond:
            chk_func = self.classifier_cond[index].get(self.enumid, None)
            if chk_func:
                (valid, flist) = chk_func(retval['Data'][clsName], clsName)
                if valid:
                    retval['Data'][clsName] = flist
                else:
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier condition not satisfied'
                    }
        if index in self.classifier:
            for attr in self.classifier[index]:
                if not clsName in retval['Data']:
                    return {
                        'Status': 'Failed',
                        'Message': clsName + ' instance is not found!'
                    }
                if not attr in retval['Data'][clsName]:
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier attribute not found!'
                    }
                if not re.search(self.classifier[index][attr],
                                 retval['Data'][clsName][attr]):
                    return {
                        'Status': 'Failed',
                        'Message': 'Classifier did not match!'
                    }

        for en in self.view_fieldspec:
            if en != index:
                continue
            for retobj in retval['Data']:
                if isinstance(retval['Data'][retobj], dict):
                    self._apply_spec(retval['Data'][retobj], en)
                else:
                    for i in retval['Data'][retobj]:
                        self._apply_spec(i, en)
        return retval
Exemplo n.º 3
0
    def _enumerate_view(self, index, views, bTrue):
        if not index in views:
            logger.debug("WARN: no " + str(index) + " for " + str(self.enumid))
            return { 'Status' : 'Success', 'Message' : 'Not supported' }
        clsName = TypeHelper.resolve(index)
        logger.debug("Collecting " + clsName + " ... via " + str(self.enumid) + "..." )
        if Simulator.is_simulating():
            retval = Simulator.simulate_proto(self.ipaddr, self.enumid, clsName)
        else:
            retval = self.proto.enumerate(clsName, views[index], self.selectors, True)
            if Simulator.is_recording():
                Simulator.record_proto(self.ipaddr,self.enumid, clsName, retval)
        if not 'Data' in retval or retval['Data'] is None:
            return retval
        if index in self.classifier:
            for attr in self.classifier[index]:
                if not clsName in retval['Data']:
                    return {
                        'Status' : 'Failed',
                        'Message': clsName + ' instance is not found!'
                    }
                if not attr in retval['Data'][clsName]:
                    return {
                        'Status' : 'Failed',
                        'Message': 'Classifier attribute not found!'
                    }
                if not re.search(self.classifier[index][attr],
                           retval['Data'][clsName][attr]):
                    return {
                        'Status' : 'Failed',
                        'Message': 'Classifier did not match!'
                    }

        for en in self.view_fieldspec:
            if en != index:
                continue
            for retobj in retval['Data']:
                if isinstance(retval['Data'][retobj], dict):
                    self._apply_spec(retval['Data'][retobj], en)
                else:                        
                    for i in retval['Data'][retobj]:
                        self._apply_spec(i, en)
        return retval