neutron/neutron/extensions/_port_mac_address_regenerate_lib.py
Hongbin Lu 2b1d8ea4a2 Implement filter validation
Enforce validation on filter parameters on list requests.
If an API request contains an unknown or unsupported parameter,
the server will return a 400 response instead of silently ignoring
the invalid input.

In resource attributes map, all filter parameters are annotated by
the ``is_filter`` keyword. Attributes with is_filter set to True
are candidates for validation.

Enabling filter validation requires support from core plugin and
all service plugins so each plugin need to indicate if it supports
the validation by setting ``__filter_validation_support`` to True.
If this field is not set, the default is False and validation is
turned off. Right now, the ML2 plugin and all the in-tree service
plugin support filter validation. Out-of-tree plugins will have
filter validation disabled by default.

An API extension is introduced to allow API users to discover this
new API behavior. This feature can be disabled by cloud operators
if they choose to do that. If it is disabled, the extension won't
be presented.

Depends-On: Ic3ab5b3ffdc378d570678b9c967cb42b0c7a8a9b
Depends-On: I4397df1c35463a8b532afdc9c5d28b37224a37b4
Depends-On: I3f2e6e861adaeef81a1a5819a57b28f5c6281d80
Depends-On: I1189bc9a50308df5c7e18c329f3a1262c90b9e12
Depends-On: I057cd917628c77dd20c0ff7747936c3fec7b4844
Depends-On: I0b24a304cc3466a2c05426cdbb6f9d99f1797edd

Change-Id: I21bf8a752813802822fd9966dda6ab3b6c4abfdc
Partial-Bug: #1749820
2018-07-19 04:13:43 +00:00

62 lines
2.0 KiB
Python

# 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.
"""
TODO(hjensas): This module should be deleted once neutron-lib containing
Change-Id: Ibfcf179c2051d2bf47d4d1e62e8146cbee29fd64 is released.
"""
from neutron_lib.api.definitions import port as port_def
from neutron_lib import constants
from neutron_lib.utils import net as net_utils
from oslo_config import cfg
def convert_to_mac_if_none(data):
"""Convert to a random mac address if data is None
:param data: The data value
:return: Random mac address if data is None, else return data.
"""
if data is None:
return net_utils.get_random_mac(cfg.CONF.base_mac.split(':'))
return data
NAME = 'Neutron Port MAC address regenerate'
ALIAS = 'port-mac-address-regenerate'
DESCRIPTION = "Network port MAC address regenerate"
UPDATED_TIMESTAMP = "2018-05-03T10:00:00-00:00"
RESOURCE_ATTRIBUTE_MAP = {
port_def.COLLECTION_NAME: {
'mac_address': {'allow_post': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED,
'convert_to': convert_to_mac_if_none,
'validate': {'type:mac_address': None},
'enforce_policy': True,
'is_filter': True,
'is_sort_key': True,
'is_visible': True},
}
}
IS_SHIM_EXTENSION = False
IS_STANDARD_ATTR_EXTENSION = False
SUB_RESOURCE_ATTRIBUTE_MAP = {}
ACTION_MAP = {}
REQUIRED_EXTENSIONS = []
OPTIONAL_EXTENSIONS = []
ACTION_STATUS = {}