diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 24b4a5e38..14ad1f56f 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -154,6 +154,19 @@ class CommonDbMixin(object): query = result_filter(query, filters) return query + def _apply_dict_extend_functions(self, resource_type, + response, db_object): + for func in self._dict_extend_functions.get( + resource_type, []): + args = (response, db_object) + if isinstance(func, basestring): + func = getattr(self, func, None) + else: + # must call unbound method - use self as 1st argument + args = (self,) + args + if func: + func(*args) + def _get_collection_query(self, context, model, filters=None, sorts=None, limit=None, marker_obj=None, page_reverse=False): @@ -865,9 +878,8 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, for subnet in network['subnets']]} # Call auxiliary extend functions, if any if process_extensions: - for func in self._dict_extend_functions.get(attributes.NETWORKS, - []): - func(self, res, network) + self._apply_dict_extend_functions( + attributes.NETWORKS, res, network) return self._fields(res, fields) def _make_subnet_dict(self, subnet, fields=None): @@ -907,9 +919,8 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, "device_owner": port["device_owner"]} # Call auxiliary extend functions, if any if process_extensions: - for func in self._dict_extend_functions.get(attributes.PORTS, - []): - func(self, res, port) + self._apply_dict_extend_functions( + attributes.PORTS, res, port) return self._fields(res, fields) def _create_bulk(self, resource, context, request_items): diff --git a/neutron/db/extradhcpopt_db.py b/neutron/db/extradhcpopt_db.py index abbccbac8..1be60a541 100644 --- a/neutron/db/extradhcpopt_db.py +++ b/neutron/db/extradhcpopt_db.py @@ -128,4 +128,4 @@ class ExtraDhcpOptMixin(object): return res db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.PORTS, [_extend_port_dict_extra_dhcp_opt]) + attributes.PORTS, ['_extend_port_dict_extra_dhcp_opt']) diff --git a/neutron/db/extraroute_db.py b/neutron/db/extraroute_db.py index 987e87b3b..7e8b7b3a7 100644 --- a/neutron/db/extraroute_db.py +++ b/neutron/db/extraroute_db.py @@ -63,7 +63,7 @@ class ExtraRoute_db_mixin(l3_db.L3_NAT_db_mixin): )) db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - l3.ROUTERS, [_extend_router_dict_extraroute]) + l3.ROUTERS, ['_extend_router_dict_extraroute']) def update_router(self, context, id, router): r = router['router'] diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 071d74f50..7059c00ac 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -143,9 +143,12 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): if router['gw_port_id']: nw_id = router.gw_port['network_id'] res[EXTERNAL_GW_INFO] = {'network_id': nw_id} + # NOTE(salv-orlando): The following assumes this mixin is used in a + # class inheriting from CommonDbMixin, which is true for all existing + # plugins. if process_extensions: - for func in self._dict_extend_functions.get(l3.ROUTERS, []): - func(self, res, router) + self._apply_dict_extend_functions( + l3.ROUTERS, res, router) return self._fields(res, fields) def create_router(self, context, router): @@ -792,7 +795,7 @@ class L3_NAT_db_mixin(l3.RouterPluginBase): # Register dict extend functions for networks db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.NETWORKS, [_extend_network_dict_l3]) + attributes.NETWORKS, ['_extend_network_dict_l3']) def _process_l3_create(self, context, net_data, req_data): external = req_data.get(l3.EXTERNAL) diff --git a/neutron/db/portsecurity_db.py b/neutron/db/portsecurity_db.py index f2eff2aae..e5ad6b19d 100644 --- a/neutron/db/portsecurity_db.py +++ b/neutron/db/portsecurity_db.py @@ -177,6 +177,6 @@ class PortSecurityDbMixin(object): # Register dict extend functions for ports and networks db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attrs.NETWORKS, [_extend_port_security_dict]) + attrs.NETWORKS, ['_extend_port_security_dict']) db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attrs.PORTS, [_extend_port_security_dict]) + attrs.PORTS, ['_extend_port_security_dict']) diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 009217dc3..89b66d2d3 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -444,7 +444,7 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): # Register dict extend functions for ports db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attr.PORTS, [_extend_port_dict_security_group]) + attr.PORTS, ['_extend_port_dict_security_group']) def _process_port_create_security_group(self, context, port, security_group_ids): diff --git a/neutron/plugins/nicira/dbexts/distributedrouter.py b/neutron/plugins/nicira/dbexts/distributedrouter.py index 1d82847e6..6856e8b35 100644 --- a/neutron/plugins/nicira/dbexts/distributedrouter.py +++ b/neutron/plugins/nicira/dbexts/distributedrouter.py @@ -66,4 +66,4 @@ class DistributedRouter_mixin(object): # Register dict extend functions for ports db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - l3.ROUTERS, [_extend_router_dict_distributed]) + l3.ROUTERS, ['_extend_router_dict_distributed']) diff --git a/neutron/plugins/nicira/dbexts/maclearning.py b/neutron/plugins/nicira/dbexts/maclearning.py index cf89485c0..ab824b18e 100644 --- a/neutron/plugins/nicira/dbexts/maclearning.py +++ b/neutron/plugins/nicira/dbexts/maclearning.py @@ -59,7 +59,7 @@ class MacLearningDbMixin(object): # Register dict extend functions for ports db_base_plugin_v2.NeutronDbPluginV2.register_dict_extend_funcs( - attributes.PORTS, [_extend_port_mac_learning_state]) + attributes.PORTS, ['_extend_port_mac_learning_state']) def _update_mac_learning_state(self, context, port_id, enabled): try: