def _get_cinderclient_parameters(context): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = { 'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name } if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() else: url = _SESSION.get_endpoint(auth, **service_parameters) return auth, service_parameters, url
def cinderclient(context, microversion=None, skip_version_check=False): """Constructs a cinder client object for making API requests. :param context: The nova request context for auth. :param microversion: Optional microversion to check against the client. This implies that Cinder v3 is required for any calls that require a microversion. If the microversion is not available, this method will raise an CinderAPIVersionNotAvailable exception. :param skip_version_check: If True and a specific microversion is requested, the version discovery check is skipped and the microversion is used directly. This should only be used if a previous check for the same microversion was successful. """ global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = {'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name} if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version != '3': raise exception.UnsupportedCinderAPIVersion(version=version) version = '3.0' # Check to see a specific microversion is requested and if so, can it # be handled by the backing server. if microversion is not None: if skip_version_check: version = microversion else: version = _check_microversion(url, microversion) return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, global_request_id=context.global_id, **service_parameters)
def test_get_auth_plugin_no_wraps(self, mock_load): context = mock.MagicMock() context.get_auth_plugin.return_value = "fake" result = service_auth.get_auth_plugin(context) self.assertEqual("fake", result) mock_load.assert_not_called()
def test_get_auth_plugin_wraps_bad_config(self, mock_load): """Tests the case that send_service_user_token is True but there is some misconfiguration with the [service_user] section which makes KSA return None for the service user auth. """ self.flags(send_service_user_token=True, group='service_user') result = service_auth.get_auth_plugin(self.ctx) self.assertEqual(1, mock_load.call_count) self.assertNotIsInstance(result, service_token.ServiceTokenAuthWrapper)
def _session_and_auth(context): # Session is cached, but auth needs to be pulled from context each time. global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.glance.glance_group.name) auth = service_auth.get_auth_plugin(context) return _SESSION, auth
def _get_auth(context): global _ADMIN_AUTH # NOTE(lixipeng): Auth token is none when call # cinder API from compute periodic tasks, context # from them generated from 'context.get_admin_context' # which only set is_admin=True but is without token. # So add load_auth_plugin when this condition appear. if context.is_admin and not context.auth_token: if not _ADMIN_AUTH: _ADMIN_AUTH = _load_auth_plugin(CONF) return _ADMIN_AUTH else: return service_auth.get_auth_plugin(context)
def _glanceclient_from_endpoint(context, endpoint, version): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.glance.glance_group.name) auth = service_auth.get_auth_plugin(context) # TODO(johngarbutt) eventually we should default to getting the # endpoint URL from the service catalog. return glanceclient.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint, global_request_id=context.global_id)
def cinderclient(context): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = { 'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name } if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version == '1': raise exception.UnsupportedCinderAPIVersion(version=version) if version == '2': LOG.warning("The support for the Cinder API v2 is deprecated, please " "upgrade to Cinder API v3.") if version == '3': # TODO(ildikov): Add microversion support for picking up the new # attach/detach API that was added in 3.27. version = '3.0' return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, global_request_id=context.global_id, **service_parameters)
def cinderclient(context): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = {'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name} if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version == '1': raise exception.UnsupportedCinderAPIVersion(version=version) if version == '2': LOG.warning("The support for the Cinder API v2 is deprecated, please " "upgrade to Cinder API v3.") if version == '3': # TODO(ildikov): Add microversion support for picking up the new # attach/detach API that was added in 3.27. version = '3.0' return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, global_request_id=context.global_id, **service_parameters)
def cinderclient(context): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = { 'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name } if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version == '1': raise exception.UnsupportedCinderAPIVersion(version=version) return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, **service_parameters)
def cinderclient(context): global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = {'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name} if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version == '1': raise exception.UnsupportedCinderAPIVersion(version=version) return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, **service_parameters)
def _get_cinderclient_parameters(context): global _ADMIN_AUTH global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) # NOTE(lixipeng): Auth token is none when call # cinder API from compute periodic tasks, context # from them generated from 'context.get_admin_context' # which only set is_admin=True but is without token. # So add load_auth_plugin when this condition appear. if context.is_admin and not context.auth_token: if not _ADMIN_AUTH: _ADMIN_AUTH = _load_auth_plugin(CONF) auth = _ADMIN_AUTH else: auth = service_auth.get_auth_plugin(context) url = None service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = { 'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name } if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() else: url = _SESSION.get_endpoint(auth, **service_parameters) return auth, service_parameters, url
def cinderclient(context, microversion=None, skip_version_check=False): """Constructs a cinder client object for making API requests. :param context: The nova request context for auth. :param microversion: Optional microversion to check against the client. This implies that Cinder v3 is required for any calls that require a microversion. If the microversion is not available, this method will raise an CinderAPIVersionNotAvailable exception. :param skip_version_check: If True and a specific microversion is requested, the version discovery check is skipped and the microversion is used directly. This should only be used if a previous check for the same microversion was successful. """ global _SESSION if not _SESSION: _SESSION = ks_loading.load_session_from_conf_options( CONF, nova.conf.cinder.cinder_group.name) url = None endpoint_override = None auth = service_auth.get_auth_plugin(context) service_type, service_name, interface = CONF.cinder.catalog_info.split(':') service_parameters = {'service_type': service_type, 'service_name': service_name, 'interface': interface, 'region_name': CONF.cinder.os_region_name} if CONF.cinder.endpoint_template: url = CONF.cinder.endpoint_template % context.to_dict() endpoint_override = url else: url = _SESSION.get_endpoint(auth, **service_parameters) # TODO(jamielennox): This should be using proper version discovery from # the cinder service rather than just inspecting the URL for certain string # values. version = cinder_client.get_volume_api_from_url(url) if version == '1': raise exception.UnsupportedCinderAPIVersion(version=version) if version == '2': if microversion is not None: # The Cinder v2 API does not support microversions. raise exception.CinderAPIVersionNotAvailable(version=microversion) LOG.warning("The support for the Cinder API v2 is deprecated, please " "upgrade to Cinder API v3.") if version == '3': version = '3.0' # Check to see a specific microversion is requested and if so, can it # be handled by the backing server. if microversion is not None: if skip_version_check: version = microversion else: version = _check_microversion(url, microversion) return cinder_client.Client(version, session=_SESSION, auth=auth, endpoint_override=endpoint_override, connect_retries=CONF.cinder.http_retries, global_request_id=context.global_id, **service_parameters)
def __init__(self, context): auth = service_auth.get_auth_plugin(context) self._client = utils.get_ksa_adapter('accelerator', ksa_auth=auth)
def test_get_auth_plugin_wraps(self): self.flags(send_service_user_token=True, group='service_user') result = service_auth.get_auth_plugin(self.ctx) self.assertIsInstance(result, service_token.ServiceTokenAuthWrapper)