| 1 |
# Copyright 2012 OpenStack Foundation |
| 2 |
# Copyright 2016 Hewlett Packard Enterprise Development Company |
| 3 |
# All Rights Reserved. |
| 4 |
# |
| 5 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 |
# not use this file except in compliance with the License. You may obtain |
| 7 |
# a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 |
# License for the specific language governing permissions and limitations |
| 15 |
# under the License. |
| 16 |
|
| 17 |
from neutron_tempest_plugin.api import clients as manager |
| 18 |
from neutron_tempest_plugin import config |
| 19 |
from neutron_tempest_plugin.services.network.json import network_client |
| 20 |
|
| 21 |
|
| 22 |
CONF = config.CONF |
| 23 |
|
| 24 |
|
| 25 |
class NetworkClient(network_client.NetworkClientJSON): |
| 26 |
|
| 27 |
def pluralize(self, resource_name): |
| 28 |
|
| 29 |
resource_plural_map = { |
| 30 |
'ikepolicy': 'ikepolicies', |
| 31 |
'ipsecpolicy': 'ipsecpolicies' |
| 32 |
} |
| 33 |
|
| 34 |
if resource_name in resource_plural_map: |
| 35 |
return resource_plural_map.get(resource_name) |
| 36 |
|
| 37 |
return super(NetworkClient, self).pluralize(resource_name) |
| 38 |
|
| 39 |
def get_uri(self, plural_name): |
| 40 |
# get service prefix from resource name |
| 41 |
|
| 42 |
service_resource_prefix_list = [ |
| 43 |
'vpnservices', |
| 44 |
'ikepolicies', |
| 45 |
'ipsecpolicies', |
| 46 |
'ipsec_site_connections', |
| 47 |
'endpoint_groups', |
| 48 |
] |
| 49 |
|
| 50 |
if plural_name in service_resource_prefix_list: |
| 51 |
plural_name = plural_name.replace("_", "-") |
| 52 |
service_prefix = 'vpn' |
| 53 |
uri = '%s/%s/%s' % (self.uri_prefix, service_prefix, |
| 54 |
plural_name) |
| 55 |
return uri |
| 56 |
|
| 57 |
return super(NetworkClient, self).get_uri(plural_name) |
| 58 |
|
| 59 |
|
| 60 |
class Manager(manager.Manager): |
| 61 |
def __init__(self, credentials=None, service=None): |
| 62 |
super(Manager, self).__init__(credentials=credentials) |
| 63 |
self.network_client = NetworkClient( |
| 64 |
self.auth_provider, |
| 65 |
CONF.network.catalog_type, |
| 66 |
CONF.network.region or CONF.identity.region, |
| 67 |
endpoint_type=CONF.network.endpoint_type, |
| 68 |
build_interval=CONF.network.build_interval, |
| 69 |
build_timeout=CONF.network.build_timeout, |
| 70 |
**self.default_params) |