From bd7055daf23f03fe2e939e6d585885341422978c Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 6 Apr 2017 05:01:30 -0700 Subject: [PATCH] Allow offloading lookups in driver contexts This allows segments looked up ahead of time to be passed into NetworkContext objects and NetworkContext objects to be passed into PortContext objects. This allows us to avoid doing segments lookups for every PortContext construction when handling a bunch of ports (e.g. in RPC handler). Conflicts: neutron/plugins/ml2/driver_context.py Change-Id: Ib4c43a7894fe1285ecf4bdf9af5e5f1b93b0b39b Partial-Bug: #1665215 (cherry picked from commit 604e598a7d43b8b3a260969de84af737a4988c4e) (cherry picked from commit a2ae48c2cee71d8a27f44c5d5cfbfbdacc1fee00) --- neutron/plugins/ml2/driver_context.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/neutron/plugins/ml2/driver_context.py b/neutron/plugins/ml2/driver_context.py index f0503138e68..d18bb25d6c2 100644 --- a/neutron/plugins/ml2/driver_context.py +++ b/neutron/plugins/ml2/driver_context.py @@ -38,12 +38,15 @@ class MechanismDriverContext(object): class NetworkContext(MechanismDriverContext, api.NetworkContext): def __init__(self, plugin, plugin_context, network, - original_network=None): + original_network=None, segments=None): super(NetworkContext, self).__init__(plugin, plugin_context) self._network = network self._original_network = original_network - self._segments = segments_db.get_network_segments( - plugin_context.session, network['id']) + if segments is None: + self._segments = segments_db.get_network_segments( + plugin_context.session, network['id']) + else: + self._segments = segments @property def current(self): @@ -88,8 +91,11 @@ class PortContext(MechanismDriverContext, api.PortContext): super(PortContext, self).__init__(plugin, plugin_context) self._port = port self._original_port = original_port - self._network_context = NetworkContext(plugin, plugin_context, - network) if network else None + if isinstance(network, NetworkContext): + self._network_context = network + else: + self._network_context = NetworkContext( + plugin, plugin_context, network) if network else None self._binding = binding self._binding_levels = binding_levels self._segments_to_bind = None