我正在尝试使用 novaclient Python API 获取我在 Rackspace 帐户中拥有的块存储卷的列表。这是我正在使用的代码:
from rackspace_auth_openstack.plugin import RackspaceAuthPlugin from rackspace_auth_openstack.plugin import auth_url_us
from novaclient.client import Client nova = Client(version = 2,
username = '******',
project_id = '******',
api_key = '******************************',
region_name = 'DFW',
auth_system = 'rackspace',
auth_plugin = RackspaceAuthPlugin(),
auth_url = auth_url_us())
print nova.servers.list() print nova.volumes.list()
所有的库都是使用安装的,pip install --upgrade rackspace-novaclient
所以我应该使用最新版本的库。下面是运行上述代码的结果:
$ python test.py
[<Server: svr01>, <Server: svr02>]
Traceback (most recent call last):
File "test.py", line 16, in <module>
print nova.volumes.list()
File "/usr/lib/python2.7/site-packages/novaclient/v1_1/volumes.py", line 95, in list
return self._list("/volumes/detail%s" % query_string, "volumes")
File "/usr/lib/python2.7/site-packages/novaclient/base.py", line 64, in _list
_resp, body = self.api.client.get(url)
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 283, in get
return self._cs_request(url, 'GET', **kwargs)
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 260, in _cs_request
**kwargs)
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 242, in _time_request
resp, body = self.request(url, method, **kwargs)
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 236, in request
raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.NotFound: Not found (HTTP 404)
服务器列表 API 调用有效,所以我很确定我的身份验证正确。CLI 命令nova volume-list
可以正常工作,因此我的代码中似乎缺少某些内容。