def make_client(instance): """Returns a volume service client.""" # Defer client imports until we actually need them from cinderclient import extension from cinderclient.v1.contrib import list_extensions from cinderclient.v1 import volume_snapshots from cinderclient.v1 import volumes # Monkey patch for v1 cinderclient volumes.Volume.NAME_ATTR = 'display_name' volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_client = utils.get_client_class(API_NAME, instance._api_version[API_NAME], API_VERSIONS) LOG.debug('Instantiating volume client: %s', volume_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) client = volume_client(session=instance.session, extensions=extensions, http_log_debug=http_log_debug, region_name=instance.region_name, **kwargs) return client
def make_client(instance): """Returns a compute service client.""" # Defer client import until we actually need them from novaclient import client as nova_client if _compute_api_version is not None: version = _compute_api_version else: version = instance._api_version[API_NAME] from novaclient import api_versions # convert to APIVersion object version = api_versions.get_api_version(version) if version.is_latest(): import novaclient # NOTE(RuiChen): executing version discovery make sense, but that need # an initialized REST client, it's not available now, # fallback to use the max version of novaclient side. version = novaclient.API_MAX_VERSION LOG.debug('Instantiating compute client for %s', version) compute_api = utils.get_client_class( API_NAME, version.ver_major, COMPUTE_API_VERSIONS, ) LOG.debug('Instantiating compute api: %s', compute_api) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [ext for ext in nova_client.discover_extensions(version) if ext.name == "list_extensions"] # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) client = nova_client.Client( version, session=instance.session, extensions=extensions, http_log_debug=http_log_debug, timings=instance.timing, region_name=instance.region_name, **kwargs ) client.api = compute_api( session=instance.session, service_type=COMPUTE_API_TYPE, endpoint=instance.get_endpoint_for_service_type( COMPUTE_API_TYPE, region_name=instance.region_name, interface=instance.interface, ) ) return client
def make_client(instance): """Returns a compute service client.""" # Defer client import until we actually need them from novaclient import client as nova_client if _compute_api_version is not None: version = _compute_api_version else: version = instance._api_version[API_NAME] from novaclient import api_versions # convert to APIVersion object version = api_versions.get_api_version(version) if version.is_latest(): import novaclient # NOTE(RuiChen): executing version discovery make sense, but that need # an initialized REST client, it's not available now, # fallback to use the max version of novaclient side. version = novaclient.API_MAX_VERSION LOG.debug('Instantiating compute client for %s', version) compute_api = utils.get_client_class( API_NAME, version.ver_major, COMPUTE_API_VERSIONS, ) LOG.debug('Instantiating compute api: %s', compute_api) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [ ext for ext in nova_client.discover_extensions(version) if ext.name == "list_extensions" ] # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) client = nova_client.Client(version, session=instance.session, extensions=extensions, http_log_debug=http_log_debug, timings=instance.timing, region_name=instance.region_name, **kwargs) client.api = compute_api(session=instance.session, service_type=COMPUTE_API_TYPE, endpoint=instance.get_endpoint_for_service_type( COMPUTE_API_TYPE, region_name=instance.region_name, interface=instance.interface, )) return client
def make_client(instance): """Returns a volume service client.""" # Defer client imports until we actually need them from cinderclient import extension from cinderclient.v3.contrib import list_extensions from cinderclient.v3 import volume_snapshots from cinderclient.v3 import volumes # Check whether the available cinderclient supports v1 or v2 try: from cinderclient.v1 import services # noqa except Exception: del API_VERSIONS['1'] try: from cinderclient.v2 import services # noqa except Exception: del API_VERSIONS['2'] if _volume_api_version is not None: version = _volume_api_version else: version = instance._api_version[API_NAME] from cinderclient import api_versions # convert to APIVersion object version = api_versions.get_api_version(version) if version.ver_major == '1': # Monkey patch for v1 cinderclient volumes.Volume.NAME_ATTR = 'display_name' volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_client = utils.get_client_class(API_NAME, version.ver_major, API_VERSIONS) LOG.debug('Instantiating volume client: %s', volume_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance.interface) endpoint_override = instance.sdk_connection.config.get_endpoint( 'block-storage') client = volume_client(session=instance.session, extensions=extensions, http_log_debug=http_log_debug, region_name=instance.region_name, endpoint_override=endpoint_override, api_version=version, **kwargs) return client
def make_client(instance): """Returns a search service client""" search_client = utils.get_client_class( API_NAME, instance._api_version[API_NAME], API_VERSIONS) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance._interface) client = search_client( session=instance.session, http_log_debug=http_log_debug, region_name=instance._region_name, **kwargs ) return client
def make_client(instance): """Returns a volume service client.""" # Defer client imports until we actually need them from cinderclient import extension from cinderclient.v1.contrib import list_extensions from cinderclient.v1 import volume_snapshots from cinderclient.v1 import volumes # Monkey patch for v1 cinderclient volumes.Volume.NAME_ATTR = 'display_name' volume_snapshots.Snapshot.NAME_ATTR = 'display_name' volume_client = utils.get_client_class( API_NAME, instance._api_version[API_NAME], API_VERSIONS ) LOG.debug('Instantiating volume client: %s', volume_client) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG extensions = [extension.Extension('list_extensions', list_extensions)] # Remember interface only if it is set kwargs = utils.build_kwargs_dict('endpoint_type', instance._interface) client = volume_client( session=instance.session, extensions=extensions, http_log_debug=http_log_debug, region_name=instance._region_name, **kwargs ) return client