2015-02-05 107 views
0

所以我有一些OpenStack設備,我厭倦了與儀表板的戰鬥,所以我想在python中編寫我自己的一點自動化。然而,我甚至幾乎弄不清腳步,並且遇到了問題。novaclient身份驗證期間urlsplit錯誤

代碼:

from keystoneclient.auth.identity import v2 
from keystoneclient import session 
from novaclient.client import Client 

auth = v2.Password(auth_url='http://10.0.0.1:5000/v2.0/', username='foo.bla-admin', 
    password='hunter2', tenant_name='foo.bla') 
sess = session.Session(auth=auth) 
nova = Client(2, sess) 

print nova.authenticate() 

錯誤:

Traceback (most recent call last): 
    File "test.py", line 13, in <module> 
    print nova.authenticate() 
    File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 169, in wrapper 
    return f(self, *args, **kwargs) 
    File "/usr/lib/python2.6/site-packages/novaclient/v1_1/client.py", line 239, in authenticate 
    self.client.authenticate() 
    File "/usr/lib/python2.6/site-packages/novaclient/client.py", line 561, in authenticate 
    magic_tuple = netutils.urlsplit(self.auth_url) 
    File "/usr/lib/python2.6/site-packages/oslo_utils/netutils.py", line 228, in urlsplit 
    url, scheme, allow_fragments) 
    File "/usr/lib64/python2.6/urlparse.py", line 171, in urlsplit 
    i = url.find(':') 
AttributeError: 'NoneType' object has no attribute 'find' 

所有連接信息的有來自控制器上的環境變量,所以我知道這應該是正確的,我已經嘗試將租戶名稱與項目ID交換,但仍然沒有快樂。我不知道爲什麼它會在urlparse中一直拋出這個錯誤,或者爲什麼它似乎在使用1.1客戶端,即使我已經指定了v2。

另外,無論我是否使用keystone auth,我都會得到相同的錯誤,我認爲這是我在控制器的rc文件中自OS_AUTH_STRATEGY=keystone以來最好的選擇。

最後,在情況下,它是有幫助的,進口過程中我也得到了以下廢棄警告:

/usr/lib/python2.6/site-packages/keystoneclient/access.py:20: DeprecationWarning: The oslo namespace package is deprecated. Please use oslo_utils instead. 
    from oslo.utils import timeutils 
/usr/lib/python2.6/site-packages/keystoneclient/i18n.py:21: DeprecationWarning: The oslo namespace package is deprecated. Please use oslo_i18n instead. 
    from oslo import i18n 
/usr/lib/python2.6/site-packages/keystoneclient/session.py:20: DeprecationWarning: The oslo namespace package is deprecated. Please use oslo_config instead. 
    from oslo.config import cfg 
/usr/lib/python2.6/site-packages/keystoneclient/session.py:21: DeprecationWarning: The oslo namespace package is deprecated. Please use oslo_serialization instead. 
    from oslo.serialization import jsonutils 

回答

1

您在代碼中有一些錯誤。仔細查看api documentation。如果您致電:

nova = Client(2, sess) 

然後sess沒有得到通行證session關鍵字參數。你想:

nova = Client(2, session=sess) 

而你並不需要調用nova.authenticate()

+0

這似乎已經做到了。謝謝! – Sammitch 2015-02-05 22:41:07