Use accessors instead of private attributes for Ml2 plugin

Start using accessors instead of private attributes of PortContext
and NetworkContext where it is possible.

Closes-bug: #1424587

Change-Id: Ie3d963ae6cee9782d65ba683936072602c78ebaa
This commit is contained in:
Ann Kamyshnikova 2015-03-04 15:50:07 +03:00
parent 5d85b396dd
commit 857322c30e
2 changed files with 10 additions and 9 deletions

View 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):

View 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