75 lines
2.7 KiB
Python
75 lines
2.7 KiB
Python
# Copyright 2016 Hewlett Packard Development Coompany LP
|
|
#
|
|
# 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.
|
|
#
|
|
import itertools
|
|
|
|
from neutron_lib import exceptions as n_exc
|
|
from neutron_lib.api import extensions as api_extensions
|
|
from neutron_lib.api.definitions import bgp
|
|
from neutron_lib.api.definitions import bgp_associations as bgp_ext
|
|
from neutron_lib.plugins import directory
|
|
|
|
from neutron.api import extensions
|
|
from neutron.api.v2 import resource_helper as rh
|
|
from neutron.api.v2 import base
|
|
|
|
from neutron_dynamic_routing._i18n import _
|
|
|
|
|
|
class Bgp_associations(api_extensions.APIExtensionDescriptor):
|
|
|
|
api_definition = bgp_ext
|
|
|
|
@classmethod
|
|
def get_resources(cls):
|
|
special_mappings = {'bgp-speakers': 'bgp-speaker'}
|
|
plural_mappings = rh.build_plural_mappings(
|
|
special_mappings, itertools.chain(
|
|
bgp_ext.RESOURCE_ATTRIBUTE_MAP,
|
|
bgp_ext.SUB_RESOURCE_ATTRIBUTE_MAP))
|
|
|
|
resources = rh.build_resource_info(
|
|
plural_mappings,
|
|
bgp_ext.RESOURCE_ATTRIBUTE_MAP,
|
|
bgp.ALIAS)
|
|
plugin = directory.get_plugin(bgp.ALIAS)
|
|
|
|
for sub_resource in bgp_ext.SUB_RESOURCE_ATTRIBUTE_MAP:
|
|
parent = bgp_ext.SUB_RESOURCE_ATTRIBUTE_MAP[
|
|
sub_resource].get('parent')
|
|
params = bgp_ext.SUB_RESOURCE_ATTRIBUTE_MAP[
|
|
sub_resource].get('parameters')
|
|
controller = base.create_resource(sub_resource, sub_resource[:-1],
|
|
plugin, params, allow_bulk=True,
|
|
parent=parent,
|
|
allow_pagination=True,
|
|
allow_sorting=True)
|
|
resource = extensions.ResourceExtension(
|
|
sub_resource,
|
|
controller, parent,
|
|
attr_map=params)
|
|
resources.append(resource)
|
|
|
|
return resources
|
|
|
|
|
|
#Bgp Association Exceptions
|
|
class BgpSpeakerRouterAssociationNotFound(n_exc.NotFound):
|
|
message = _("BGP speaker Router Association %(id)s could not be found.")
|
|
|
|
|
|
class BgpSpeakerPeerAssociationNotFound(n_exc.NotFound):
|
|
message = _("BGP speaker Peer Association %(id)s could not be found.")
|