代码之家  ›  专栏  ›  技术社区  ›  Sammitch

novaclient身份验证期间的urlsplit错误

  •  0
  • Sammitch  · 技术社区  · 9 年前

    所以我有一些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中一直抛出这个错误,也不知道为什么即使我指定了v2,它仍然使用1.1客户端。

    此外,无论我是否使用keystone身份验证,我都会遇到同样的错误,我认为这是我自 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
    
    1 回复  |  直到 9 年前
        1
  •  1
  •   larsks    9 年前

    代码中有一些错误。请仔细查看 api documentation 。如果您拨打:

    nova = Client(2, sess)
    

    然后 sess 无法获得 session 关键字参数。您需要:

    nova = Client(2, session=sess)
    

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