novaclient 身份验证期间出现 urlsplit 错误

urlsplit error during novaclient authentication

所以我有一些 OpenStack 设备,我厌倦了与仪表板打交道,所以我想在 python 中编写自己的自动化程序。然而,我什至连脚都没有弄湿,我 运行 遇到了问题。

代码:

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 身份验证,我都会遇到同样的错误,我认为这是我最好的选择,因为在控制器的 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

您的代码中有一些错误。仔细看看api documentation。如果您致电:

nova = Client(2, sess)

然后 sess 没有获得 session 关键字参数的传递。你想要:

nova = Client(2, session=sess)

而且您不需要调用 nova.authenticate()