Move _filter_non_model_columns method to CommonDbMixin

Such way other non-core plugins may avoid duplicating this small
piece of code.

Change-Id: I00ae0b590fc2ad46d3667d18f29fccb5b40bde82
This commit is contained in:
Eugene Nikanorov 2014-06-18 18:13:28 +04:00 committed by enikanorov
parent 7edd837582
commit e010c9015f

View File

@ -217,6 +217,14 @@ class CommonDbMixin(object):
return getattr(self, '_get_%s' % resource)(context, marker) return getattr(self, '_get_%s' % resource)(context, marker)
return None return None
def _filter_non_model_columns(self, data, model):
"""Remove all the attributes from data which are not columns of
the model passed as second parameter.
"""
columns = [c.name for c in model.__table__.columns]
return dict((k, v) for (k, v) in
data.iteritems() if k in columns)
class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
CommonDbMixin): CommonDbMixin):
@ -255,14 +263,6 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
cur_funcs.extend(funcs) cur_funcs.extend(funcs)
cls._dict_extend_functions[resource] = cur_funcs cls._dict_extend_functions[resource] = cur_funcs
def _filter_non_model_columns(self, data, model):
"""Remove all the attributes from data which are not columns of
the model passed as second parameter.
"""
columns = [c.name for c in model.__table__.columns]
return dict((k, v) for (k, v) in
data.iteritems() if k in columns)
def _get_network(self, context, id): def _get_network(self, context, id):
try: try:
network = self._get_by_id(context, models_v2.Network, id) network = self._get_by_id(context, models_v2.Network, id)