我正在尝试使用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
正常工作,因此看起来我的代码中缺少一些内容。
答案 0 :(得分:2)
由于Cloud Block Storage API位于不同的端点,因此您必须指定service_type
from rackspace_auth_openstack.plugin import RackspaceAuthPlugin, 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(),
service_type = 'volume') # Right here
print nova.volumes.list()
答案 1 :(得分:0)
我已对此进行了测试,并确认novaclient在使用其CLI和使用其Python模块时表现不同。我已将此问题转发给Rackspace中的团队,该团队致力于novaclient;我希望其中一位能够对此有所了解。