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'
}
+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.
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):
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,
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):
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)
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)
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)
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,
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 "
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,
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):