From bb49c4f6820b444966693d6c1f6d7ebeb00b1f43 Mon Sep 17 00:00:00 2001 From: Henry Gessau Date: Tue, 6 Dec 2016 21:04:58 -0500 Subject: [PATCH] Move _get_marker_obj() out of CommonDbMixin. This refactoring is a step towards the goal of removing the CommonDbMixin mixin class. Related-Blueprint: neutron-lib Change-Id: I1e2da0687310cc2da767dc2a6d13500307bba1ee --- neutron/db/_utils.py | 18 ++++++++++++++++++ neutron/db/common_db_mixin.py | 5 ++--- neutron/db/db_base_plugin_common.py | 3 ++- neutron/db/db_base_plugin_v2.py | 6 ++++-- neutron/db/l3_db.py | 7 ++++--- neutron/db/securitygroups_db.py | 9 +++++---- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/neutron/db/_utils.py b/neutron/db/_utils.py index 0e40810c8c9..f53264f437f 100644 --- a/neutron/db/_utils.py +++ b/neutron/db/_utils.py @@ -120,3 +120,21 @@ def filter_non_model_columns(data, model): data.items() if k in columns or isinstance(getattr(model, k, None), associationproxy.AssociationProxy)) + + +# NOTE: This used to be CommonDbMixin._get_marker_obj +def get_marker_obj(plugin, context, resource, limit, marker): + """Retrieve a resource marker object. + + This function is used to invoke: + plugin._get_(context, marker) + It is used for pagination. + + :param plugin: The plugin processing the request. + :param context: The request context. + :param resource: The resource name. + :param limit: Indicates if pagination is in effect. + :param marker: The id of the marker object. + """ + if limit and marker: + return getattr(plugin, '_get_%s' % resource)(context, marker) diff --git a/neutron/db/common_db_mixin.py b/neutron/db/common_db_mixin.py index 7288c763341..99c6fdd20ea 100644 --- a/neutron/db/common_db_mixin.py +++ b/neutron/db/common_db_mixin.py @@ -95,10 +95,9 @@ class CommonDbMixin(object): def _get_collection_count(context, model, filters=None): return _model_query.get_collection_count(context, model, filters) + # TODO(HenryG): Remove this when available in neutron-lib def _get_marker_obj(self, context, resource, limit, marker): - if limit and marker: - return getattr(self, '_get_%s' % resource)(context, marker) - return None + return ndb_utils.get_marker_obj(self, context, resource, limit, marker) @staticmethod def _filter_non_model_columns(data, model): diff --git a/neutron/db/db_base_plugin_common.py b/neutron/db/db_base_plugin_common.py index 9ea399d5c9d..4d9c4df3ebc 100644 --- a/neutron/db/db_base_plugin_common.py +++ b/neutron/db/db_base_plugin_common.py @@ -251,7 +251,8 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin): def _get_subnets(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'subnet', limit, marker) + marker_obj = db_utils.get_marker_obj(self, context, 'subnet', + limit, marker) make_subnet_dict = functools.partial(self._make_subnet_dict, context=context) return model_query.get_collection(context, models_v2.Subnet, diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 75be729be03..0f2074c7b75 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -461,7 +461,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, def get_networks(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'network', limit, marker) + marker_obj = ndb_utils.get_marker_obj(self, context, 'network', + limit, marker) make_network_dict = functools.partial(self._make_network_dict, context=context) return model_query.get_collection(context, models_v2.Network, @@ -1370,7 +1371,8 @@ class NeutronDbPluginV2(db_base_plugin_common.DbBasePluginCommon, def get_ports(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'port', limit, marker) + marker_obj = ndb_utils.get_marker_obj(self, context, 'port', + limit, marker) query = self._get_ports_query(context, filters=filters, sorts=sorts, limit=limit, marker_obj=marker_obj, diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 14279344f17..787ef9abf77 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -561,7 +561,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, def get_routers(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'router', limit, marker) + marker_obj = db_utils.get_marker_obj(self, context, 'router', + limit, marker) return model_query.get_collection(context, l3_models.Router, self._make_router_dict, filters=filters, fields=fields, @@ -1380,8 +1381,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, def get_floatingips(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'floatingip', limit, - marker) + marker_obj = db_utils.get_marker_obj(self, context, 'floatingip', + limit, marker) if filters is not None: for key, val in API_TO_DB_COLUMN_MAP.items(): if key in filters: diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 270be98bd74..05585278d4e 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -143,8 +143,8 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): else: tenant_id = context.tenant_id self._ensure_default_security_group(context, tenant_id) - marker_obj = self._get_marker_obj(context, 'security_group', limit, - marker) + marker_obj = db_utils.get_marker_obj(self, context, 'security_group', + limit, marker) return model_query.get_collection(context, sg_models.SecurityGroup, self._make_security_group_dict, @@ -603,8 +603,9 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): def get_security_group_rules(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): - marker_obj = self._get_marker_obj(context, 'security_group_rule', - limit, marker) + marker_obj = db_utils.get_marker_obj(self, context, + 'security_group_rule', + limit, marker) return model_query.get_collection(context, sg_models.SecurityGroupRule, self._make_security_group_rule_dict,