0

所以我有一些 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.1 客户端。

此外,无论我是否使用 keystone auth,我都会遇到同样的错误,我认为这是我最好的选择,因为OS_AUTH_STRATEGY=keystone在控制器的 rc 文件中。

最后,如果它有帮助,在导入期间我还会收到以下弃用警告:

/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
4

1 回答 1

1

您的代码中有一些错误。仔细查看api 文档。如果你打电话:

nova = Client(2, sess)

然后sess没有传递给session关键字参数。你要:

nova = Client(2, session=sess)

而且你不需要打电话nova.authenticate()

于 2015-02-05T22:21:43.387 回答