2013-07-08 16:48:10 -05:00
|
|
|
# Copyright 2012-2013 OpenStack Foundation
|
2012-12-26 14:22:23 -06: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.
|
|
|
|
#
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2016-05-13 16:14:09 -05:00
|
|
|
from osc_lib import utils
|
|
|
|
|
2016-05-19 13:56:34 +08:00
|
|
|
from openstackclient.i18n import _
|
2012-12-26 14:22:23 -06:00
|
|
|
|
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
2016-11-17 16:59:57 +13:00
|
|
|
DEFAULT_API_VERSION = '2'
|
2013-11-20 18:02:09 -06:00
|
|
|
API_VERSION_OPTION = 'os_image_api_version'
|
2012-12-26 14:22:23 -06:00
|
|
|
API_NAME = "image"
|
|
|
|
API_VERSIONS = {
|
2015-04-02 09:58:26 +11:00
|
|
|
"1": "glanceclient.v1.client.Client",
|
2013-07-08 16:48:10 -05:00
|
|
|
"2": "glanceclient.v2.client.Client",
|
2012-12-26 14:22:23 -06:00
|
|
|
}
|
|
|
|
|
2014-09-18 00:56:38 -05:00
|
|
|
IMAGE_API_TYPE = 'image'
|
|
|
|
IMAGE_API_VERSIONS = {
|
|
|
|
'1': 'openstackclient.api.image_v1.APIv1',
|
|
|
|
'2': 'openstackclient.api.image_v2.APIv2',
|
|
|
|
}
|
|
|
|
|
2012-12-26 14:22:23 -06:00
|
|
|
|
|
|
|
def make_client(instance):
|
2014-09-18 00:56:38 -05:00
|
|
|
"""Returns an image service client"""
|
2012-12-26 14:22:23 -06:00
|
|
|
image_client = utils.get_client_class(
|
|
|
|
API_NAME,
|
|
|
|
instance._api_version[API_NAME],
|
2013-01-31 13:31:41 -06:00
|
|
|
API_VERSIONS)
|
2014-07-08 01:44:55 -05:00
|
|
|
LOG.debug('Instantiating image client: %s', image_client)
|
2012-12-26 14:22:23 -06:00
|
|
|
|
2014-10-17 23:43:38 -05:00
|
|
|
endpoint = instance.get_endpoint_for_service_type(
|
|
|
|
API_NAME,
|
2016-06-23 17:51:54 -05:00
|
|
|
region_name=instance.region_name,
|
|
|
|
interface=instance.interface,
|
2014-10-17 23:43:38 -05:00
|
|
|
)
|
2012-12-26 14:22:23 -06:00
|
|
|
|
2014-09-18 00:56:38 -05:00
|
|
|
client = image_client(
|
2014-10-17 23:43:38 -05:00
|
|
|
endpoint,
|
2014-10-17 22:26:57 -05:00
|
|
|
token=instance.auth.get_token(instance.session),
|
2016-06-23 17:51:54 -05:00
|
|
|
cacert=instance.cacert,
|
|
|
|
insecure=not instance.verify,
|
2013-10-07 12:23:00 -05:00
|
|
|
)
|
2013-07-08 16:48:10 -05:00
|
|
|
|
2014-09-18 00:56:38 -05:00
|
|
|
# Create the low-level API
|
|
|
|
|
|
|
|
image_api = utils.get_client_class(
|
|
|
|
API_NAME,
|
|
|
|
instance._api_version[API_NAME],
|
|
|
|
IMAGE_API_VERSIONS)
|
|
|
|
LOG.debug('Instantiating image api: %s', image_api)
|
|
|
|
|
|
|
|
client.api = image_api(
|
|
|
|
session=instance.session,
|
|
|
|
endpoint=instance.get_endpoint_for_service_type(
|
|
|
|
IMAGE_API_TYPE,
|
2016-06-23 17:51:54 -05:00
|
|
|
region_name=instance.region_name,
|
|
|
|
interface=instance.interface,
|
2014-09-18 00:56:38 -05:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return client
|
|
|
|
|
2013-07-08 16:48:10 -05:00
|
|
|
|
2013-11-20 18:02:09 -06:00
|
|
|
def build_option_parser(parser):
|
|
|
|
"""Hook to add global options"""
|
|
|
|
parser.add_argument(
|
|
|
|
'--os-image-api-version',
|
|
|
|
metavar='<image-api-version>',
|
2015-05-08 13:14:15 -06:00
|
|
|
default=utils.env('OS_IMAGE_API_VERSION'),
|
2016-05-19 13:56:34 +08:00
|
|
|
help=_('Image API version, default=%s (Env: OS_IMAGE_API_VERSION)') %
|
|
|
|
DEFAULT_API_VERSION,
|
|
|
|
)
|
2013-11-20 18:02:09 -06:00
|
|
|
return parser
|