我正在尝试使用 libcloud 为 OpenStack 运行一些测试,但遇到了找不到指定端点问题。当我运行此代码时:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
import libcloud.security
libcloud.security.VERIFY_SSL_CERT = False
OpenStack = get_driver(Provider.OPENSTACK)
driver = OpenStack(
'admin', 'password',
ex_force_auth_url='http://controller:5000',
ex_force_auth_version='2.0_password'
)
driver.list_images()
我收到此错误:
Traceback (most recent call last):
File "my_script.py", line 25, in <module>
driver.list_images()
File "/usr/local/lib/python2.7/dist-packages/libcloud/compute/drivers/openstack.py", line 279, 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 202, in request
raw=raw)
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/base.py", line 709, in request
action = self.morph_action_hook(action)
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 269, in morph_action_hook
self._populate_hosts_and_request_paths()
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 313, in _populate_hosts_and_request_paths
url = self._ex_force_base_url or self.get_endpoint()
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack.py", line 254, in get_endpoint
region=service_region)
File "/usr/local/lib/python2.7/dist-packages/libcloud/common/openstack_identity.py", line 278, in get_endpoint
raise LibcloudError('Could not find specified endpoint')
libcloud.common.types.LibcloudError: <LibcloudError in None 'Could not find specified endpoint'>
根据文档https://libcloud.readthedocs.org/en/latest/compute/drivers/openstack.html#i-get-could-not-find-specified-endpoint-error似乎来自 OpenStack 的服务目录不是被填满。这似乎是真的,因为这是我从服务器得到的答案。可以看到 serviceCatalog 是空的。
{
"access": {
"metadata": {
"is_admin": 0,
"roles": []
},
"serviceCatalog": [],
"token": {
"audit_ids": [
"bH-SKGBdRCWlZTtB8LcDIg"
],
"expires": "2016-04-18T20:41:38Z",
"id": "3298b08a96284dfd9473881afce659c9",
"issued_at": "2016-04-18T19:41:38.277756"
},
"user": {
"id": "74767f37d3ee4e3d92a1d0fe6d7da82f",
"name": "admin",
"roles": [],
"roles_links": [],
"username": "admin"
}
}
}
但是当我运行openstack catalog list
命令时,我得到了这个结果:
+------------+----------+------------------------------------------------------------------------+
| Name | Type | Endpoints |
+------------+----------+------------------------------------------------------------------------+
| keystone | identity | RegionOne |
| | | public: http://controller:5000/v2.0 |
| | | RegionOne |
| | | admin: http://controller:35357/v2.0 |
| | | RegionOne |
| | | internal: http://controller:5000/v2.0 |
| | | |
| glance | image | RegionOne |
| | | public: http://controller:9292 |
| | | RegionOne |
| | | internal: http://controller:9292 |
| | | RegionOne |
| | | admin: http://controller:9292 |
...
我如何让 libcloud 从 openstack 中识别我的服务目录,因为它似乎没问题,但没有被获取?已经尝试使用 ex_force_service_type、ex_force_service_name、ex_force_service_region 并获得相同的结果。使用 ex_force_auth_token 和 ex_force_base_url 会导致 404 错误。
谢谢!