keystoneauth1.adapter module¶
- class keystoneauth1.adapter.Adapter(session: Session, service_type: str | None = None, service_name: str | None = None, interface: str | list[str] | None = None, region_name: str | None = None, endpoint_override: str | None = None, version: str | None = None, auth: plugin.BaseAuthPlugin | None = None, user_agent: str | None = None, connect_retries: int | None = None, logger: Logger | None = None, allow: dict[str, Any] | None = None, additional_headers: MutableMapping[str, str] | None = None, client_name: str | None = None, client_version: str | None = None, allow_version_hack: bool | None = None, global_request_id: str | None = None, min_version: str | None = None, max_version: str | None = None, default_microversion: str | None = None, status_code_retries: int | None = None, retriable_status_codes: list[int] | None = None, raise_exc: bool | None = None, rate_limit: float | None = None, concurrency: int | None = None, connect_retry_delay: float | None = None, status_code_retry_delay: float | None = None)
Bases:
_BaseAdapter- __annotations__ = {}
- __doc__ = None
- __module__ = 'keystoneauth1.adapter'
- class keystoneauth1.adapter.LegacyJsonAdapter(session: Session, service_type: str | None = None, service_name: str | None = None, interface: str | list[str] | None = None, region_name: str | None = None, endpoint_override: str | None = None, version: str | None = None, auth: plugin.BaseAuthPlugin | None = None, user_agent: str | None = None, connect_retries: int | None = None, logger: Logger | None = None, allow: dict[str, Any] | None = None, additional_headers: MutableMapping[str, str] | None = None, client_name: str | None = None, client_version: str | None = None, allow_version_hack: bool | None = None, global_request_id: str | None = None, min_version: str | None = None, max_version: str | None = None, default_microversion: str | None = None, status_code_retries: int | None = None, retriable_status_codes: list[int] | None = None, raise_exc: bool | None = None, rate_limit: float | None = None, concurrency: int | None = None, connect_retry_delay: float | None = None, status_code_retry_delay: float | None = None)
Bases:
_BaseAdapterMake something that looks like an old HTTPClient.
A common case when using an adapter is that we want an interface similar to the HTTPClients of old which returned the body as JSON as well.
You probably don’t want this if you are starting from scratch.
- __annotations__ = {}
- __doc__ = "Make something that looks like an old HTTPClient.\n\n A common case when using an adapter is that we want an interface similar to\n the HTTPClients of old which returned the body as JSON as well.\n\n You probably don't want this if you are starting from scratch.\n "
- __module__ = 'keystoneauth1.adapter'
- delete(url: str, **kwargs: Any) tuple[Response, object]
执行 DELETE 请求。
This calls
request()withmethodset toDELETE.
- get(url: str, **kwargs: Any) tuple[Response, object]
执行 GET 请求。
This calls
request()withmethodset toGET.
- head(url: str, **kwargs: Any) tuple[Response, object]
执行 HEAD 请求。
This calls
request()withmethodset toHEAD.
- patch(url: str, **kwargs: Any) tuple[Response, object]
执行 PATCH 请求。
This calls
request()withmethodset toPATCH.
- post(url: str, **kwargs: Any) tuple[Response, object]
执行 POST 请求。
This calls
request()withmethodset toPOST.
- class keystoneauth1.adapter._BaseAdapter(session: Session, service_type: str | None = None, service_name: str | None = None, interface: str | list[str] | None = None, region_name: str | None = None, endpoint_override: str | None = None, version: str | None = None, auth: plugin.BaseAuthPlugin | None = None, user_agent: str | None = None, connect_retries: int | None = None, logger: Logger | None = None, allow: dict[str, Any] | None = None, additional_headers: MutableMapping[str, str] | None = None, client_name: str | None = None, client_version: str | None = None, allow_version_hack: bool | None = None, global_request_id: str | None = None, min_version: str | None = None, max_version: str | None = None, default_microversion: str | None = None, status_code_retries: int | None = None, retriable_status_codes: list[int] | None = None, raise_exc: bool | None = None, rate_limit: float | None = None, concurrency: int | None = None, connect_retry_delay: float | None = None, status_code_retry_delay: float | None = None)
基类:
object一个包含局部变量的会话实例。
会话是一个全局对象,在许多客户端之间共享。因此,它包含对每个人都相关的一些状态。有很多状态,例如服务类型和区域名称,仅与使用会话的特定客户端相关。适配器在全局会话对象周围提供一个客户端本地数据的包装。
version、min_version、max_version 和 default_microversion 都可以作为字符串或元组给出。
- 参数:
session (keystoneauth1.session.Session) – 要包装的会话对象。
service_type (str) – URL 发现的默认 service_type。
service_name (str) – URL 发现的默认 service_name。
interface (str) – URL 发现的默认 interface。
region_name (str) – URL 发现的默认 region_name。
endpoint_override (str) – 始终为此客户端的请求使用此端点 URL。
version – 限制给定主要 API 的最小版本。与 min_version 和 max_version 互斥。(可选)
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于替换会话中插件的身份验证插件。
user_agent (str) – 要设置的用户代理字符串。
connect_retries (int) – 应该尝试的连接错误的重试次数上限。默认值为 None - 使用会话默认值,即不重试。
logger (logging.Logger) – 一个日志记录对象,用于通过此适配器的请求。
allow (dict) – 在发现 API 版本时传递的额外筛选器。(可选)
additional_headers (dict) – 应该附加到通过适配器的每个请求的额外标头。每个请求指定的相同名称的标头将优先。
client_name (str) – 创建适配器的客户端的名称。这将用于创建 user_agent。
client_version (str) – 创建适配器的客户端的版本。这将用于创建 user_agent。
allow_version_hack (bool) – 允许 keystoneauth 破解目录 URL 以支持旧方案。(可选,默认值为 True)
global_request_id (str) – 将传递到所有请求的 global_request_id(形式为
req-$uuid)。启用跨项目请求 ID 跟踪。min_version – 给定 API 的最小主要版本,旨在与 max_version 一起用作范围的下限。与 version 互斥。如果给出 min_version 而没有 max_version,则就像 max 版本是“latest”。(可选)
max_version – 给定 API 的最大主要版本,旨在与 min_version 一起用作范围的上限。与 version 互斥。(可选)
default_microversion – 与 API 请求一起发送的默认 microversion 值。虽然 microversion 是每个请求的功能,但用户可能知道他们想默认发送特定值。(可选)
status_code_retries (int) – 应该尝试的可重试 HTTP 状态代码的重试次数上限(可选,默认为 0 - 从不重试)。
retriable_status_codes (list) – 应该重试的 HTTP 状态代码列表(可选,默认为 HTTP 503,当 status_code_retries 为 0 时不起作用)。
raise_exc (bool) – 如果为 True,则返回失败 HTTP 响应的请求将引发异常;如果为 False,则返回响应。这可以通过使用相同名称的 kwargs 在每个请求的基础上覆盖。
rate_limit (float) – 通过此适配器发出的请求施加的客户端速率限制,以每秒请求为单位。例如,rate_limit 为 2 表示不允许每秒超过 2 个请求,rate_limit 为 0.5 表示不允许每两秒超过 1 个请求。(可选,默认为 None,这意味着不应用任何速率限制)。
concurrency (int) – 此适配器可以同时使用的 http 请求数量。(可选,默认为 None,这意味着没有限制)。
connect_retry_delay (float) – 两次连接重试之间(如果启用)的延迟(以秒为单位)。默认情况下,从 0.5 秒开始到最大 60 秒的指数重试。
status_code_retry_delay (float) – 两次状态代码重试之间(如果启用)的延迟(以秒为单位)。默认情况下,从 0.5 秒开始到最大 60 秒的指数重试。
- __annotations__ = {'client_name': str | None, 'client_version': str | None}
- __dict__ = mappingproxy({'__module__': 'keystoneauth1.adapter', '__annotations__': {'client_name': str | None, 'client_version': str | None}, '__doc__': "An instance of a session with local variables.\n\n A session is a global object that is shared around amongst many clients. It\n therefore contains state that is relevant to everyone. There is a lot of\n state such as the service type and region_name that are only relevant to a\n particular client that is using the session. An adapter provides a wrapper\n of client local data around the global session object.\n\n version, min_version, max_version and default_microversion can all be\n given either as a string or a tuple.\n\n :param session: The session object to wrap.\n :type session: keystoneauth1.session.Session\n :param str service_type: The default service_type for URL discovery.\n :param str service_name: The default service_name for URL discovery.\n :param str interface: The default interface for URL discovery.\n :param str region_name: The default region_name for URL discovery.\n :param str endpoint_override:\n Always use this endpoint URL for requests for this client.\n :param version:\n The minimum version restricted to a given Major API.\n Mutually exclusive with min_version and max_version.\n (optional)\n :param auth: An auth plugin to use instead of the session one.\n :type auth: keystoneauth1.plugin.BaseAuthPlugin\n :param str user_agent: The User-Agent string to set.\n :param int connect_retries:\n The maximum number of retries that should be attempted for\n connection errors. Default None - use session default which\n is don't retry.\n :param logger:\n A logging object to use for requests that pass through this\n adapter.\n :type logger: logging.Logger\n :param dict allow:\n Extra filters to pass when discovering API versions. (optional)\n :param dict additional_headers:\n Additional headers that should be attached to every request\n passing through the adapter. Headers of the same name specified\n per request will take priority.\n :param str client_name:\n The name of the client that created the adapter. This will be\n used to create the user_agent.\n :param str client_version:\n The version of the client that created the adapter. This will\n be used to create the user_agent.\n :param bool allow_version_hack:\n Allow keystoneauth to hack up catalog URLS to support older schemes.\n (optional, default True)\n :param str global_request_id:\n A global_request_id (in the form of ``req-$uuid``) that will be\n passed on all requests. Enables cross project request id tracking.\n :param min_version:\n The minimum major version of a given API, intended to be used as\n the lower bound of a range with max_version. Mutually exclusive with\n version. If min_version is given with no max_version it is as\n if max version is 'latest'. (optional)\n :param max_version:\n The maximum major version of a given API, intended to be used as\n the upper bound of a range with min_version. Mutually exclusive with\n version. (optional)\n :param default_microversion:\n The default microversion value to send with API requests. While\n microversions are a per-request feature, a user may know they\n want to default to sending a specific value. (optional)\n :param int status_code_retries:\n The maximum number of retries that should be attempted for retriable\n HTTP status codes (optional, defaults to 0 - never retry).\n :param list retriable_status_codes:\n List of HTTP status codes that should be retried (optional,\n defaults to HTTP 503, has no effect when status_code_retries is 0).\n :param bool raise_exc:\n If True, requests returning failing HTTP responses will raise an\n exception; if False, the response is returned. This can be\n overridden on a per-request basis via the kwarg of the same name.\n :param float rate_limit:\n A client-side rate limit to impose on requests made through this\n adapter in requests per second. For instance, a rate_limit of 2\n means to allow no more than 2 requests per second, and a rate_limit\n of 0.5 means to allow no more than 1 request every two seconds.\n (optional, defaults to None, which means no rate limiting will be\n applied).\n :param int concurrency:\n How many simultaneous http requests this Adapter can be used for.\n (optional, defaults to None, which means no limit).\n :param float connect_retry_delay:\n Delay (in seconds) between two connect retries (if enabled).\n By default exponential retry starting with 0.5 seconds up to\n a maximum of 60 seconds is used.\n :param float status_code_retry_delay:\n Delay (in seconds) between two status code retries (if enabled).\n By default exponential retry starting with 0.5 seconds up to\n a maximum of 60 seconds is used.\n ", 'client_name': None, 'client_version': None, '__init__': <function _BaseAdapter.__init__>, '_set_endpoint_filter_kwargs': <function _BaseAdapter._set_endpoint_filter_kwargs>, '_request': <function _BaseAdapter._request>, 'get_token': <function _BaseAdapter.get_token>, 'get_endpoint': <function _BaseAdapter.get_endpoint>, 'get_endpoint_data': <function _BaseAdapter.get_endpoint_data>, 'get_all_version_data': <function _BaseAdapter.get_all_version_data>, 'get_api_major_version': <function _BaseAdapter.get_api_major_version>, 'invalidate': <function _BaseAdapter.invalidate>, 'get_user_id': <function _BaseAdapter.get_user_id>, 'get_project_id': <function _BaseAdapter.get_project_id>, 'register_argparse_arguments': <classmethod(<function _BaseAdapter.register_argparse_arguments>)>, 'register_service_argparse_arguments': <classmethod(<function _BaseAdapter.register_service_argparse_arguments>)>, '__dict__': <attribute '__dict__' of '_BaseAdapter' objects>, '__weakref__': <attribute '__weakref__' of '_BaseAdapter' objects>})
- __doc__ = "An instance of a session with local variables.\n\n A session is a global object that is shared around amongst many clients. It\n therefore contains state that is relevant to everyone. There is a lot of\n state such as the service type and region_name that are only relevant to a\n particular client that is using the session. An adapter provides a wrapper\n of client local data around the global session object.\n\n version, min_version, max_version and default_microversion can all be\n given either as a string or a tuple.\n\n :param session: The session object to wrap.\n :type session: keystoneauth1.session.Session\n :param str service_type: The default service_type for URL discovery.\n :param str service_name: The default service_name for URL discovery.\n :param str interface: The default interface for URL discovery.\n :param str region_name: The default region_name for URL discovery.\n :param str endpoint_override:\n Always use this endpoint URL for requests for this client.\n :param version:\n The minimum version restricted to a given Major API.\n Mutually exclusive with min_version and max_version.\n (optional)\n :param auth: An auth plugin to use instead of the session one.\n :type auth: keystoneauth1.plugin.BaseAuthPlugin\n :param str user_agent: The User-Agent string to set.\n :param int connect_retries:\n The maximum number of retries that should be attempted for\n connection errors. Default None - use session default which\n is don't retry.\n :param logger:\n A logging object to use for requests that pass through this\n adapter.\n :type logger: logging.Logger\n :param dict allow:\n Extra filters to pass when discovering API versions. (optional)\n :param dict additional_headers:\n Additional headers that should be attached to every request\n passing through the adapter. Headers of the same name specified\n per request will take priority.\n :param str client_name:\n The name of the client that created the adapter. This will be\n used to create the user_agent.\n :param str client_version:\n The version of the client that created the adapter. This will\n be used to create the user_agent.\n :param bool allow_version_hack:\n Allow keystoneauth to hack up catalog URLS to support older schemes.\n (optional, default True)\n :param str global_request_id:\n A global_request_id (in the form of ``req-$uuid``) that will be\n passed on all requests. Enables cross project request id tracking.\n :param min_version:\n The minimum major version of a given API, intended to be used as\n the lower bound of a range with max_version. Mutually exclusive with\n version. If min_version is given with no max_version it is as\n if max version is 'latest'. (optional)\n :param max_version:\n The maximum major version of a given API, intended to be used as\n the upper bound of a range with min_version. Mutually exclusive with\n version. (optional)\n :param default_microversion:\n The default microversion value to send with API requests. While\n microversions are a per-request feature, a user may know they\n want to default to sending a specific value. (optional)\n :param int status_code_retries:\n The maximum number of retries that should be attempted for retriable\n HTTP status codes (optional, defaults to 0 - never retry).\n :param list retriable_status_codes:\n List of HTTP status codes that should be retried (optional,\n defaults to HTTP 503, has no effect when status_code_retries is 0).\n :param bool raise_exc:\n If True, requests returning failing HTTP responses will raise an\n exception; if False, the response is returned. This can be\n overridden on a per-request basis via the kwarg of the same name.\n :param float rate_limit:\n A client-side rate limit to impose on requests made through this\n adapter in requests per second. For instance, a rate_limit of 2\n means to allow no more than 2 requests per second, and a rate_limit\n of 0.5 means to allow no more than 1 request every two seconds.\n (optional, defaults to None, which means no rate limiting will be\n applied).\n :param int concurrency:\n How many simultaneous http requests this Adapter can be used for.\n (optional, defaults to None, which means no limit).\n :param float connect_retry_delay:\n Delay (in seconds) between two connect retries (if enabled).\n By default exponential retry starting with 0.5 seconds up to\n a maximum of 60 seconds is used.\n :param float status_code_retry_delay:\n Delay (in seconds) between two status code retries (if enabled).\n By default exponential retry starting with 0.5 seconds up to\n a maximum of 60 seconds is used.\n "
- __init__(session: Session, service_type: str | None = None, service_name: str | None = None, interface: str | list[str] | None = None, region_name: str | None = None, endpoint_override: str | None = None, version: str | None = None, auth: plugin.BaseAuthPlugin | None = None, user_agent: str | None = None, connect_retries: int | None = None, logger: Logger | None = None, allow: dict[str, Any] | None = None, additional_headers: MutableMapping[str, str] | None = None, client_name: str | None = None, client_version: str | None = None, allow_version_hack: bool | None = None, global_request_id: str | None = None, min_version: str | None = None, max_version: str | None = None, default_microversion: str | None = None, status_code_retries: int | None = None, retriable_status_codes: list[int] | None = None, raise_exc: bool | None = None, rate_limit: float | None = None, concurrency: int | None = None, connect_retry_delay: float | None = None, status_code_retry_delay: float | None = None)
- __module__ = 'keystoneauth1.adapter'
- __weakref__
对该对象的弱引用列表
- get_all_version_data(interface: str | list[str] | None = 'public', region_name: str | None = None) dict[str, dict[str, dict[str, list[VersionData]]]]
获取服务的有关所有版本的数据。
- 参数:
interface – 要获取版本数据的端点类型。可以是一个单一值或一个值列表。值为 None 表示应查询所有接口。(可选,默认为 public)
region_name (string) – 要获取版本数据的端点区域。值为 None 表示应查询所有区域。(可选,默认为 None)
- 返回值:
一个字典,键为 region_name,值为包含字典的字典,字典的键为 interface,值为
VersionData列表。
- get_api_major_version(auth: plugin.BaseAuthPlugin | None = None, **kwargs: Any) tuple[int | float, ...] | None
从身份验证插件获取主要 API 版本。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – 如果插件不可用。
- 返回值:
服务发现的 API 主要版本。
- 返回类型:
tuple 或 None
- get_endpoint(auth: plugin.BaseAuthPlugin | None = None, **kwargs: Any) str | None
获取由认证插件提供的端点。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – 如果插件不可用。
- 返回值:
如果可用,则返回端点,否则返回 None。
- 返回类型:
- get_endpoint_data(auth: plugin.BaseAuthPlugin | None = None) discover.EndpointData | None
获取此适配器的端点数据。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – 如果插件不可用。
TypeError – 如果参数无效
- 返回值:
如果可用,则返回端点数据,否则返回 None。
- 返回类型:
keystoneauth1.discover.EndpointData
- get_project_id(auth: plugin.BaseAuthPlugin | None = None) str | None
返回由认证插件提供的已认证的项目 ID。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth.AuthorizationFailure – 如果新的 token 获取失败。
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – 如果插件不可用。
- 返回值:
当前的 project_id 或如果插件不支持则为 None。
- 返回类型:
- get_token(auth: plugin.BaseAuthPlugin | None = None) str | None
返回由认证插件提供的令牌。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth.AuthorizationFailure – 如果新的 token 获取失败。
- 返回值:
一个有效的 token。
- 返回类型:
- get_user_id(auth: plugin.BaseAuthPlugin | None = None) str | None
返回由认证插件提供的已认证的用户 ID。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 用于令牌的身份验证插件。覆盖会话中的插件。(可选)
- 引发:
keystoneauth1.exceptions.auth.AuthorizationFailure – 如果新的 token 获取失败。
keystoneauth1.exceptions.auth_plugins.MissingAuthPlugin – 如果插件不可用。
- 返回值:
当前的 user_id 或如果插件不支持则为 None。
- 返回类型:
- invalidate(auth: plugin.BaseAuthPlugin | None = None) bool
使认证插件失效。
- 参数:
auth (keystoneauth1.plugin.BaseAuthPlugin) – 要使失效的认证插件。覆盖会话上的插件。(可选)
- classmethod register_argparse_arguments(parser: ArgumentParser, service_type: str | None = None) None
将参数附加到 Adapter 的给定 argparse Parser。
- 参数:
parser (argparse.ArgumentParser) – 要附加选项的 argparse 解析器。
service_type (str) – 默认 service_type 值。(可选)
- classmethod register_service_argparse_arguments(parser: ArgumentParser, service_type: str) None
将参数附加到 Adapter 的给定 argparse Parser。
- 参数:
parser (argparse.ArgumentParser) – 要附加选项的 argparse 解析器。
service_type (str) – 用于生成附加参数的服务名称。
- keystoneauth1.adapter.register_adapter_argparse_arguments(parser: ArgumentParser, service_type: str | None = None) None
- keystoneauth1.adapter.register_service_adapter_argparse_arguments(parser: ArgumentParser, service_type: str) None