2013-09-02 23:42:41 -04:00
|
|
|
# Copyright 2010 Jacob Kaplan-Moss
|
|
|
|
# Copyright 2011 OpenStack LLC.
|
|
|
|
# Copyright 2011 Piston Cloud Computing, Inc.
|
2015-02-23 11:51:27 +02:00
|
|
|
|
2013-09-02 23:42:41 -04:00
|
|
|
# All Rights Reserved.
|
2014-07-07 17:48:35 +03:00
|
|
|
#
|
|
|
|
# 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-09-02 23:42:41 -04:00
|
|
|
"""
|
|
|
|
OpenStack Client interface. Handles the REST calls and responses.
|
|
|
|
"""
|
|
|
|
|
2015-05-06 19:35:22 +00:00
|
|
|
from oslo_utils import importutils
|
2013-09-02 23:42:41 -04:00
|
|
|
|
2013-09-03 14:37:34 +03:00
|
|
|
from manilaclient import exceptions
|
2013-09-02 23:42:41 -04:00
|
|
|
|
|
|
|
|
|
|
|
def get_client_class(version):
|
|
|
|
version_map = {
|
2013-09-03 14:37:34 +03:00
|
|
|
'1': 'manilaclient.v1.client.Client',
|
2013-09-02 23:42:41 -04:00
|
|
|
}
|
|
|
|
try:
|
|
|
|
client_path = version_map[str(version)]
|
|
|
|
except (KeyError, ValueError):
|
|
|
|
msg = "Invalid client version '%s'. must be one of: %s" % (
|
2014-06-25 11:48:37 +03:00
|
|
|
(version, ', '.join(version_map)))
|
2013-09-02 23:42:41 -04:00
|
|
|
raise exceptions.UnsupportedVersion(msg)
|
|
|
|
|
2014-07-15 15:04:31 +03:00
|
|
|
return importutils.import_class(client_path)
|
2013-09-02 23:42:41 -04:00
|
|
|
|
|
|
|
|
2015-08-26 18:49:56 -04:00
|
|
|
def get_major_version(version):
|
|
|
|
return version.split('.')[0]
|
|
|
|
|
|
|
|
|
2013-09-02 23:42:41 -04:00
|
|
|
def Client(version, *args, **kwargs):
|
2015-08-26 18:49:56 -04:00
|
|
|
client_class = get_client_class(get_major_version(version))
|
|
|
|
return client_class(version, *args, **kwargs)
|