2013-08-15 21:09:44 -07:00
|
|
|
# Copyright 2012 OpenStack Foundation.
|
2012-05-18 09:02:29 +08:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
2013-07-02 18:44:42 -04:00
|
|
|
from neutronclient.common import utils
|
2012-05-18 09:02:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
API_NAME = 'network'
|
|
|
|
API_VERSIONS = {
|
2013-07-02 18:44:42 -04:00
|
|
|
'2.0': 'neutronclient.v2_0.client.Client',
|
2015-11-09 09:52:05 -05:00
|
|
|
'2': 'neutronclient.v2_0.client.Client',
|
2012-05-18 09:02:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def make_client(instance):
|
2014-08-21 15:45:10 +03:00
|
|
|
"""Returns an neutron client."""
|
2013-07-02 18:44:42 -04:00
|
|
|
neutron_client = utils.get_client_class(
|
2012-05-18 09:02:29 +08:00
|
|
|
API_NAME,
|
2018-11-02 15:08:45 +02:00
|
|
|
instance._api_version,
|
2012-05-18 09:02:29 +08:00
|
|
|
API_VERSIONS,
|
|
|
|
)
|
|
|
|
instance.initialize()
|
|
|
|
url = instance._url
|
|
|
|
url = url.rstrip("/")
|
2015-11-09 09:52:05 -05:00
|
|
|
client = neutron_client(username=instance._username,
|
2016-05-23 12:58:29 -05:00
|
|
|
project_name=instance._project_name,
|
2015-11-09 09:52:05 -05:00
|
|
|
password=instance._password,
|
|
|
|
region_name=instance._region_name,
|
|
|
|
auth_url=instance._auth_url,
|
|
|
|
endpoint_url=url,
|
|
|
|
endpoint_type=instance._endpoint_type,
|
|
|
|
token=instance._token,
|
|
|
|
auth_strategy=instance._auth_strategy,
|
|
|
|
insecure=instance._insecure,
|
|
|
|
ca_cert=instance._ca_cert,
|
|
|
|
retries=instance._retries,
|
|
|
|
raise_errors=instance._raise_errors,
|
|
|
|
session=instance._session,
|
|
|
|
auth=instance._auth)
|
|
|
|
return client
|
2012-09-12 10:33:38 +08:00
|
|
|
|
|
|
|
|
|
|
|
def Client(api_version, *args, **kwargs):
|
2013-07-02 18:44:42 -04:00
|
|
|
"""Return an neutron client.
|
2014-08-21 15:45:10 +03:00
|
|
|
|
2012-09-12 10:33:38 +08:00
|
|
|
@param api_version: only 2.0 is supported now
|
|
|
|
"""
|
2013-07-02 18:44:42 -04:00
|
|
|
neutron_client = utils.get_client_class(
|
2012-09-12 10:33:38 +08:00
|
|
|
API_NAME,
|
|
|
|
api_version,
|
|
|
|
API_VERSIONS,
|
|
|
|
)
|
2013-07-02 18:44:42 -04:00
|
|
|
return neutron_client(*args, **kwargs)
|