Merge "Refactor ml2 manager"
This commit is contained in:
commit
014b4be568
@ -21,7 +21,7 @@ from neutron.common import exceptions as n_exc
|
|||||||
NETWORK_TYPE = 'provider:network_type'
|
NETWORK_TYPE = 'provider:network_type'
|
||||||
PHYSICAL_NETWORK = 'provider:physical_network'
|
PHYSICAL_NETWORK = 'provider:physical_network'
|
||||||
SEGMENTATION_ID = 'provider:segmentation_id'
|
SEGMENTATION_ID = 'provider:segmentation_id'
|
||||||
|
ATTRIBUTES = (NETWORK_TYPE, PHYSICAL_NETWORK, SEGMENTATION_ID)
|
||||||
EXTENDED_ATTRIBUTES_2_0 = {
|
EXTENDED_ATTRIBUTES_2_0 = {
|
||||||
'networks': {
|
'networks': {
|
||||||
NETWORK_TYPE: {'allow_post': True, 'allow_put': True,
|
NETWORK_TYPE: {'allow_post': True, 'allow_put': True,
|
||||||
@ -49,8 +49,7 @@ def _raise_if_updates_provider_attributes(attrs):
|
|||||||
This method is used for plugins that do not support
|
This method is used for plugins that do not support
|
||||||
updating provider networks.
|
updating provider networks.
|
||||||
"""
|
"""
|
||||||
immutable = (NETWORK_TYPE, PHYSICAL_NETWORK, SEGMENTATION_ID)
|
if any(attributes.is_attr_set(attrs.get(a)) for a in ATTRIBUTES):
|
||||||
if any(attributes.is_attr_set(attrs.get(a)) for a in immutable):
|
|
||||||
msg = _("Plugin does not support updating provider attributes")
|
msg = _("Plugin does not support updating provider attributes")
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
|
@ -72,11 +72,9 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
|||||||
LOG.info(_LI("Tenant network_types: %s"), self.tenant_network_types)
|
LOG.info(_LI("Tenant network_types: %s"), self.tenant_network_types)
|
||||||
|
|
||||||
def _process_provider_segment(self, segment):
|
def _process_provider_segment(self, segment):
|
||||||
network_type = self._get_attribute(segment, provider.NETWORK_TYPE)
|
(network_type, physical_network,
|
||||||
physical_network = self._get_attribute(segment,
|
segmentation_id) = (self._get_attribute(segment, attr)
|
||||||
provider.PHYSICAL_NETWORK)
|
for attr in provider.ATTRIBUTES)
|
||||||
segmentation_id = self._get_attribute(segment,
|
|
||||||
provider.SEGMENTATION_ID)
|
|
||||||
|
|
||||||
if attributes.is_attr_set(network_type):
|
if attributes.is_attr_set(network_type):
|
||||||
segment = {api.NETWORK_TYPE: network_type,
|
segment = {api.NETWORK_TYPE: network_type,
|
||||||
@ -88,23 +86,19 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
|||||||
msg = _("network_type required")
|
msg = _("network_type required")
|
||||||
raise exc.InvalidInput(error_message=msg)
|
raise exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
|
def _get_segment_attributes(self, network):
|
||||||
|
return {attr: self._get_attribute(network, attr)
|
||||||
|
for attr in provider.ATTRIBUTES}
|
||||||
|
|
||||||
def _process_provider_create(self, network):
|
def _process_provider_create(self, network):
|
||||||
if any(attributes.is_attr_set(network.get(f))
|
if any(attributes.is_attr_set(network.get(attr))
|
||||||
for f in (provider.NETWORK_TYPE, provider.PHYSICAL_NETWORK,
|
for attr in provider.ATTRIBUTES):
|
||||||
provider.SEGMENTATION_ID)):
|
|
||||||
# Verify that multiprovider and provider attributes are not set
|
# Verify that multiprovider and provider attributes are not set
|
||||||
# at the same time.
|
# at the same time.
|
||||||
if attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
|
if attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
|
||||||
raise mpnet.SegmentsSetInConjunctionWithProviders()
|
raise mpnet.SegmentsSetInConjunctionWithProviders()
|
||||||
|
|
||||||
network_type = self._get_attribute(network, provider.NETWORK_TYPE)
|
segments = [self._get_segment_attributes(network)]
|
||||||
physical_network = self._get_attribute(network,
|
|
||||||
provider.PHYSICAL_NETWORK)
|
|
||||||
segmentation_id = self._get_attribute(network,
|
|
||||||
provider.SEGMENTATION_ID)
|
|
||||||
segments = [{provider.NETWORK_TYPE: network_type,
|
|
||||||
provider.PHYSICAL_NETWORK: physical_network,
|
|
||||||
provider.SEGMENTATION_ID: segmentation_id}]
|
|
||||||
return [self._process_provider_segment(s) for s in segments]
|
return [self._process_provider_segment(s) for s in segments]
|
||||||
elif attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
|
elif attributes.is_attr_set(network.get(mpnet.SEGMENTS)):
|
||||||
segments = [self._process_provider_segment(s)
|
segments = [self._process_provider_segment(s)
|
||||||
@ -125,9 +119,8 @@ class TypeManager(stevedore.named.NamedExtensionManager):
|
|||||||
segments = db.get_network_segments(context.session, id)
|
segments = db.get_network_segments(context.session, id)
|
||||||
if not segments:
|
if not segments:
|
||||||
LOG.error(_LE("Network %s has no segments"), id)
|
LOG.error(_LE("Network %s has no segments"), id)
|
||||||
network[provider.NETWORK_TYPE] = None
|
for attr in provider.ATTRIBUTES:
|
||||||
network[provider.PHYSICAL_NETWORK] = None
|
network[attr] = None
|
||||||
network[provider.SEGMENTATION_ID] = None
|
|
||||||
elif len(segments) > 1:
|
elif len(segments) > 1:
|
||||||
network[mpnet.SEGMENTS] = [
|
network[mpnet.SEGMENTS] = [
|
||||||
{provider.NETWORK_TYPE: segment[api.NETWORK_TYPE],
|
{provider.NETWORK_TYPE: segment[api.NETWORK_TYPE],
|
||||||
|
Loading…
Reference in New Issue
Block a user