| 1 |
# Copyright 2012 OpenStack Foundation. |
| 2 |
# All Rights Reserved |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 |
# not use this file except in compliance with the License. You may obtain |
| 6 |
# a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 |
# License for the specific language governing permissions and limitations |
| 14 |
# under the License. |
| 15 |
# |
| 16 |
|
| 17 |
from neutronclient.common import utils |
| 18 |
|
| 19 |
|
| 20 |
API_NAME = 'network' |
| 21 |
API_VERSIONS = { |
| 22 |
'2.0': 'neutronclient.v2_0.client.Client', |
| 23 |
'2': 'neutronclient.v2_0.client.Client', |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
def make_client(instance): |
| 28 |
"""Returns an neutron client.""" |
| 29 |
neutron_client = utils.get_client_class( |
| 30 |
API_NAME, |
| 31 |
instance._api_version, |
| 32 |
API_VERSIONS, |
| 33 |
) |
| 34 |
instance.initialize() |
| 35 |
url = instance._url |
| 36 |
url = url.rstrip("/") |
| 37 |
client = neutron_client(username=instance._username, |
| 38 |
project_name=instance._project_name, |
| 39 |
password=instance._password, |
| 40 |
region_name=instance._region_name, |
| 41 |
auth_url=instance._auth_url, |
| 42 |
endpoint_url=url, |
| 43 |
endpoint_type=instance._endpoint_type, |
| 44 |
token=instance._token, |
| 45 |
auth_strategy=instance._auth_strategy, |
| 46 |
insecure=instance._insecure, |
| 47 |
ca_cert=instance._ca_cert, |
| 48 |
retries=instance._retries, |
| 49 |
raise_errors=instance._raise_errors, |
| 50 |
session=instance._session, |
| 51 |
auth=instance._auth) |
| 52 |
return client |
| 53 |
|
| 54 |
|
| 55 |
def Client(api_version, *args, **kwargs): |
| 56 |
"""Return an neutron client. |
| 57 |
|
| 58 |
@param api_version: only 2.0 is supported now |
| 59 |
""" |
| 60 |
neutron_client = utils.get_client_class( |
| 61 |
API_NAME, |
| 62 |
api_version, |
| 63 |
API_VERSIONS, |
| 64 |
) |
| 65 |
return neutron_client(*args, **kwargs) |