def retrieve_matched_rrsets(context, controller_obj, zone_id, **params): if zone_id: # NOTE: We need to ensure the zone actually exists, otherwise we may # return deleted recordsets instead of a zone not found controller_obj.central_api.get_zone(context, zone_id) # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, controller_obj.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'name', 'type', 'ttl', 'data', 'status', 'description',) criterion = controller_obj._apply_filter_params( params, accepted_filters, {}) # Use DB index for better performance in the case of cross zone search force_index = True if zone_id: criterion['zone_id'] = zone_id force_index = False recordsets = controller_obj.central_api.find_recordsets( context, criterion, marker, limit, sort_key, sort_dir, force_index) return recordsets
def retrieve_matched_rrsets(context, controller_obj, zone_id, **params): if zone_id: # NOTE: We need to ensure the zone actually exists, otherwise we may # return deleted recordsets instead of a zone not found controller_obj.central_api.get_zone(context, zone_id) # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, controller_obj.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'name', 'type', 'ttl', 'data', 'status', 'description', ) criterion = controller_obj._apply_filter_params(params, accepted_filters, {}) # Use DB index for better performance in the case of cross zone search force_index = True if zone_id: criterion['zone_id'] = zone_id force_index = False recordsets = controller_obj.central_api.find_recordsets( context, criterion, marker, limit, sort_key, sort_dir, force_index) return recordsets
def get_all(self, **params): """List Zones""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'name', 'type', 'email', 'status', 'description', 'ttl', ) criterion = self._apply_filter_params(params, accepted_filters, {}) zones = self.central_api.find_zones(context, criterion, marker, limit, sort_key, sort_dir) LOG.info("Retrieved %(zones)s", {'zones': zones}) return DesignateAdapter.render('API_v2', zones, request=request)
def get_all(self, zone_id, **params): """List RecordSets""" request = pecan.request context = request.environ['context'] # NOTE: We need to ensure the zone actually exists, otherwise we may # return deleted recordsets instead of a zone not found self.central_api.get_zone(context, zone_id) # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'name', 'type', 'ttl', 'data', 'status', 'description', ) criterion = self._apply_filter_params( params, accepted_filters, {}) criterion['zone_id'] = zone_id recordsets = self.central_api.find_recordsets( context, criterion, marker, limit, sort_key, sort_dir) LOG.info(_LI("Retrieved %(recordsets)s"), {'recordsets': recordsets}) return DesignateAdapter.render('API_v2', recordsets, request=request)
def test_get_paging_params_max_limit(self): CONF.set_override('max_limit_v2', 1000, 'service:api') context = mock.Mock() result = utils.get_paging_params(context, {'limit': 'max'}, []) self.assertEqual(result[1], 1000)
def get_all(self, zone_id, **params): """List RecordSets""" request = pecan.request context = request.environ['context'] # NOTE: We need to ensure the domain actually exists, otherwise we may # return deleted recordsets instead of a domain not found self.central_api.get_domain(context, zone_id) # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'name', 'type', 'ttl', 'data', 'status', 'description', ) criterion = self._apply_filter_params( params, accepted_filters, {}) criterion['domain_id'] = zone_id # Data must be filtered separately, through the Records table data = criterion.pop('data', None) status = criterion.pop('status', None) # Retrieve recordsets recordsets = self.central_api.find_recordsets( context, criterion, marker, limit, sort_key, sort_dir) # 'data' filter param: only return recordsets with matching data if data: records = self.central_api.find_records( context, criterion={'data': data, 'domain_id': zone_id}) recordset_with_data_ids = set(record.recordset_id for record in records) new_rsets = RecordSetList() for recordset in recordsets: if recordset.id in recordset_with_data_ids: new_rsets.append(recordset) recordsets = new_rsets recordsets.total_count = len(recordset_with_data_ids) # 'status' filter param: only return recordsets with matching status if status: new_rsets = RecordSetList() for recordset in recordsets: if recordset.status == status: new_rsets.append(recordset) recordsets = new_rsets return DesignateAdapter.render('API_v2', recordsets, request=request)
def get_all(self, **params): """List Zone Imports""" request = pecan.request context = request.environ["context"] marker, limit, sort_key, sort_dir = utils.get_paging_params(params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ("status", "message", "zone_id") criterion = self._apply_filter_params(params, accepted_filters, {}) return ZoneImportAPIv2Adapter.render( "API_v2", self.central_api.find_zone_imports(context, criterion, marker, limit, sort_key, sort_dir), request=request, )
def get_all(self, **params): """List Zone Exports""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('status', 'message', 'zone_id', ) criterion = self._apply_filter_params( params, accepted_filters, {}) return ZoneExportAPIv2Adapter.render( 'API_v2', self.central_api.find_zone_exports( context, criterion, marker, limit, sort_key, sort_dir), request=request)
def get_all(self, **params): """List ZoneTransferRequests""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. criterion = self._apply_filter_params(params, ('status',), {}) return DesignateAdapter.render( 'API_v2', self.central_api.find_zone_transfer_requests( context, criterion, marker, limit, sort_key, sort_dir), request=request, context=context)
def get_all(self, **params): request = pecan.request context = pecan.request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) accepted_filters = ["hostname", "service_name", "status"] criterion = self._apply_filter_params( params, accepted_filters, {}) service_statuses = self.central_api.find_service_statuses( context, criterion, ) return DesignateAdapter.render( 'API_v2', service_statuses, request=request)
def get_all(self, **params): """List all Pools""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name') criterion = self._apply_filter_params(params, accepted_filters, {}) return DesignateAdapter.render('API_v2', self.central_api.find_pools( context, criterion, marker, limit, sort_key, sort_dir), request=request)
def get_all(self, **params): request = pecan.request context = pecan.request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) accepted_filters = ["hostname", "service_name", "status"] criterion = self._apply_filter_params(params, accepted_filters, {}) service_statuses = self.central_api.find_service_statuses( context, criterion, ) return DesignateAdapter.render('API_v2', service_statuses, request=request)
def test_get_paging_params_without_sort_keys(self): CONF.set_override('default_limit_v2', 0, 'service:api') context = mock.Mock() params = { 'updated_at': None, 'created_at': '2019-06-28T04:17:34.000000', 'pattern': 'blacklisted.com.', 'id': 'f6663a98-281e-4cea-b0c3-3bc425e086ea', } marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, sort_keys=None) self.assertIsNone(marker) self.assertEqual(0, limit) self.assertIsNone(sort_key) self.assertIsNone(sort_dir)
def get_all(self, zone_id, **params): """List RecordSets""" request = pecan.request context = request.environ['context'] # NOTE: We need to ensure the domain actually exists, otherwise we may # return deleted recordsets instead of a domain not found self.central_api.get_domain(context, zone_id) # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name', 'type', 'ttl', 'data', ) criterion = self._apply_filter_params( params, accepted_filters, {}) criterion['domain_id'] = zone_id # Data must be filtered separately, through the Records table recordsets_with_data = set() data = criterion.pop('data', None) # Retrieve recordsets recordsets = self.central_api.find_recordsets( context, criterion, marker, limit, sort_key, sort_dir) # 'data' filter param: only return recordsets with matching data if data: records = self.central_api.find_records( context, criterion={'data': data, 'domain_id': zone_id}) recordsets_with_data.update( [record.recordset_id for record in records]) new_rsets = RecordSetList() for recordset in recordsets: if recordset.id in recordsets_with_data: new_rsets.append(recordset) recordsets = new_rsets return DesignateAdapter.render('API_v2', recordsets, request=request)
def get_all(self, **params): """List all Blacklisted Zones""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params accepted_filters = ('pattern', ) criterion = self._apply_filter_params( params, accepted_filters, {}) return DesignateAdapter.render( 'API_v2', self.central_api.find_blacklists( context, criterion, marker, limit, sort_key, sort_dir), request=request)
def get_all(self, **params): """List all TsigKeys""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params accepted_filters = ('name', 'algorithm', 'scope') criterion = self._apply_filter_params(params, accepted_filters, {}) tsigkeys = self.central_api.find_tsigkeys(context, criterion, marker, limit, sort_key, sort_dir) LOG.info("Retrieved %(tsigkeys)s", {'tsigkeys': tsigkeys}) return DesignateAdapter.render('API_v2', tsigkeys, request=request)
def get_all(self, **params): """List all TsigKeys""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params accepted_filters = ('name', 'algorithm', 'scope') criterion = self._apply_filter_params( params, accepted_filters, {}) return DesignateAdapter.render( 'API_v2', self.central_api.find_tsigkeys( context, criterion, marker, limit, sort_key, sort_dir), request=request)
def get_all(self, **params): """List Zones""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name', 'email', 'status', ) criterion = self._apply_filter_params( params, accepted_filters, {}) return DesignateAdapter.render( 'API_v2', self.central_api.find_domains( context, criterion, marker, limit, sort_key, sort_dir), request=request)
def get_all(self, **params): """List Tlds""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name', ) criterion = self._apply_filter_params(params, accepted_filters, {}) tlds = self.central_api.find_tlds(context, criterion, marker, limit, sort_key, sort_dir) LOG.info(_LI("Retrieved %(tlds)s"), {'tlds': tlds}) return DesignateAdapter.render('API_v2', tlds, request=request)
def get_all(self, **params): """List all Blacklisted Zones""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params accepted_filters = ('pattern', ) criterion = self._apply_filter_params( params, accepted_filters, {}) blacklists = self.central_api.find_blacklists( context, criterion, marker, limit, sort_key, sort_dir) LOG.info("Retrieved %(blacklists)s", {'blacklists': blacklists}) return DesignateAdapter.render('API_v2', blacklists, request=request)
def get_all(self, **params): """List all Pools""" request = pecan.request context = request.environ['context'] # Extract the pagination params marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name', ) criterion = self._apply_filter_params( params, accepted_filters, {}) pools = self.central_api.find_pools( context, criterion, marker, limit, sort_key, sort_dir) LOG.info(_LI("Retrieved %(pools)s"), {'pools': pools}) return DesignateAdapter.render('API_v2', pools, request=request)
def get_all(self, **params): """List ZoneImports""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'status', 'message', 'zone_id', ) criterion = self._apply_filter_params(params, accepted_filters, {}) return ZoneImportAPIv2Adapter.render( 'API_v2', self.central_api.find_zone_imports(context, criterion, marker, limit, sort_key, sort_dir), request=request)
def test_get_paging_params_sort_by_tenant_id(self): CONF.set_override('default_limit_v2', 100, 'service:api') context = mock.Mock() context.all_tenants = True params = { 'updated_at': None, 'created_at': '2019-06-28T04:17:34.000000', 'pattern': 'blacklisted.com.', 'id': 'f6663a98-281e-4cea-b0c3-3bc425e086ea', 'sort_key': 'tenant_id', } marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, ['created_at', 'id', 'updated_at', 'pattern', 'tenant_id']) self.assertIsNone(marker) self.assertEqual(100, limit) self.assertEqual('tenant_id', sort_key) self.assertIsNone(sort_dir)
def get_all(self, **params): """List Zones""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('name', 'type', 'email', 'status', 'description', 'ttl', ) criterion = self._apply_filter_params( params, accepted_filters, {}) zones = self.central_api.find_zones( context, criterion, marker, limit, sort_key, sort_dir) LOG.info(_LI("Retrieved %(zones)s"), {'zones': zones}) return DesignateAdapter.render('API_v2', zones, request=request)
def get_all(self, **params): """List Zone Imports""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ('status', 'message', 'zone_id', ) criterion = self._apply_filter_params( params, accepted_filters, {}) zone_imports = self.central_api.find_zone_imports( context, criterion, marker, limit, sort_key, sort_dir) LOG.info("Retrieved %(imports)s", {'imports': zone_imports}) return DesignateAdapter.render( 'API_v2', zone_imports, request=request)
def get_all(self, **params): """List Zone Imports""" request = pecan.request context = request.environ['context'] marker, limit, sort_key, sort_dir = utils.get_paging_params( context, params, self.SORT_KEYS) # Extract any filter params. accepted_filters = ( 'status', 'message', 'zone_id', ) criterion = self._apply_filter_params(params, accepted_filters, {}) zone_imports = self.central_api.find_zone_imports( context, criterion, marker, limit, sort_key, sort_dir) LOG.info(_LI("Retrieved %(imports)s"), {'imports': zone_imports}) return DesignateAdapter.render('API_v2', zone_imports, request=request)
def test_get_paging_params_max_limit(self): self.config(max_limit_v2=1000, group='service:api') result = utils.get_paging_params({'limit': "max"}, []) self.assertEqual(result[1], 1000)
def test_get_paging_params_invalid_sort_dir(self): with testtools.ExpectedException(exceptions.InvalidSortDir): utils.get_paging_params({'sort_dir': "dsc"}, [])
def test_get_paging_params_invalid_limit(self): for value in [9223372036854775809, -1]: with testtools.ExpectedException(exceptions.InvalidLimit): utils.get_paging_params({'limit': value}, [])
def test_get_paging_params_invalid_sort_key(self): with testtools.ExpectedException(exceptions.InvalidSortKey): utils.get_paging_params({'sort_key': "dsc"}, ['asc', 'desc'])
def test_get_paging_params_invalid_limit(self): context = Mock() for value in [9223372036854775809, -1]: with testtools.ExpectedException(exceptions.InvalidLimit): utils.get_paging_params(context, {'limit': value}, [])
def test_get_paging_params_invalid_sort_key(self): context = Mock() with testtools.ExpectedException(exceptions.InvalidSortKey): utils.get_paging_params(context, {'sort_key': "dsc"}, ['asc', 'desc'])
def test_get_paging_params_invalid_sort_dir(self): context = Mock() with testtools.ExpectedException(exceptions.InvalidSortDir): utils.get_paging_params(context, {'sort_dir': "dsc"}, [])
def test_get_paging_params_max_limit(self): context = Mock() self.config(max_limit_v2=1000, group='service:api') result = utils.get_paging_params(context, {'limit': "max"}, []) self.assertEqual(result[1], 1000)