Switch to new engine facade for TrunkPlugin and TrunkSkeleton
Partially-Implements blueprint: enginefacade-switch Change-Id: I7bf70a71a0878654a63edc6132102711ef215b6a
This commit is contained in:
parent
29ccecebd7
commit
24acbf9414
|
@ -31,6 +31,7 @@ class SubPort(base.NeutronDbObject):
|
|||
VERSION = '1.0'
|
||||
|
||||
db_model = models.SubPort
|
||||
new_facade = True
|
||||
|
||||
primary_keys = ['port_id']
|
||||
foreign_keys = {'Trunk': {'trunk_id': 'id'}}
|
||||
|
@ -51,33 +52,35 @@ class SubPort(base.NeutronDbObject):
|
|||
return _dict
|
||||
|
||||
def create(self):
|
||||
with self.db_context_writer(self.obj_context):
|
||||
try:
|
||||
try:
|
||||
with self.db_context_writer(self.obj_context):
|
||||
super(SubPort, self).create()
|
||||
except o_db_exc.DBReferenceError as ex:
|
||||
if ex.key_table is None:
|
||||
# NOTE(ivc): 'key_table' is provided by 'oslo.db' [1]
|
||||
# only for a limited set of database backends (i.e.
|
||||
# MySQL and PostgreSQL). Other database backends
|
||||
# (including SQLite) would have 'key_table' set to None.
|
||||
# We emulate the 'key_table' support for such database
|
||||
# backends.
|
||||
#
|
||||
# [1] https://github.com/openstack/oslo.db/blob/3fadd5a
|
||||
# /oslo_db/sqlalchemy/exc_filters.py#L190-L203
|
||||
except o_db_exc.DBReferenceError as ex:
|
||||
if ex.key_table is None:
|
||||
# NOTE(ivc): 'key_table' is provided by 'oslo.db' [1]
|
||||
# only for a limited set of database backends (i.e.
|
||||
# MySQL and PostgreSQL). Other database backends
|
||||
# (including SQLite) would have 'key_table' set to None.
|
||||
# We emulate the 'key_table' support for such database
|
||||
# backends.
|
||||
#
|
||||
# [1] https://github.com/openstack/oslo.db/blob/3fadd5a
|
||||
# /oslo_db/sqlalchemy/exc_filters.py#L190-L203
|
||||
self.obj_context.session.rollback()
|
||||
with self.db_context_reader(self.obj_context):
|
||||
if not Trunk.get_object(self.obj_context,
|
||||
id=self.trunk_id):
|
||||
ex.key_table = Trunk.db_model.__tablename__
|
||||
|
||||
if ex.key_table == Trunk.db_model.__tablename__:
|
||||
raise t_exc.TrunkNotFound(trunk_id=self.trunk_id)
|
||||
if ex.key_table == Trunk.db_model.__tablename__:
|
||||
raise t_exc.TrunkNotFound(trunk_id=self.trunk_id)
|
||||
|
||||
raise n_exc.PortNotFound(port_id=self.port_id)
|
||||
except o_exc.NeutronDbObjectDuplicateEntry:
|
||||
raise t_exc.DuplicateSubPort(
|
||||
segmentation_type=self.segmentation_type,
|
||||
segmentation_id=self.segmentation_id,
|
||||
trunk_id=self.trunk_id)
|
||||
raise n_exc.PortNotFound(port_id=self.port_id)
|
||||
except o_exc.NeutronDbObjectDuplicateEntry:
|
||||
raise t_exc.DuplicateSubPort(
|
||||
segmentation_type=self.segmentation_type,
|
||||
segmentation_id=self.segmentation_id,
|
||||
trunk_id=self.trunk_id)
|
||||
|
||||
|
||||
@base.NeutronObjectRegistry.register
|
||||
|
@ -87,6 +90,7 @@ class Trunk(base.NeutronDbObject):
|
|||
VERSION = '1.1'
|
||||
|
||||
db_model = models.Trunk
|
||||
new_facade = True
|
||||
|
||||
fields = {
|
||||
'admin_state_up': obj_fields.BooleanField(),
|
||||
|
|
|
@ -223,7 +223,7 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
|||
port_id=trunk['port_id'],
|
||||
status=constants.TRUNK_DOWN_STATUS,
|
||||
sub_ports=sub_ports)
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk_obj.create()
|
||||
payload = callbacks.TrunkPayload(context, trunk_obj.id,
|
||||
current_trunk=trunk_obj)
|
||||
|
@ -238,7 +238,7 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
|||
def update_trunk(self, context, trunk_id, trunk):
|
||||
"""Update information for the specified trunk."""
|
||||
trunk_data = trunk['trunk']
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk_obj = self._get_trunk(context, trunk_id)
|
||||
original_trunk = copy.deepcopy(trunk_obj)
|
||||
# NOTE(status_police): a trunk status should not change during an
|
||||
|
@ -261,7 +261,7 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
|||
|
||||
def delete_trunk(self, context, trunk_id):
|
||||
"""Delete the specified trunk."""
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk = self._get_trunk(context, trunk_id)
|
||||
rules.trunk_can_be_managed(context, trunk)
|
||||
trunk_port_validator = rules.TrunkPortValidator(trunk.port_id)
|
||||
|
@ -283,7 +283,7 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
|||
@db_base_plugin_common.convert_result_to_dict
|
||||
def add_subports(self, context, trunk_id, subports):
|
||||
"""Add one or more subports to trunk."""
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk = self._get_trunk(context, trunk_id)
|
||||
|
||||
# Check for basic validation since the request body here is not
|
||||
|
@ -337,7 +337,7 @@ class TrunkPlugin(service_base.ServicePluginBase):
|
|||
def remove_subports(self, context, trunk_id, subports):
|
||||
"""Remove one or more subports from trunk."""
|
||||
subports = subports['sub_ports']
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk = self._get_trunk(context, trunk_id)
|
||||
original_trunk = copy.deepcopy(trunk)
|
||||
rules.trunk_can_be_managed(context, trunk)
|
||||
|
|
|
@ -104,7 +104,7 @@ class TrunkSkeleton(object):
|
|||
|
||||
def update_trunk_status(self, context, trunk_id, status):
|
||||
"""Update the trunk status to reflect outcome of data plane wiring."""
|
||||
with db_api.autonested_transaction(context.session):
|
||||
with db_api.CONTEXT_WRITER.using(context):
|
||||
trunk = trunk_objects.Trunk.get_object(context, id=trunk_id)
|
||||
if trunk:
|
||||
trunk.update(status=status)
|
||||
|
|
Loading…
Reference in New Issue