2017-09-01 79 views
0

使用this link進入openstack dev,我的auth_url的格式爲http://192.168.43.18/identity/v3,來自openstack RC yaml文件。當我使用它,因爲在鏈接中使用,我得到了以下錯誤消息:使用SDK進行Openstack開發 - auth_url不起作用

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"}} 

我試圖改變的驗證網址來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) 

回答

0

它看起來像你可以指定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選項。

梯形版本:

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

更多關於libcloud信息:

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

此外,你可以看到,如果重點是使用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) 

如果仍不能正常工作,請確認您使用的是公共梯形端點。根據您的版本,您可能會收到不同級別的信息:

openstack endpoint list --long 

openstack endpoint list 
+0

謝謝你的答覆。試過他們,仍然不起作用。當我嘗試沒有端口的curl命令時,我回到了一些html,其中說'404未找到'。在此服務器上找不到/v2.0。當我嘗試使用端口(5000或35357)時,我拒絕連接。這可能是由於超過最大嘗試。如果可能的話,有沒有辦法清除以前的嘗試?我相信這個問題在於失敗的嘗試次數過多,這給了我最大的嘗試超過URL ..錯誤消息。 – user2883071