列出服务器 - OpenStack Nova API

Listing Servers - OpenStack Nova API

我已经从另一个 class 传递会话对象(使用 Cherrypy cookie)并在此 class 中重建 Nova 实例以列出服务器。重建的 Nova 实例有效,但是当我尝试创建服务器列表时,出现属性错误。互联网上关于此类问题的信息非常少(我发现没有任何像这个问题那样的远程问题)。 我该如何解决这个问题? :)

代码:

import cherrypy
import xmlrpclib
import xml.etree.ElementTree as ET
from keystoneauth1 import loading
from keystoneauth1 import session
import novaclient.client as client
from socket import gethostbyaddr

nova = client.Client("2.1", session=cherrypy.request.cookie.get('sessCookie').value)
serverList = nova.servers.list()
print serverList

错误:

File "/usr/lib/python2.7/site-packages/cherrypy/_cprequest.py", line 656, in respond
    response.body = self.handler()
  File "/usr/lib/python2.7/site-packages/cherrypy/lib/encoding.py", line 188, in __call__
    self.body = self.oldhandler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/cherrypy/lib/jsontools.py", line 61, in json_handler
    value = cherrypy.serving.request._json_inner_handler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/cherrypy/_cpdispatch.py", line 34, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "/var/www/frontend/controllers/api/vm.py", line 158, in GET
    serverList = nova.servers.list()
  File "/usr/lib/python2.7/site-packages/novaclient/v2/servers.py", line 749, in list
    "servers")
  File "/usr/lib/python2.7/site-packages/novaclient/base.py", line 242, in _list
    resp, body = self.api.client.get(url)
  File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 173, in get
    return self.request(url, 'GET', **kwargs)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 89, in request
    **kwargs)
  File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 331, in request
    resp = super(LegacyJsonAdapter, self).request(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/keystoneauth1/adapter.py", line 98, in request
    return self.session.request(url, method, **kwargs)
AttributeError: 'str' object has no attribute 'request'

session 关键字的值应该是一个 Keystone session 对象,但您传递的是一个字符串。

您可以阅读有关使用 Keystone 会话的更多信息here