0

我是 OpenStack 客户端和 API 的新手

今天我试图连接到 Keystone,并创建一个这样的 Client 对象:

from keystoneauth1.identity import v3
from keystoneclient.exceptions import ClientException
from keystoneauth1.session import Session
from keystoneclient.v3.client import Client

def keystone_client(version=(3, ), auth_url=None, user_id=None, password=None, project_id=None):
    auth = v3.Password(auth_url=auth_url,
                       user_id=user_id,
                       password=password,
                       project_id=project_id)
    sess = Session(auth=auth)
    try:
        return Client(session=sess)

    except ClientException as e:
        print(e)   # TODO: USE LOGGING

当我尝试使用具有管理员用户凭据的客户端并获取用户列表、项目列表、任何 keystone 功能时,例如:

client = keystone_client(...)
clinet.services.list()
client.users.list()

首先,try-except 块中客户端源代码中的这一遇到异常并记录以下警告消息

   LOG.warning('Failed to contact the endpoint at %s for discovery. Fallback '
                'to using that endpoint as the base url.', url)

然后最后抛出一堆超时异常,回溯:

Failed to contact the endpoint at https://example:5000 for discovery. Fallback to using that endpoint as the base url.
Traceback (most recent call last):
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connection.py", line 159, in _new_conn
    conn = connection.create_connection(
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 84, in create_connection
    raise err
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/util/connection.py", line 74, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
    httplib_response = self._make_request(
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 392, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.8/http/client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1010, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 950, in send
    self.connect()
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connection.py", line 187, in connect
    conn = self._new_conn()
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connection.py", line 171, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7ffa929afb80>: Failed to establish a new connection: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
    retries = retries.increment(
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 446, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='example', port=5000): Max retries exceeded with url: /users (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffa929afb80>: Failed to establish a new connection: [Errno 110] Connection timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/session.py", line 1012, in _send_request
    resp = self.session.request(method, url, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='example', port=5000): Max retries exceeded with url: /users (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffa929afb80>: Failed to establish a new connection: [Errno 110] Connection timed out'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/debtcollector/renames.py", line 43, in decorator
    return wrapped(*args, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneclient/v3/users.py", line 132, in list
    return super(UserManager, self).list(
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneclient/base.py", line 86, in func
    return f(*args, **new_kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneclient/base.py", line 448, in list
    list_resp = self._list(url_query, self.collection_key)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneclient/base.py", line 141, in _list
    resp, body = self.client.get(url, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/adapter.py", line 395, in get
    return self.request(url, 'GET', **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/adapter.py", line 554, in request
    resp = super(LegacyJsonAdapter, self).request(*args, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/adapter.py", line 257, in request
    return self.session.request(url, method, **kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/session.py", line 921, in request
    resp = send(**kwargs)
  File "/home/arthur/codes/dir/test/venv/lib/python3.8/site-packages/keystoneauth1/session.py", line 1028, in _send_request
    raise exceptions.ConnectFailure(msg)
keystoneauth1.exceptions.connection.ConnectFailure: Unable to establish connection to http://example:5000/users?: HTTPConnectionPool(host='example', port=5000): Max retries exceeded with url: /users (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7ffa929afb80>: Failed to establish a new connection: [Errno 110] Connection timed out'))


包括该用户列表在内的所有功能都可以在 Keystone Identity 原始 API 和 OpenStack 命令行客户端中正常工作。似乎 python-keystone-client 查看服务目录并确定它应该使用哪个端点,但最后,它决定使用的那个端点是一个内部端点,不应该直接使用。

还有其他人有这个问题吗?

4

1 回答 1

0

有一个名为“interface”的参数,它的值是“public”、“internal”和“admin”。为了防止 Keystone 客户端尝试私有端点,它应该像这样传递:


client = Client(session, interface='public')
于 2020-11-11T16:13:33.783 回答