'sfc' and 'flowclassifier' API extension definitions (networking-sfc)
Adds the API definitions for the 'sfc' and 'flow_classifier' API extensions from networking-sfc. Co-Authored-By: Thomas Morin <thomas.morin@orange.com> Needed-By: I4958fb7b47050a76618183ab4f938622d95c8a0c Change-Id: Id5aea04553b78dd17fca85de88cf076b42d24140
This commit is contained in:
parent
d6cb64165c
commit
a508fa127c
@ -152,6 +152,15 @@ def convert_none_to_empty_dict(value):
|
|||||||
return {} if value is None else value
|
return {} if value is None else value
|
||||||
|
|
||||||
|
|
||||||
|
def convert_none_to_empty_string(value):
|
||||||
|
"""Convert the value to an empty string if it's None.
|
||||||
|
|
||||||
|
:param value: The value to convert.
|
||||||
|
:returns: An empty string if 'value' is None, otherwise 'value'.
|
||||||
|
"""
|
||||||
|
return '' if value is None else value
|
||||||
|
|
||||||
|
|
||||||
def convert_to_list(data):
|
def convert_to_list(data):
|
||||||
"""Convert a value into a list.
|
"""Convert a value into a list.
|
||||||
|
|
||||||
@ -263,3 +272,37 @@ def convert_to_string(data):
|
|||||||
|
|
||||||
if data is not None:
|
if data is not None:
|
||||||
return str(data)
|
return str(data)
|
||||||
|
|
||||||
|
|
||||||
|
def convert_prefix_forced_case(data, prefix):
|
||||||
|
"""If <prefix> is a prefix of data, case insensitive, then force its case
|
||||||
|
|
||||||
|
This converter forces the case of a given prefix of a string.
|
||||||
|
|
||||||
|
Example, with prefix="Foo":
|
||||||
|
* 'foobar' converted into 'Foobar'
|
||||||
|
* 'fOozar' converted into 'Foozar'
|
||||||
|
* 'FOObaz' converted into 'Foobaz'
|
||||||
|
|
||||||
|
:param data: The data to convert
|
||||||
|
:returns: if data is a string starting with <prefix> in a case insensitive
|
||||||
|
comparison, then the return value is data with this prefix
|
||||||
|
replaced by <prefix>
|
||||||
|
"""
|
||||||
|
plen = len(prefix)
|
||||||
|
if (isinstance(data, six.string_types) and len(data) >= plen and
|
||||||
|
data[0:plen].lower() == prefix.lower()):
|
||||||
|
return prefix + data[plen:]
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def convert_uppercase_ip(data):
|
||||||
|
"""Uppercase "ip" if present at start of data case-insensitive
|
||||||
|
|
||||||
|
Can be used for instance to accept both "ipv4" and "IPv4".
|
||||||
|
|
||||||
|
:param data: The data to convert
|
||||||
|
:returns: if data is a string starting with "ip" case insensitive, then
|
||||||
|
the return value is data with the first two letter uppercased
|
||||||
|
"""
|
||||||
|
return convert_prefix_forced_case(data, "IP")
|
||||||
|
@ -33,6 +33,7 @@ from neutron_lib.api.definitions import firewall
|
|||||||
from neutron_lib.api.definitions import firewall_v2
|
from neutron_lib.api.definitions import firewall_v2
|
||||||
from neutron_lib.api.definitions import firewallrouterinsertion
|
from neutron_lib.api.definitions import firewallrouterinsertion
|
||||||
from neutron_lib.api.definitions import flavors
|
from neutron_lib.api.definitions import flavors
|
||||||
|
from neutron_lib.api.definitions import flowclassifier
|
||||||
from neutron_lib.api.definitions import ip_allocation
|
from neutron_lib.api.definitions import ip_allocation
|
||||||
from neutron_lib.api.definitions import ip_substring_port_filtering
|
from neutron_lib.api.definitions import ip_substring_port_filtering
|
||||||
from neutron_lib.api.definitions import l2_adjacency
|
from neutron_lib.api.definitions import l2_adjacency
|
||||||
@ -66,6 +67,7 @@ from neutron_lib.api.definitions import router_interface_fip
|
|||||||
from neutron_lib.api.definitions import routerservicetype
|
from neutron_lib.api.definitions import routerservicetype
|
||||||
from neutron_lib.api.definitions import segment
|
from neutron_lib.api.definitions import segment
|
||||||
from neutron_lib.api.definitions import servicetype
|
from neutron_lib.api.definitions import servicetype
|
||||||
|
from neutron_lib.api.definitions import sfc
|
||||||
from neutron_lib.api.definitions import sorting
|
from neutron_lib.api.definitions import sorting
|
||||||
from neutron_lib.api.definitions import subnet
|
from neutron_lib.api.definitions import subnet
|
||||||
from neutron_lib.api.definitions import subnet_onboard
|
from neutron_lib.api.definitions import subnet_onboard
|
||||||
@ -106,6 +108,7 @@ _ALL_API_DEFINITIONS = {
|
|||||||
ip_allocation,
|
ip_allocation,
|
||||||
ip_substring_port_filtering,
|
ip_substring_port_filtering,
|
||||||
l2_adjacency,
|
l2_adjacency,
|
||||||
|
flowclassifier,
|
||||||
l3,
|
l3,
|
||||||
l3_ext_gw_mode,
|
l3_ext_gw_mode,
|
||||||
l3_ext_ha_mode,
|
l3_ext_ha_mode,
|
||||||
@ -136,6 +139,7 @@ _ALL_API_DEFINITIONS = {
|
|||||||
routerservicetype,
|
routerservicetype,
|
||||||
segment,
|
segment,
|
||||||
servicetype,
|
servicetype,
|
||||||
|
sfc,
|
||||||
sorting,
|
sorting,
|
||||||
subnet,
|
subnet,
|
||||||
subnet_onboard,
|
subnet_onboard,
|
||||||
|
@ -138,6 +138,10 @@ KNOWN_EXTENSIONS = (
|
|||||||
'vpnaas',
|
'vpnaas',
|
||||||
'vpn-endpoint-groups',
|
'vpn-endpoint-groups',
|
||||||
'vpn-flavors',
|
'vpn-flavors',
|
||||||
|
|
||||||
|
# http://git.openstack.org/cgit/openstack/networking-sfc:
|
||||||
|
'flow_classifier',
|
||||||
|
'sfc',
|
||||||
)
|
)
|
||||||
|
|
||||||
KNOWN_KEYWORDS = (
|
KNOWN_KEYWORDS = (
|
||||||
|
173
neutron_lib/api/definitions/flowclassifier.py
Normal file
173
neutron_lib/api/definitions/flowclassifier.py
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
# Copyright 2015 Futurewei. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.api import converters
|
||||||
|
from neutron_lib import constants
|
||||||
|
from neutron_lib.db import constants as db_const
|
||||||
|
|
||||||
|
# The alias of the extension.
|
||||||
|
ALIAS = 'flow_classifier'
|
||||||
|
|
||||||
|
# Whether or not this extension is simply signaling behavior to the user
|
||||||
|
# or it actively modifies the attribute map.
|
||||||
|
IS_SHIM_EXTENSION = False
|
||||||
|
|
||||||
|
# Whether the extension is marking the adoption of standardattr model for
|
||||||
|
# legacy resources, or introducing new standardattr attributes. False or
|
||||||
|
# None if the standardattr model is adopted since the introduction of
|
||||||
|
# resource extension.
|
||||||
|
# If this is True, the alias for the extension should be prefixed with
|
||||||
|
# 'standard-attr-'.
|
||||||
|
IS_STANDARD_ATTR_EXTENSION = False
|
||||||
|
|
||||||
|
# The name of the extension.
|
||||||
|
NAME = 'Flow Classifier'
|
||||||
|
|
||||||
|
# A prefix for API resources. An empty prefix means that the API is going
|
||||||
|
# to be exposed at the v2/ level as any other core resource.
|
||||||
|
API_PREFIX = '/sfc'
|
||||||
|
|
||||||
|
# The description of the extension.
|
||||||
|
DESCRIPTION = ("API for selection of packets to direct through service "
|
||||||
|
"function chains")
|
||||||
|
|
||||||
|
# A timestamp of when the extension was last updated.
|
||||||
|
UPDATED_TIMESTAMP = "2015-10-05T10:00:00-00:00"
|
||||||
|
|
||||||
|
|
||||||
|
FC_SUPPORTED_ETHERTYPES = [constants.IPv4, constants.IPv6]
|
||||||
|
|
||||||
|
|
||||||
|
RESOURCE_NAME = 'flow_classifier'
|
||||||
|
COLLECTION_NAME = 'flow_classifiers'
|
||||||
|
|
||||||
|
|
||||||
|
# Attribute Map
|
||||||
|
RESOURCE_ATTRIBUTE_MAP = {
|
||||||
|
COLLECTION_NAME: {
|
||||||
|
'id': {
|
||||||
|
'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None},
|
||||||
|
'primary_key': True},
|
||||||
|
'name': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
|
||||||
|
'convert_to': converters.convert_none_to_empty_string},
|
||||||
|
'description': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:string': db_const.DESCRIPTION_FIELD_SIZE},
|
||||||
|
'convert_to': converters.convert_none_to_empty_string},
|
||||||
|
'tenant_id': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE},
|
||||||
|
'required_by_policy': True},
|
||||||
|
'ethertype': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': "IPv4",
|
||||||
|
'default_overrides_none': True,
|
||||||
|
'validate': {'type:values': FC_SUPPORTED_ETHERTYPES},
|
||||||
|
'convert_to': converters.convert_uppercase_ip},
|
||||||
|
'protocol': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'convert_to': converters.convert_to_protocol},
|
||||||
|
'source_port_range_min': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'validate': {'type:range_or_none': [0, constants.PORT_MAX]}},
|
||||||
|
'source_port_range_max': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'validate': {'type:range_or_none': [0, constants.PORT_MAX]}},
|
||||||
|
'destination_port_range_min': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'validate': {'type:range_or_none': [0, constants.PORT_MAX]}},
|
||||||
|
'destination_port_range_max': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'validate': {'type:range_or_none': [0, constants.PORT_MAX]}},
|
||||||
|
'source_ip_prefix': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:subnet_or_none': None}},
|
||||||
|
'destination_ip_prefix': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:subnet_or_none': None}},
|
||||||
|
'logical_source_port': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:uuid_or_none': None}},
|
||||||
|
'logical_destination_port': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:uuid_or_none': None}},
|
||||||
|
'l7_parameters': {
|
||||||
|
# NOTE(tmorin): at this point, there is no clean way to extend
|
||||||
|
# this attribute; it seems only used by GBP (by monkeypatching it
|
||||||
|
# at runtime, see
|
||||||
|
# http://codesearch.openstack.org/?q=AIM_FLC_L7_PARAMS)
|
||||||
|
# So let's support the GBP fields by now, but consider that
|
||||||
|
# future additions will need to happen via proper API extensions
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'default': {}, 'default_overrides_none': True,
|
||||||
|
'convert_to': converters.convert_none_to_empty_dict,
|
||||||
|
'validate': {
|
||||||
|
'type:dict': {
|
||||||
|
'logical_source_network': {
|
||||||
|
'default': None,
|
||||||
|
'type:uuid_or_none': None
|
||||||
|
},
|
||||||
|
'logical_destination_network': {
|
||||||
|
'default': None,
|
||||||
|
'type:uuid_or_none': None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
# The subresource attribute map for the extension. It adds child resources
|
||||||
|
# to main extension's resource. The subresource map must have a parent and
|
||||||
|
# a parameters entry. If an extension does not need such a map, None can
|
||||||
|
# be specified (mandatory).
|
||||||
|
SUB_RESOURCE_ATTRIBUTE_MAP = None
|
||||||
|
|
||||||
|
# The action map: it associates verbs with methods to be performed on
|
||||||
|
# the API resource.
|
||||||
|
ACTION_MAP = {
|
||||||
|
}
|
||||||
|
|
||||||
|
# The action status.
|
||||||
|
ACTION_STATUS = {
|
||||||
|
}
|
||||||
|
|
||||||
|
# The list of required extensions.
|
||||||
|
REQUIRED_EXTENSIONS = [
|
||||||
|
]
|
||||||
|
|
||||||
|
# The list of optional extensions.
|
||||||
|
OPTIONAL_EXTENSIONS = [
|
||||||
|
]
|
281
neutron_lib/api/definitions/sfc.py
Normal file
281
neutron_lib/api/definitions/sfc.py
Normal file
@ -0,0 +1,281 @@
|
|||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.api import converters
|
||||||
|
from neutron_lib.api.definitions import flowclassifier as fc_api
|
||||||
|
from neutron_lib import constants
|
||||||
|
from neutron_lib.db import constants as db_const
|
||||||
|
|
||||||
|
# The alias of the extension.
|
||||||
|
ALIAS = 'sfc'
|
||||||
|
|
||||||
|
# Whether or not this extension is simply signaling behavior to the user
|
||||||
|
# or it actively modifies the attribute map.
|
||||||
|
IS_SHIM_EXTENSION = False
|
||||||
|
|
||||||
|
# Whether the extension is marking the adoption of standardattr model for
|
||||||
|
# legacy resources, or introducing new standardattr attributes. False or
|
||||||
|
# None if the standardattr model is adopted since the introduction of
|
||||||
|
# resource extension.
|
||||||
|
# If this is True, the alias for the extension should be prefixed with
|
||||||
|
# 'standard-attr-'.
|
||||||
|
IS_STANDARD_ATTR_EXTENSION = False
|
||||||
|
|
||||||
|
# The name of the extension.
|
||||||
|
NAME = 'Service Function Chaining'
|
||||||
|
|
||||||
|
# The description of the extension.
|
||||||
|
DESCRIPTION = "Provides support for Service Function Chaining"
|
||||||
|
|
||||||
|
# A timestamp of when the extension was last updated.
|
||||||
|
UPDATED_TIMESTAMP = "2015-10-05T10:00:00-00:00"
|
||||||
|
|
||||||
|
API_PREFIX = '/sfc'
|
||||||
|
|
||||||
|
# Service Function Chaining constants
|
||||||
|
PORT_PAIRS = 'port_pairs'
|
||||||
|
PORT_PAIR_GROUPS = 'port_pair_groups'
|
||||||
|
PORT_CHAINS = 'port_chains'
|
||||||
|
MAX_CHAIN_ID = 65535
|
||||||
|
|
||||||
|
MPLS = 'mpls'
|
||||||
|
NSH = 'nsh'
|
||||||
|
|
||||||
|
PPG_N_TUPLE_DICT_SPEC = {
|
||||||
|
'source_ip_prefix': {
|
||||||
|
'default': None,
|
||||||
|
'type:subnet_or_none': None
|
||||||
|
},
|
||||||
|
'destination_ip_prefix': {
|
||||||
|
'default': None,
|
||||||
|
'type:subnet_or_none': None
|
||||||
|
},
|
||||||
|
'source_port_range_min': {
|
||||||
|
'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'type:range_or_none': [0, constants.PORT_MAX]
|
||||||
|
},
|
||||||
|
'source_port_range_max': {
|
||||||
|
'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'type:range_or_none': [0, constants.PORT_MAX]
|
||||||
|
},
|
||||||
|
'destination_port_range_min': {
|
||||||
|
'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'type:range_or_none': [0, constants.PORT_MAX]
|
||||||
|
},
|
||||||
|
'destination_port_range_max': {
|
||||||
|
'default': None,
|
||||||
|
'convert_to': converters.convert_to_int_if_not_none,
|
||||||
|
'type:range_or_none': [0, constants.PORT_MAX]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# The resource attribute map for the extension.
|
||||||
|
RESOURCE_ATTRIBUTE_MAP = {
|
||||||
|
PORT_PAIRS: {
|
||||||
|
'id': {
|
||||||
|
'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None},
|
||||||
|
'primary_key': True
|
||||||
|
},
|
||||||
|
'name': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'description': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.DESCRIPTION_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'tenant_id': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE},
|
||||||
|
'required_by_policy': True
|
||||||
|
},
|
||||||
|
'ingress': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None}
|
||||||
|
},
|
||||||
|
'egress': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None}
|
||||||
|
},
|
||||||
|
'service_function_parameters': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'dict_populate_defaults': True,
|
||||||
|
'validate': {
|
||||||
|
'type:dict': {
|
||||||
|
'correlation': {
|
||||||
|
'type:values': [None, MPLS, NSH],
|
||||||
|
'default': None
|
||||||
|
},
|
||||||
|
'weight': {
|
||||||
|
'type:non_negative': None,
|
||||||
|
'default': 1,
|
||||||
|
'convert_to': converters.convert_to_int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PORT_PAIR_GROUPS: {
|
||||||
|
'id': {
|
||||||
|
'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None},
|
||||||
|
'primary_key': True},
|
||||||
|
'group_id': {
|
||||||
|
'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True
|
||||||
|
},
|
||||||
|
'name': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'description': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.DESCRIPTION_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'tenant_id': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE},
|
||||||
|
'required_by_policy': True
|
||||||
|
},
|
||||||
|
'port_pairs': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:uuid_list': None},
|
||||||
|
'convert_to': converters.convert_none_to_empty_list
|
||||||
|
},
|
||||||
|
'port_pair_group_parameters': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'dict_populate_defaults': True,
|
||||||
|
'validate': {
|
||||||
|
'type:dict': {
|
||||||
|
'lb_fields': {
|
||||||
|
'type:list_of_regex_or_none':
|
||||||
|
'eth|ip|tcp|udp)_(src|dst)',
|
||||||
|
'default': []
|
||||||
|
},
|
||||||
|
'ppg_n_tuple_mapping': {
|
||||||
|
'dict_populate_defaults': True,
|
||||||
|
'type:dict': {
|
||||||
|
'ingress_n_tuple': {
|
||||||
|
'type:dict': PPG_N_TUPLE_DICT_SPEC,
|
||||||
|
'default': {}
|
||||||
|
},
|
||||||
|
'egress_n_tuple': {
|
||||||
|
'type:dict': PPG_N_TUPLE_DICT_SPEC,
|
||||||
|
'default': {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PORT_CHAINS: {
|
||||||
|
'id': {
|
||||||
|
'allow_post': False, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid': None},
|
||||||
|
'primary_key': True
|
||||||
|
},
|
||||||
|
'chain_id': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True, 'default': 0,
|
||||||
|
'validate': {'type:range': (0, MAX_CHAIN_ID)},
|
||||||
|
'convert_to': converters.convert_to_int
|
||||||
|
},
|
||||||
|
'name': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.NAME_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'description': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': '',
|
||||||
|
'validate': {'type:string': db_const.DESCRIPTION_FIELD_SIZE},
|
||||||
|
},
|
||||||
|
'tenant_id': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:string': db_const.PROJECT_ID_FIELD_SIZE},
|
||||||
|
'required_by_policy': True
|
||||||
|
},
|
||||||
|
'port_pair_groups': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True,
|
||||||
|
'validate': {'type:uuid_list_non_empty': None},
|
||||||
|
'default': None
|
||||||
|
},
|
||||||
|
'flow_classifiers': {
|
||||||
|
'allow_post': True, 'allow_put': True,
|
||||||
|
'is_visible': True, 'default': None,
|
||||||
|
'validate': {'type:uuid_list': None},
|
||||||
|
'convert_to': converters.convert_to_list
|
||||||
|
},
|
||||||
|
'chain_parameters': {
|
||||||
|
'allow_post': True, 'allow_put': False,
|
||||||
|
'is_visible': True,
|
||||||
|
'dict_populate_defaults': True,
|
||||||
|
'validate': {
|
||||||
|
'type:dict': {
|
||||||
|
'correlation': {
|
||||||
|
'type:values': [MPLS, NSH],
|
||||||
|
'default': MPLS
|
||||||
|
},
|
||||||
|
'symmetric': {
|
||||||
|
'type:boolean': None,
|
||||||
|
'default': False,
|
||||||
|
'convert_to': converters.convert_to_boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# The subresource attribute map for the extension. It adds child resources
|
||||||
|
# to main extension's resource. The subresource map must have a parent and
|
||||||
|
# a parameters entry. If an extension does not need such a map, None can
|
||||||
|
# be specified (mandatory).
|
||||||
|
SUB_RESOURCE_ATTRIBUTE_MAP = None
|
||||||
|
|
||||||
|
# The action map.
|
||||||
|
ACTION_MAP = {
|
||||||
|
}
|
||||||
|
|
||||||
|
ACTION_STATUS = {
|
||||||
|
}
|
||||||
|
# The list of required extensions.
|
||||||
|
REQUIRED_EXTENSIONS = [
|
||||||
|
fc_api.ALIAS,
|
||||||
|
]
|
||||||
|
|
||||||
|
# The list of optional extensions.
|
||||||
|
OPTIONAL_EXTENSIONS = [
|
||||||
|
]
|
@ -117,6 +117,17 @@ def _validate_list_of_items(item_validator, data, *args, **kwargs):
|
|||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_list_of_items_non_empty(item_validator, data, *args, **kwargs):
|
||||||
|
res = _validate_list_of_items(item_validator, data, *args, **kwargs)
|
||||||
|
|
||||||
|
if res is not None:
|
||||||
|
return res
|
||||||
|
|
||||||
|
if len(data) == 0:
|
||||||
|
msg = _("List should not be empty")
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def validate_values(data, valid_values=None, valid_values_display=None):
|
def validate_values(data, valid_values=None, valid_values_display=None):
|
||||||
"""Validate that the provided 'data' is within 'valid_values'.
|
"""Validate that the provided 'data' is within 'valid_values'.
|
||||||
|
|
||||||
@ -805,6 +816,18 @@ def validate_uuid_list(data, valid_values=None):
|
|||||||
return _validate_uuid_list(data, valid_values)
|
return _validate_uuid_list(data, valid_values)
|
||||||
|
|
||||||
|
|
||||||
|
def validate_uuid_list_non_empty(data, valid_values=None):
|
||||||
|
"""Validate data is a non-empty list of UUID like values.
|
||||||
|
|
||||||
|
:param data: The data to validate.
|
||||||
|
:param valid_values: Not used!
|
||||||
|
:returns: None if data is a non-empty iterable that contains valid UUID
|
||||||
|
values, otherwise a message is returned indicating why validation
|
||||||
|
failed.
|
||||||
|
"""
|
||||||
|
return _validate_list_of_items_non_empty(validate_uuid, data)
|
||||||
|
|
||||||
|
|
||||||
def _extract_validator(key_validator):
|
def _extract_validator(key_validator):
|
||||||
# Find validator function in key validation spec
|
# Find validator function in key validation spec
|
||||||
#
|
#
|
||||||
@ -1089,6 +1112,7 @@ validators = {'type:dict': validate_dict,
|
|||||||
'type:uuid': validate_uuid,
|
'type:uuid': validate_uuid,
|
||||||
'type:uuid_or_none': validate_uuid_or_none,
|
'type:uuid_or_none': validate_uuid_or_none,
|
||||||
'type:uuid_list': validate_uuid_list,
|
'type:uuid_list': validate_uuid_list,
|
||||||
|
'type:uuid_list_non_empty': validate_uuid_list_non_empty,
|
||||||
'type:values': validate_values,
|
'type:values': validate_values,
|
||||||
'type:boolean': validate_boolean,
|
'type:boolean': validate_boolean,
|
||||||
'type:integer': validate_integer,
|
'type:integer': validate_integer,
|
||||||
@ -1096,7 +1120,7 @@ validators = {'type:dict': validate_dict,
|
|||||||
'type:list_of_any_key_specs_or_none':
|
'type:list_of_any_key_specs_or_none':
|
||||||
validate_any_key_specs_or_none,
|
validate_any_key_specs_or_none,
|
||||||
'type:service_plugin_type': validate_service_plugin_type,
|
'type:service_plugin_type': validate_service_plugin_type,
|
||||||
'type:list_of_subnets_or_none': validate_subnet_list_or_none,
|
'type:list_of_subnets_or_none': validate_subnet_list_or_none
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -318,6 +318,9 @@ DNS_DOMAIN_DEFAULT = 'openstacklocal.'
|
|||||||
DNS_LABEL_MAX_LEN = 63
|
DNS_LABEL_MAX_LEN = 63
|
||||||
DNS_LABEL_REGEX = "^[a-z0-9-]{1,%d}$" % DNS_LABEL_MAX_LEN
|
DNS_LABEL_REGEX = "^[a-z0-9-]{1,%d}$" % DNS_LABEL_MAX_LEN
|
||||||
|
|
||||||
|
# max value for TCP, UDP, SCTP ports
|
||||||
|
PORT_MAX = 2**16 - 1
|
||||||
|
|
||||||
VALID_DSCP_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34,
|
VALID_DSCP_MARKS = [0, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34,
|
||||||
36, 38, 40, 46, 48, 56]
|
36, 38, 40, 46, 48, 56]
|
||||||
|
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.api.definitions import flowclassifier
|
||||||
|
from neutron_lib.tests.unit.api.definitions import base
|
||||||
|
|
||||||
|
|
||||||
|
class FlowClassifierDefinitionTestCase(base.DefinitionBaseTestCase):
|
||||||
|
extension_module = flowclassifier
|
||||||
|
extension_resources = (flowclassifier.COLLECTION_NAME,)
|
||||||
|
extension_attributes = ('ethertype',
|
||||||
|
'protocol',
|
||||||
|
'source_port_range_min',
|
||||||
|
'source_port_range_max',
|
||||||
|
'destination_port_range_min',
|
||||||
|
'destination_port_range_max',
|
||||||
|
'source_ip_prefix',
|
||||||
|
'destination_ip_prefix',
|
||||||
|
'logical_destination_port',
|
||||||
|
'logical_source_port',
|
||||||
|
'l7_parameters')
|
28
neutron_lib/tests/unit/api/definitions/test_sfc.py
Normal file
28
neutron_lib/tests/unit/api/definitions/test_sfc.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from neutron_lib.api.definitions import sfc
|
||||||
|
from neutron_lib.tests.unit.api.definitions import base
|
||||||
|
|
||||||
|
|
||||||
|
class SFCDefinitionTestCase(base.DefinitionBaseTestCase):
|
||||||
|
extension_module = sfc
|
||||||
|
extension_resources = tuple(sfc.RESOURCE_ATTRIBUTE_MAP.keys())
|
||||||
|
extension_attributes = ( # from port_pair:
|
||||||
|
'type', 'ingress', 'egress',
|
||||||
|
'service_function_parameters',
|
||||||
|
# from port_pair_group:
|
||||||
|
'group_id', 'port_pairs',
|
||||||
|
'port_pair_group_parameters',
|
||||||
|
# from port_chain:
|
||||||
|
'chain_id', 'port_pair_groups',
|
||||||
|
'flow_classifiers', 'chain_parameters')
|
@ -298,3 +298,36 @@ class TestConvertToString(base.BaseTestCase):
|
|||||||
def test_data_is_dict(self):
|
def test_data_is_dict(self):
|
||||||
self.assertEqual("{'foo': 'bar'}",
|
self.assertEqual("{'foo': 'bar'}",
|
||||||
converters.convert_to_string({'foo': 'bar'}))
|
converters.convert_to_string({'foo': 'bar'}))
|
||||||
|
|
||||||
|
|
||||||
|
class TestConvertUppercasePrefix(base.BaseTestCase):
|
||||||
|
|
||||||
|
def test_prefix_not_present(self):
|
||||||
|
self.assertEqual('foobar',
|
||||||
|
converters.convert_prefix_forced_case('foobar',
|
||||||
|
'bar'))
|
||||||
|
|
||||||
|
def test_prefix_no_need_to_replace(self):
|
||||||
|
self.assertEqual('FOObar',
|
||||||
|
converters.convert_prefix_forced_case('FOObar',
|
||||||
|
'FOO'))
|
||||||
|
|
||||||
|
def test_ucfirst_prefix_converted_1(self):
|
||||||
|
self.assertEqual('Foobar',
|
||||||
|
converters.convert_prefix_forced_case('foobar',
|
||||||
|
'Foo'))
|
||||||
|
|
||||||
|
def test_lc_prefix_converted_2(self):
|
||||||
|
self.assertEqual('foobar',
|
||||||
|
converters.convert_prefix_forced_case('fOobar',
|
||||||
|
'foo'))
|
||||||
|
|
||||||
|
def test_mixed_prefix_converted_1(self):
|
||||||
|
self.assertEqual('fOoXbar',
|
||||||
|
converters.convert_prefix_forced_case('Fooxbar',
|
||||||
|
'fOoX'))
|
||||||
|
|
||||||
|
def test_shorter_string(self):
|
||||||
|
self.assertEqual('fo',
|
||||||
|
converters.convert_prefix_forced_case('fo',
|
||||||
|
'foo'))
|
||||||
|
@ -856,6 +856,16 @@ class TestAttributeValidation(base.BaseTestCase):
|
|||||||
mock.Mock(return_value=None), list_obj)
|
mock.Mock(return_value=None), list_obj)
|
||||||
self.assertIsNone(msg)
|
self.assertIsNone(msg)
|
||||||
|
|
||||||
|
def test__test__validate_list_of_items_non_empty(self):
|
||||||
|
items = None
|
||||||
|
msg = validators._validate_list_of_items_non_empty(mock.Mock(), items)
|
||||||
|
error = "'%s' is not a list" % items
|
||||||
|
self.assertEqual(error, msg)
|
||||||
|
|
||||||
|
items = []
|
||||||
|
msg = validators._validate_list_of_items_non_empty(mock.Mock(), items)
|
||||||
|
self.assertEqual("List should not be empty", msg)
|
||||||
|
|
||||||
def test_validate_dict_type(self):
|
def test_validate_dict_type(self):
|
||||||
for value in (None, True, '1', []):
|
for value in (None, True, '1', []):
|
||||||
self.assertEqual("'%s' is not a dictionary" % value,
|
self.assertEqual("'%s' is not a dictionary" % value,
|
||||||
|
11
releasenotes/notes/sfc-api-def-4f46632eadfe895a.yaml
Normal file
11
releasenotes/notes/sfc-api-def-4f46632eadfe895a.yaml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- Add the definitions for the ``sfc`` and ``flowclassifier`` API extensions
|
||||||
|
of the networking-sfc project.
|
||||||
|
- Add a ``convert_uppercase_ip`` converter, convenient to easily accept for
|
||||||
|
instance ``Ipv4``, ``IPv4`` and ``ipv4`` independently of the case of the
|
||||||
|
first two letters.
|
||||||
|
- And add a ``convert_prefix_forced_case`` converter, to allow forcing the
|
||||||
|
case of a string prefix
|
||||||
|
- Add a ``uuid_list_non_empty`` validator, that will validate that the
|
||||||
|
value is a non-empty list of UUIDs
|
Loading…
x
Reference in New Issue
Block a user