neutron/neutron/db/data_plane_status_db.py
Henry Gessau b3c0d5f239 Eliminate lookup of "resource extend" funcs by name
By registering functions directly we cut off the dependency of the
"resource extend" functions on the plugin. This is a step towards
the goal of removing the CommonDbMixin mixin class.

Also, we register all "resource extend" functions at plugin create
(in __new__) instead of in the class definition (which caused the
hooks to be registered on import). This ensures the "resource
extend" functions are only registered for the plugins/mixins that
are actually used.

Note that decorators are used to register "resource extend" methods,
similar to the callback receiver decorators.

Related-Blueprint: neutron-lib

Change-Id: I128cfda773d5f9597df9cd61261fdc05f2a174aa
2017-04-21 14:48:42 -04:00

50 lines
2.0 KiB
Python

# Copyright (c) 2017 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib.api.definitions import data_plane_status as dps_lib
from neutron.objects.port.extensions import data_plane_status as dps_obj
class DataPlaneStatusMixin(object):
"""Mixin class to add data plane status to a port"""
def _process_create_port_data_plane_status(self, context, data, res):
obj = dps_obj.PortDataPlaneStatus(context, port_id=res['id'],
data_plane_status=data[dps_lib.DATA_PLANE_STATUS])
obj.create()
res[dps_lib.DATA_PLANE_STATUS] = data[dps_lib.DATA_PLANE_STATUS]
def _process_update_port_data_plane_status(self, context, data,
res):
if dps_lib.DATA_PLANE_STATUS not in data:
return
obj = dps_obj.PortDataPlaneStatus.get_object(context,
port_id=res['id'])
if obj:
obj.data_plane_status = data[dps_lib.DATA_PLANE_STATUS]
obj.update()
res[dps_lib.DATA_PLANE_STATUS] = data[dps_lib.DATA_PLANE_STATUS]
else:
self._process_create_port_data_plane_status(context, data, res)
@staticmethod
def _extend_port_data_plane_status(port_res, port_db):
port_res[dps_lib.DATA_PLANE_STATUS] = None
if port_db.get(dps_lib.DATA_PLANE_STATUS):
port_res[dps_lib.DATA_PLANE_STATUS] = (
port_db[dps_lib.DATA_PLANE_STATUS].data_plane_status)