diff --git a/neutron/db/vlantransparent_db.py b/neutron/db/vlantransparent_db.py index 588ae4fcc3c..066371027aa 100644 --- a/neutron/db/vlantransparent_db.py +++ b/neutron/db/vlantransparent_db.py @@ -13,9 +13,9 @@ # under the License. from neutron_lib.api.definitions import network as net_def +from neutron_lib.api.definitions import vlantransparent as vlan_apidef from neutron.db import _resource_extend as resource_extend -from neutron.extensions import vlantransparent @resource_extend.has_resource_extenders @@ -25,6 +25,6 @@ class Vlantransparent_db_mixin(object): @staticmethod @resource_extend.extends([net_def.COLLECTION_NAME]) def _extend_network_dict_vlan_transparent(network_res, network_db): - network_res[vlantransparent.VLANTRANSPARENT] = ( + network_res[vlan_apidef.VLANTRANSPARENT] = ( network_db.vlan_transparent) return network_res diff --git a/neutron/extensions/vlantransparent.py b/neutron/extensions/vlantransparent.py index 56136064b28..e4a4cf9cab5 100644 --- a/neutron/extensions/vlantransparent.py +++ b/neutron/extensions/vlantransparent.py @@ -12,70 +12,22 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron_lib.api import converters +from neutron_lib.api.definitions import vlantransparent as apidef from neutron_lib.api import extensions -from neutron_lib.api import validators -from neutron_lib import constants -from neutron_lib import exceptions from oslo_config import cfg from oslo_log import log as logging -from neutron._i18n import _ - LOG = logging.getLogger(__name__) -class VlanTransparencyDriverError(exceptions.NeutronException): - """Vlan Transparency not supported by all mechanism drivers.""" - message = _("Backend does not support VLAN Transparency.") - - -VLANTRANSPARENT = 'vlan_transparent' -EXTENDED_ATTRIBUTES_2_0 = { - 'networks': { - VLANTRANSPARENT: {'allow_post': True, 'allow_put': False, - 'convert_to': converters.convert_to_boolean, - 'default': constants.ATTR_NOT_SPECIFIED, - 'is_visible': True}, - }, -} - - -def disable_extension_by_config(aliases): +def _disable_extension_by_config(aliases): if not cfg.CONF.vlan_transparent: if 'vlan-transparent' in aliases: aliases.remove('vlan-transparent') LOG.info('Disabled vlantransparent extension.') -def get_vlan_transparent(network): - return (network['vlan_transparent'] - if ('vlan_transparent' in network and - validators.is_attr_set(network['vlan_transparent'])) - else False) - - -class Vlantransparent(extensions.ExtensionDescriptor): +class Vlantransparent(extensions.APIExtensionDescriptor): """Extension class supporting vlan transparent networks.""" - @classmethod - def get_name(cls): - return "Vlantransparent" - - @classmethod - def get_alias(cls): - return "vlan-transparent" - - @classmethod - def get_description(cls): - return "Provides Vlan Transparent Networks" - - @classmethod - def get_updated(cls): - return "2015-03-23T09:00:00-00:00" - - def get_extended_resources(self, version): - if version == "2.0": - return EXTENDED_ATTRIBUTES_2_0 - else: - return {} + api_definition = apidef diff --git a/neutron/plugins/ml2/managers.py b/neutron/plugins/ml2/managers.py index 57960ced645..a7b6e7d8a34 100644 --- a/neutron/plugins/ml2/managers.py +++ b/neutron/plugins/ml2/managers.py @@ -19,6 +19,7 @@ from neutron_lib.api.definitions import provider_net as provider from neutron_lib.api import validators from neutron_lib import constants from neutron_lib import exceptions as exc +from neutron_lib.exceptions import vlantransparent as vlan_exc from neutron_lib.plugins.ml2 import api from oslo_config import cfg from oslo_log import log @@ -30,7 +31,6 @@ from neutron.conf.plugins.ml2 import config from neutron.db import api as db_api from neutron.db import segments_db from neutron.extensions import multiprovidernet as mpnet -from neutron.extensions import vlantransparent from neutron.plugins.ml2.common import exceptions as ml2_exc from neutron.plugins.ml2 import models @@ -396,14 +396,14 @@ class MechanismManager(stevedore.named.NamedExtensionManager): """Helper method for checking vlan transparecncy support. :param context: context parameter to pass to each method call - :raises: neutron.extensions.vlantransparent. + :raises: neutron_lib.exceptions.vlantransparent. VlanTransparencyDriverError if any mechanism driver doesn't support vlan transparency. """ if context.current.get('vlan_transparent'): for driver in self.ordered_mech_drivers: if not driver.obj.check_vlan_transparency(context): - raise vlantransparent.VlanTransparencyDriverError() + raise vlan_exc.VlanTransparencyDriverError() def _call_on_drivers(self, method_name, context, continue_on_failure=False, raise_db_retriable=False): diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index 166b73ab918..06f0d6cd547 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -23,6 +23,7 @@ from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import portbindings from neutron_lib.api.definitions import subnet as subnet_def +from neutron_lib.api.definitions import vlantransparent as vlan_apidef from neutron_lib.api import validators from neutron_lib.api.validators import availability_zone as az_validator from neutron_lib.callbacks import events @@ -164,7 +165,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, aliases = self._supported_extension_aliases[:] aliases += self.extension_manager.extension_aliases() sg_rpc.disable_security_group_extension_by_config(aliases) - vlantransparent.disable_extension_by_config(aliases) + vlantransparent._disable_extension_by_config(aliases) self._aliases = aliases return self._aliases @@ -811,7 +812,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, # Update the transparent vlan if configured if utils.is_extension_supported(self, 'vlan-transparent'): - vlt = vlantransparent.get_vlan_transparent(net_data) + vlt = vlan_apidef.get_vlan_transparent(net_data) net_db['vlan_transparent'] = vlt result['vlan_transparent'] = vlt diff --git a/neutron/tests/unit/extensions/test_vlantransparent.py b/neutron/tests/unit/extensions/test_vlantransparent.py index daed26064f6..6367c0f2dc4 100644 --- a/neutron/tests/unit/extensions/test_vlantransparent.py +++ b/neutron/tests/unit/extensions/test_vlantransparent.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from neutron_lib.api.definitions import vlantransparent as vlan_apidef from oslo_config import cfg from webob import exc as web_exc @@ -35,7 +36,7 @@ class VlanTransparentExtensionManager(object): return [] def get_extended_resources(self, version): - return vlt.Vlantransparent().get_extended_resources(version) + return vlt.Vlantransparent.get_extended_resources(version) class VlanTransparentExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2, @@ -50,7 +51,7 @@ class VlanTransparentExtensionTestPlugin(db_base_plugin_v2.NeutronDbPluginV2, self).create_network(context, network) # Update the vlan_transparent in the database n = network['network'] - vlan_transparent = vlt.get_vlan_transparent(n) + vlan_transparent = vlan_apidef.get_vlan_transparent(n) network = self._get_network(context, new_net['id']) n['vlan_transparent'] = vlan_transparent network.update(n) @@ -80,7 +81,7 @@ class VlanTransparentExtensionTestCase(test_db_base_plugin_v2.TestNetworksV2): res = self.deserialize(self.fmt, req.get_response(self.api)) self.assertEqual(net['network']['name'], res['network']['name']) - self.assertTrue(res['network'][vlt.VLANTRANSPARENT]) + self.assertTrue(res['network'][vlan_apidef.VLANTRANSPARENT]) def test_network_create_with_bad_vlan_transparent_attr(self): vlantrans = {'vlan_transparent': "abc"} @@ -94,10 +95,10 @@ class VlanTransparentExtensionTestCase(test_db_base_plugin_v2.TestNetworksV2): def test_network_update_with_vlan_transparent_exception(self): with self.network(name='net1') as net: self._update('networks', net['network']['id'], - {'network': {vlt.VLANTRANSPARENT: False}}, + {'network': {vlan_apidef.VLANTRANSPARENT: False}}, web_exc.HTTPBadRequest.code) req = self.new_show_request('networks', net['network']['id']) res = self.deserialize(self.fmt, req.get_response(self.api)) self.assertEqual(net['network']['name'], res['network']['name']) - self.assertFalse(res['network'][vlt.VLANTRANSPARENT]) + self.assertFalse(res['network'][vlan_apidef.VLANTRANSPARENT])