【问题标题】:Openstack development using SDK - auth_url does not work使用 SDK 进行 Openstack 开发 - auth_url 不起作用
【发布时间】:2023-03-09 00:03:02
【问题描述】:

使用this link 进入openstack dev,结果我的auth_url 是来自openstack RC yaml 文件的http://192.168.43.18/identity/v3 形式。当我使用它时,如链接中所用,我收到以下错误消息:

Traceback (most recent call last):
  File "conn_tester.py", line 22, in <module>
    images = conn.list_images()
  File "/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/openstack.py", line 282, in list_images
    self.connection.request('/images/detail').object, ex_only_active)
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 223, in request
    raw=raw)
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py", line 536, in request
    action = self.morph_action_hook(action)
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 290, in morph_action_hook
    self._populate_hosts_and_request_paths()
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 324, in _populate_hosts_and_request_paths
    osa = osa.authenticate(**kwargs)  # may throw InvalidCreds
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack_identity.py", line 855, in authenticate
    return self._authenticate_2_0_with_password()
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack_identity.py", line 880, in _authenticate_2_0_with_password
    return self._authenticate_2_0_with_body(reqbody)
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack_identity.py", line 885, in _authenticate_2_0_with_body
    method='POST')
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py", line 637, in request
    response = responseCls(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py", line 157, in __init__
    message=self.parse_error())
libcloud.common.exceptions.BaseHTTPError: {"error": {"message": "get_version_v3() got an unexpected keyword argument 'auth'", "code": 400, "title": "Bad Request"}}

我尝试将身份验证 URL 更改为 http://192.168.43.18:35357 和端口 5000,但我收到此错误:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='192.168.43.18', port=35357): Max retries exceeded with url: /v2.0/tokens (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fe06f7dff90>: Failed to establish a new connection: [Errno 111] Connection refused',))

使用devstack版本16.0.0

Python 代码:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

auth_username = 'demo'
auth_password = 'password'
#auth_url = 'http://controller:5000'
auth_url = 'http://192.168.43.18:35357'
#auth_url = 'http://192.168.43.18/identity/v3/'
project_name = 'demo'
region_name = 'RegionOne'

provider = get_driver(Provider.OPENSTACK)
conn = provider(auth_username,
                auth_password,
                ex_force_auth_url=auth_url,
                ex_force_auth_version='2.0_password',
                ex_tenant_name=project_name,
                ex_force_service_region=region_name)


#print "hello"
images = conn.list_images()
for image in images:
    print(image)

【问题讨论】:

    标签: openstack devstack


    【解决方案1】:

    看起来您可以指定 v3:

    from libcloud.compute.types import Provider
    from libcloud.compute.providers import get_driver
    
    auth_username = 'demo'
    auth_password = 'password'
    auth_url = 'http://192.168.43.18:5000'
    project_name = 'demo'
    region_name = 'RegionOne'
    
    provider = get_driver(Provider.OPENSTACK)
    conn = provider(auth_username,
                    auth_password,
                    ex_force_auth_url=auth_url,
                    ex_force_auth_version='3.x_password',
                    ex_tenant_name=project_name,
                    ex_force_service_region=region_name)
    
    
    #print "hello"
    images = conn.list_images()
    for image in images:
    print(image)
    

    使用 v3 的示例并不多。租户通常与 2.0 相关联,因此我不确定是否需要 ex_tenant_name 选项。

    Keystone 版本控制:

    https://developer.openstack.org/api-ref/identity/v3/

    有关 libcloud 的更多信息:

    https://libcloud.readthedocs.io/en/latest/compute/drivers/openstack.html#connecting-to-the-openstack-installation

    另外,您可以查看 keystone 是否使用 v2.0:

    curl http://192.168.43.18:5000/v2.0
    

    如果是这样,那么我会假设这样的事情会起作用:

    from libcloud.compute.types import Provider
    from libcloud.compute.providers import get_driver
    
    auth_username = 'demo'
    auth_password = 'password'
    auth_url = 'http://192.168.43.18:5000'
    project_name = 'demo'
    region_name = 'RegionOne'
    
    provider = get_driver(Provider.OPENSTACK)
    conn = provider(auth_username,
                    auth_password,
                    ex_force_auth_url=auth_url,
                    ex_force_auth_version='2.0_password',
                    ex_tenant_name=project_name,
                    ex_force_service_region=region_name)
    
    
    #print "hello"
    images = conn.list_images()
    for image in images:
        print(image)
    

    如果仍然无法正常工作,请确认您正在使用公共 keystone 端点。根据您的版本,您可能会收到不同级别的信息:

    openstack endpoint list --long
    

    openstack endpoint list
    

    【讨论】:

    • 感谢您的回复。试过了,还是不行。当我在没有端口的情况下尝试 curl 命令时,我得到了一些 html,上面写着404 not found/v2.0 was not found on this server。当我尝试使用端口(5000 或 35357)时,连接被拒绝。这可能是由于超过了最大尝试次数。如果可能,有没有办法清除以前的尝试?我认为问题在于失败的尝试太多,这给了我max tries exceeded with url.. 错误消息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多