コード例 #1
0
ファイル: xhr.py プロジェクト: AlfredArouna/NIPAP
    def smart_search_vrf(self):
        """ Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.
        """

        search_options = {}
        extra_query = None

        if 'query_id' in request.params:
            search_options['query_id'] = request.params['query_id']

        if 'max_result' in request.params:
            search_options['max_result'] = request.params['max_result']

        if 'offset' in request.params:
            search_options['offset'] = request.params['offset']

        if 'vrf_id' in request.params:
            extra_query = {
                    'val1': 'id',
                    'operator': 'equals',
                    'val2': request.params['vrf_id']
                }

        try:
            result = VRF.smart_search(request.params['query_string'],
                search_options, extra_query
                )
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
コード例 #2
0
    def search_vrf(self, rt):
        """
        This method wildcard searches a vrf, for example seaching for
        209:123 will return 209:123, 209:123xxxx
        :param rt:
        :return: a vrf instance
        """
        try:
            retVal = VRF.smart_search(rt)
        except:
            logging.debug("Exception search for vrf {0}".format(rt))
            retVal = None

        return retVal
コード例 #3
0
    def smart_search_vrf(self):
        """ Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.
        """

        search_options = {}
        extra_query = None

        if 'query_id' in request.json:
            search_options['query_id'] = request.json['query_id']

        if 'max_result' in request.json:
            search_options['max_result'] = request.json['max_result']

        if 'offset' in request.json:
            search_options['offset'] = request.json['offset']

        if 'vrf_id' in request.json:
            extra_query = {
                'val1': 'id',
                'operator': 'equals',
                'val2': request.json['vrf_id']
            }

        try:
            result = VRF.smart_search(request.json['query_string'],
                                      search_options, extra_query)
            # Remove error key in result from backend as it interferes with the
            # error handling of the web interface.
            # TODO: Reevaluate how to deal with different types of errors; soft
            # errors like query string parser errors and hard errors like lost
            # database.
            del result['error']
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
コード例 #4
0
ファイル: xhr.py プロジェクト: fredsod/NIPAP
    def smart_search_vrf(self):
        """ Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.
        """

        search_options = {}
        extra_query = None

        if 'query_id' in request.json:
            search_options['query_id'] = request.json['query_id']

        if 'max_result' in request.json:
            search_options['max_result'] = request.json['max_result']

        if 'offset' in request.json:
            search_options['offset'] = request.json['offset']

        if 'vrf_id' in request.json:
            extra_query = {
                    'val1': 'id',
                    'operator': 'equals',
                    'val2': request.json['vrf_id']
                }

        try:
            result = VRF.smart_search(request.json['query_string'],
                search_options, extra_query
                )
            # Remove error key in result from backend as it interferes with the
            # error handling of the web interface.
            # TODO: Reevaluate how to deal with different types of errors; soft
            # errors like query string parser errors and hard errors like lost
            # database.
            del result['error']
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})
コード例 #5
0
    def smart_search_vrf(self):
        """ Perform a smart VRF search.

            The "smart" search function tries extract a query from
            a text string. This query is then passed to the search_vrf
            function, which performs the search.
        """

        search_options = {}
        extra_query = None

        if 'query_id' in request.params:
            search_options['query_id'] = request.params['query_id']

        if 'max_result' in request.params:
            search_options['max_result'] = request.params['max_result']

        if 'offset' in request.params:
            search_options['offset'] = request.params['offset']

        if 'vrf_id' in request.params:
            extra_query = {
                'val1': 'id',
                'operator': 'equals',
                'val2': request.params['vrf_id']
            }

        try:
            result = VRF.smart_search(request.params['query_string'],
                                      search_options, extra_query)
        except NipapError, e:
            return json.dumps({
                'error': 1,
                'message': e.args,
                'type': type(e).__name__
            })
コード例 #6
0
ファイル: nipap-ro.py プロジェクト: scoffers/NIPAPP
 def test_smart_search_vrf(self):
     """ We should be able to execute smart_search_vrf as read-only user
     """
     v = VRF.smart_search('default')
     self.assertEqual(v['result'][0].id, 0)