2013-01-24 12:00:30 -06:00
|
|
|
# Copyright 2012-2013 OpenStack, LLC.
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -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
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
2013-01-24 12:00:30 -06:00
|
|
|
# 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.
|
2012-05-10 14:58:16 -05:00
|
|
|
#
|
|
|
|
|
2012-05-02 17:02:08 -04:00
|
|
|
import logging
|
|
|
|
|
2012-08-20 18:02:30 -05:00
|
|
|
from openstackclient.common import utils
|
2012-05-02 17:02:08 -04:00
|
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
2013-11-20 18:02:09 -06:00
|
|
|
DEFAULT_COMPUTE_API_VERSION = '2'
|
|
|
|
API_VERSION_OPTION = 'os_compute_api_version'
|
2012-05-10 16:25:31 -05:00
|
|
|
API_NAME = 'compute'
|
2015-04-13 16:21:50 -06:00
|
|
|
API_VERSIONS = {
|
|
|
|
"2": "novaclient.client",
|
|
|
|
}
|
2012-05-10 16:25:31 -05:00
|
|
|
|
2012-05-02 17:02:08 -04:00
|
|
|
|
|
|
|
def make_client(instance):
|
2013-01-31 13:31:41 -06:00
|
|
|
"""Returns a compute service client."""
|
2015-04-13 16:47:49 -05:00
|
|
|
|
|
|
|
# Defer client imports until we actually need them
|
|
|
|
from novaclient import client as nova_client
|
|
|
|
from novaclient import extension
|
|
|
|
try:
|
|
|
|
from novaclient.v2.contrib import list_extensions
|
|
|
|
except ImportError:
|
|
|
|
from novaclient.v1_1.contrib import list_extensions
|
|
|
|
|
2015-03-02 13:49:40 -06:00
|
|
|
compute_client = nova_client.get_client_class(
|
2012-08-20 18:02:30 -05:00
|
|
|
instance._api_version[API_NAME],
|
2015-03-02 13:49:40 -06:00
|
|
|
)
|
2014-07-08 01:44:55 -05:00
|
|
|
LOG.debug('Instantiating compute client: %s', compute_client)
|
2013-12-18 15:07:03 +00:00
|
|
|
|
|
|
|
# Set client http_log_debug to True if verbosity level is high enough
|
|
|
|
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
|
|
|
|
|
2014-07-03 18:25:42 -04:00
|
|
|
extensions = [extension.Extension('list_extensions', list_extensions)]
|
2014-10-17 22:26:57 -05:00
|
|
|
|
2015-05-22 16:22:35 -07:00
|
|
|
# Remember endpoint_type only if it is set
|
|
|
|
kwargs = utils.build_kwargs_dict('endpoint_type',
|
|
|
|
instance._endpoint_type)
|
|
|
|
|
2012-08-20 18:02:30 -05:00
|
|
|
client = compute_client(
|
2014-10-09 15:16:07 -05:00
|
|
|
session=instance.session,
|
2014-07-03 18:25:42 -04:00
|
|
|
extensions=extensions,
|
2014-05-08 22:42:21 -05:00
|
|
|
http_log_debug=http_log_debug,
|
|
|
|
timings=instance.timing,
|
2014-12-24 06:08:19 -07:00
|
|
|
region_name=instance._region_name,
|
2015-05-22 16:22:35 -07:00
|
|
|
**kwargs
|
2014-05-08 22:42:21 -05:00
|
|
|
)
|
2012-05-04 12:28:35 -05:00
|
|
|
|
2012-05-02 17:02:08 -04:00
|
|
|
return client
|
2013-11-20 18:02:09 -06:00
|
|
|
|
|
|
|
|
|
|
|
def build_option_parser(parser):
|
|
|
|
"""Hook to add global options"""
|
|
|
|
parser.add_argument(
|
|
|
|
'--os-compute-api-version',
|
|
|
|
metavar='<compute-api-version>',
|
|
|
|
default=utils.env(
|
|
|
|
'OS_COMPUTE_API_VERSION',
|
|
|
|
default=DEFAULT_COMPUTE_API_VERSION),
|
|
|
|
help='Compute API version, default=' +
|
|
|
|
DEFAULT_COMPUTE_API_VERSION +
|
|
|
|
' (Env: OS_COMPUTE_API_VERSION)')
|
|
|
|
return parser
|