Merge "Remove duplicate _check_provider_update from plugins"
This commit is contained in:
commit
9b0c3e80ab
|
@ -17,6 +17,8 @@
|
|||
|
||||
from quantum.api import extensions
|
||||
from quantum.api.v2 import attributes
|
||||
from quantum.common import exceptions as q_exc
|
||||
|
||||
|
||||
NETWORK_TYPE = 'provider:network_type'
|
||||
PHYSICAL_NETWORK = 'provider:physical_network'
|
||||
|
@ -43,6 +45,18 @@ EXTENDED_ATTRIBUTES_2_0 = {
|
|||
}
|
||||
|
||||
|
||||
def _raise_if_updates_provider_attributes(attrs):
|
||||
"""Raise exception if provider attributes are present.
|
||||
|
||||
This method is used for plugins that do not support
|
||||
updating provider networks.
|
||||
"""
|
||||
immutable = (NETWORK_TYPE, PHYSICAL_NETWORK, SEGMENTATION_ID)
|
||||
if any(attributes.is_attr_set(attrs.get(a)) for a in immutable):
|
||||
msg = _("plugin does not support updating provider attributes")
|
||||
raise q_exc.InvalidInput(error_message=msg)
|
||||
|
||||
|
||||
class Providernet(extensions.ExtensionDescriptor):
|
||||
"""Extension class supporting provider networks.
|
||||
|
||||
|
|
|
@ -253,25 +253,8 @@ class HyperVQuantumPlugin(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
p = self._network_providers_map[binding.network_type]
|
||||
p.extend_network_dict(network, binding)
|
||||
|
||||
def _check_provider_update(self, context, attrs):
|
||||
network_type = attrs.get(provider.NETWORK_TYPE)
|
||||
physical_network = attrs.get(provider.PHYSICAL_NETWORK)
|
||||
segmentation_id = attrs.get(provider.SEGMENTATION_ID)
|
||||
|
||||
network_type_set = attributes.is_attr_set(network_type)
|
||||
physical_network_set = attributes.is_attr_set(physical_network)
|
||||
segmentation_id_set = attributes.is_attr_set(segmentation_id)
|
||||
|
||||
if not (network_type_set or physical_network_set or
|
||||
segmentation_id_set):
|
||||
return
|
||||
|
||||
msg = _("plugin does not support updating provider attributes")
|
||||
raise q_exc.InvalidInput(error_message=msg)
|
||||
|
||||
def update_network(self, context, id, network):
|
||||
network_attrs = network['network']
|
||||
self._check_provider_update(context, network_attrs)
|
||||
provider._raise_if_updates_provider_attributes(network['network'])
|
||||
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
|
|
|
@ -358,22 +358,6 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
|
||||
return (network_type, physical_network, segmentation_id)
|
||||
|
||||
def _check_provider_update(self, context, attrs):
|
||||
network_type = attrs.get(provider.NETWORK_TYPE)
|
||||
physical_network = attrs.get(provider.PHYSICAL_NETWORK)
|
||||
segmentation_id = attrs.get(provider.SEGMENTATION_ID)
|
||||
|
||||
network_type_set = attributes.is_attr_set(network_type)
|
||||
physical_network_set = attributes.is_attr_set(physical_network)
|
||||
segmentation_id_set = attributes.is_attr_set(segmentation_id)
|
||||
|
||||
if not (network_type_set or physical_network_set or
|
||||
segmentation_id_set):
|
||||
return
|
||||
|
||||
msg = _("Plugin does not support updating provider attributes")
|
||||
raise q_exc.InvalidInput(error_message=msg)
|
||||
|
||||
def create_network(self, context, network):
|
||||
(network_type, physical_network,
|
||||
vlan_id) = self._process_provider_create(context,
|
||||
|
@ -412,7 +396,7 @@ class LinuxBridgePluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
return net
|
||||
|
||||
def update_network(self, context, id, network):
|
||||
self._check_provider_update(context, network['network'])
|
||||
provider._raise_if_updates_provider_attributes(network['network'])
|
||||
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
|
|
|
@ -134,13 +134,6 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
value = None
|
||||
return value
|
||||
|
||||
def _check_provider_update(self, context, attrs):
|
||||
if (attributes.is_attr_set(attrs.get(provider.NETWORK_TYPE)) or
|
||||
attributes.is_attr_set(attrs.get(provider.PHYSICAL_NETWORK)) or
|
||||
attributes.is_attr_set(attrs.get(provider.SEGMENTATION_ID))):
|
||||
msg = _("Plugin does not support updating provider attributes")
|
||||
raise exc.InvalidInput(error_message=msg)
|
||||
|
||||
def _extend_network_dict_provider(self, context, network):
|
||||
id = network['id']
|
||||
segments = db.get_network_segments(context.session, id)
|
||||
|
@ -213,14 +206,13 @@ class Ml2Plugin(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
return result
|
||||
|
||||
def update_network(self, context, id, network):
|
||||
attrs = network['network']
|
||||
self._check_provider_update(context, attrs)
|
||||
provider._raise_if_updates_provider_attributes(network['network'])
|
||||
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
result = super(Ml2Plugin, self).update_network(context, id,
|
||||
network)
|
||||
self._process_l3_update(context, attrs, id)
|
||||
self._process_l3_update(context, network['network'], id)
|
||||
self._extend_network_dict_provider(context, result)
|
||||
self._extend_network_dict_l3(context, result)
|
||||
|
||||
|
|
|
@ -219,21 +219,6 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
raise q_exc.InvalidInput(error_message=msg)
|
||||
return physical_network
|
||||
|
||||
def _check_provider_update(self, context, attrs):
|
||||
network_type = attrs.get(provider.NETWORK_TYPE)
|
||||
physical_network = attrs.get(provider.PHYSICAL_NETWORK)
|
||||
segmentation_id = attrs.get(provider.SEGMENTATION_ID)
|
||||
|
||||
network_type_set = attributes.is_attr_set(network_type)
|
||||
physical_network_set = attributes.is_attr_set(physical_network)
|
||||
segmentation_id_set = attributes.is_attr_set(segmentation_id)
|
||||
|
||||
if not (network_type_set or physical_network_set or
|
||||
segmentation_id_set):
|
||||
return
|
||||
msg = _("Plugin does not support updating provider attributes")
|
||||
raise q_exc.InvalidInput(error_message=msg)
|
||||
|
||||
def _process_port_binding_create(self, context, attrs):
|
||||
binding_profile = attrs.get(portbindings.PROFILE)
|
||||
binding_profile_set = attributes.is_attr_set(binding_profile)
|
||||
|
@ -288,7 +273,7 @@ class MellanoxEswitchPlugin(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
return net
|
||||
|
||||
def update_network(self, context, net_id, network):
|
||||
self._check_provider_update(context, network['network'])
|
||||
provider._raise_if_updates_provider_attributes(network['network'])
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
net = super(MellanoxEswitchPlugin, self).update_network(context,
|
||||
|
|
|
@ -1036,6 +1036,7 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
return quantum_lswitches
|
||||
|
||||
def update_network(self, context, id, network):
|
||||
pnet._raise_if_updates_provider_attributes(network['network'])
|
||||
if network["network"].get("admin_state_up"):
|
||||
if network['network']["admin_state_up"] is False:
|
||||
raise q_exc.NotImplementedError(_("admin_state_up=False "
|
||||
|
|
|
@ -420,22 +420,6 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
|
||||
return (network_type, physical_network, segmentation_id)
|
||||
|
||||
def _check_provider_update(self, context, attrs):
|
||||
network_type = attrs.get(provider.NETWORK_TYPE)
|
||||
physical_network = attrs.get(provider.PHYSICAL_NETWORK)
|
||||
segmentation_id = attrs.get(provider.SEGMENTATION_ID)
|
||||
|
||||
network_type_set = attributes.is_attr_set(network_type)
|
||||
physical_network_set = attributes.is_attr_set(physical_network)
|
||||
segmentation_id_set = attributes.is_attr_set(segmentation_id)
|
||||
|
||||
if not (network_type_set or physical_network_set or
|
||||
segmentation_id_set):
|
||||
return
|
||||
|
||||
msg = _("Plugin does not support updating provider attributes")
|
||||
raise q_exc.InvalidInput(error_message=msg)
|
||||
|
||||
def create_network(self, context, network):
|
||||
(network_type, physical_network,
|
||||
segmentation_id) = self._process_provider_create(context,
|
||||
|
@ -480,7 +464,7 @@ class OVSQuantumPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
|
|||
return net
|
||||
|
||||
def update_network(self, context, id, network):
|
||||
self._check_provider_update(context, network['network'])
|
||||
provider._raise_if_updates_provider_attributes(network['network'])
|
||||
|
||||
session = context.session
|
||||
with session.begin(subtransactions=True):
|
||||
|
|
Loading…
Reference in New Issue