Commit I81748aa0e48b1275df3e1ea41b1d36a117d0097d added the l3 extension API definition to neutron-lib and commit I2324a3a02789c798248cab41c278a2d9981d24be rehomed the l3 exceptions, while Ifd79eb1a92853e49bd4ef028e7a7bd89811c6957 shims the l3 exceptions. This patch consumes the l3 api def by: - Removing the code from neutron that's now in lib. - Using lib's version of the code where applicable. - Tidying up the related unit tests as now that the l3 api def from lib is used the necessary fixture is already setup in the parent chain when setting up the unit test class. NeutronLibImpact Change-Id: If2e66e06b83e15ee2851ea2bc3b64ad366e675dd
96 lines
3.5 KiB
Python
96 lines
3.5 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.
|
|
|
|
from neutron_lib.api.definitions import l3 as l3_apidef
|
|
from neutron_lib.api.definitions import port as port_def
|
|
from neutron_lib.api.definitions import subnet as subnet_def
|
|
from neutron_lib.api.definitions import subnetpool as subnetpool_def
|
|
from neutron_lib.api import extensions as api_extensions
|
|
from neutron_lib.api import faults
|
|
from neutron_lib.plugins import directory
|
|
|
|
from neutron.api import extensions
|
|
from neutron.api.v2 import resource as api_resource
|
|
from neutron.extensions import tagging
|
|
|
|
|
|
# This extension is deprecated because tagging supports all resources
|
|
|
|
TAG_SUPPORTED_RESOURCES = {
|
|
# We shouldn't add new resources here. If more resources need to be tagged,
|
|
# we must add them in new extension.
|
|
subnet_def.COLLECTION_NAME: subnet_def.RESOURCE_NAME,
|
|
port_def.COLLECTION_NAME: port_def.RESOURCE_NAME,
|
|
subnetpool_def.COLLECTION_NAME: subnetpool_def.RESOURCE_NAME,
|
|
l3_apidef.ROUTERS: l3_apidef.ROUTER,
|
|
}
|
|
|
|
|
|
class TagExtController(tagging.TaggingController):
|
|
def __init__(self):
|
|
self.plugin = directory.get_plugin(tagging.TAG_PLUGIN_TYPE)
|
|
self.supported_resources = TAG_SUPPORTED_RESOURCES
|
|
|
|
|
|
class Tag_ext(api_extensions.ExtensionDescriptor):
|
|
"""Extension class supporting tags for ext resources."""
|
|
|
|
@classmethod
|
|
def get_name(cls):
|
|
return ("Tag support for resources: %s"
|
|
% ', '.join(TAG_SUPPORTED_RESOURCES.values()))
|
|
|
|
@classmethod
|
|
def get_alias(cls):
|
|
return "tag-ext"
|
|
|
|
@classmethod
|
|
def get_description(cls):
|
|
return "Extends tag support to more L2 and L3 resources."
|
|
|
|
@classmethod
|
|
def get_updated(cls):
|
|
return "2017-01-01T00:00:00-00:00"
|
|
|
|
@classmethod
|
|
def get_resources(cls):
|
|
"""Returns Ext Resources."""
|
|
exts = []
|
|
action_status = {'index': 200, 'show': 204, 'update': 201,
|
|
'update_all': 200, 'delete': 204, 'delete_all': 204}
|
|
controller = api_resource.Resource(TagExtController(),
|
|
faults.FAULT_MAP,
|
|
action_status=action_status)
|
|
collection_methods = {"delete_all": "DELETE",
|
|
"update_all": "PUT"}
|
|
exts = []
|
|
for collection_name, member_name in TAG_SUPPORTED_RESOURCES.items():
|
|
parent = {'member_name': member_name,
|
|
'collection_name': collection_name}
|
|
exts.append(extensions.ResourceExtension(
|
|
tagging.TAGS, controller, parent,
|
|
collection_methods=collection_methods))
|
|
return exts
|
|
|
|
def get_optional_extensions(self):
|
|
return ['router']
|
|
|
|
def get_extended_resources(self, version):
|
|
if version != "2.0":
|
|
return {}
|
|
EXTENDED_ATTRIBUTES_2_0 = {}
|
|
for collection_name in TAG_SUPPORTED_RESOURCES:
|
|
EXTENDED_ATTRIBUTES_2_0[collection_name] = (
|
|
tagging.TAG_ATTRIBUTE_MAP)
|
|
return EXTENDED_ATTRIBUTES_2_0
|