]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use accessors instead of private attributes for Ml2 plugin
authorAnn Kamyshnikova <akamyshnikova@mirantis.com>
Wed, 4 Mar 2015 12:50:07 +0000 (15:50 +0300)
committerAnn Kamyshnikova <akamyshnikova@mirantis.com>
Fri, 6 Mar 2015 15:37:41 +0000 (18:37 +0300)
Start using accessors instead of private attributes of PortContext
and NetworkContext where it is possible.

Closes-bug: #1424587

Change-Id: Ie3d963ae6cee9782d65ba683936072602c78ebaa

neutron/plugins/ml2/managers.py
neutron/plugins/ml2/plugin.py

index 4fc271d5ef61f483e83f5a4e247bdfea7a2466a4..6c3743e19377209961c33696d8c8662ef6659c3c 100644 (file)
@@ -595,7 +595,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager):
 
     def _bind_port_level(self, context, level, segments_to_bind):
         binding = context._binding
-        port_id = context._port['id']
+        port_id = context.current['id']
         LOG.debug("Attempting to bind port %(port)s on host %(host)s "
                   "at level %(level)s using segments %(segments)s",
                   {'port': port_id,
@@ -652,7 +652,7 @@ class MechanismManager(stevedore.named.NamedExtensionManager):
                               driver.name)
         binding.vif_type = portbindings.VIF_TYPE_BINDING_FAILED
         LOG.error(_LE("Failed to bind port %(port)s on host %(host)s"),
-                  {'port': context._port['id'],
+                  {'port': context.current['id'],
                    'host': binding.host})
 
     def _check_driver_to_bind(self, driver, segments_to_bind, binding_levels):
index 25b8be482d8c1d43778c537ed379c6d3e4f60644..421c1379c6299bed744ea9ae1ff22523a9c2a190 100644 (file)
@@ -247,7 +247,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
     def _bind_port_if_needed(self, context, allow_notify=False,
                              need_notify=False):
         plugin_context = context._plugin_context
-        port_id = context._port['id']
+        port_id = context.current['id']
 
         # Since the mechanism driver bind_port() calls must be made
         # outside a DB transaction locking the port state, it is
@@ -316,7 +316,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
     def _bind_port(self, orig_context):
         # Construct a new PortContext from the one from the previous
         # transaction.
-        port = orig_context._port
+        port = orig_context.current
         orig_binding = orig_context._binding
         new_binding = models.PortBinding(
             host=orig_binding.host,
@@ -328,7 +328,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
         self._update_port_dict_binding(port, new_binding)
         new_context = driver_context.PortContext(
             self, orig_context._plugin_context, port,
-            orig_context._network_context._network, new_binding, None)
+            orig_context.network.current, new_binding, None)
 
         # Attempt to bind the port and return the context with the
         # result.
@@ -516,7 +516,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
         '_ml2_port_result_filter_hook')
 
     def _notify_port_updated(self, mech_context):
-        port = mech_context._port
+        port = mech_context.current
         segment = mech_context.bottom_bound_segment
         if not segment:
             # REVISIT(rkukura): This should notify agent to unplug port
@@ -958,7 +958,8 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
                 LOG.error(_LE("_bind_port_if_needed "
                               "failed, deleting port '%s'"), result['id'])
                 self.delete_port(context, result['id'])
-        return bound_context._port
+
+        return bound_context.current
 
     def create_port_bulk(self, context, ports):
         objects = self._create_bulk_ml2(attributes.PORT, context, ports)
@@ -979,7 +980,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
             for obj in objects:
                 obj['bound_context'] = self._bind_port_if_needed(
                     obj['mech_context'])
-            return [obj['bound_context']._port for obj in objects]
+            return [obj['bound_context'].current for obj in objects]
         except ml2_exc.MechanismDriverError:
             with excutils.save_and_reraise_exception():
                 resource_ids = [res['result']['id'] for res in objects]
@@ -1056,7 +1057,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
             mech_context,
             allow_notify=True,
             need_notify=need_port_update_notify)
-        return bound_context._port
+        return bound_context.current
 
     def _process_dvr_port_binding(self, mech_context, context, attrs):
         session = mech_context._plugin_context.session