1

我正在尝试使用 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可以正常工作,因此我的代码中似乎缺少某些内容。

4

2 回答 2

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()
于 2014-05-16T23:05:53.520 回答
0

我已经对此进行了测试,并确认 novaclient 在使用其 CLI 和使用其 Python 模块时表现不同。我已将此问题转发给在 novaclient 上工作的 Rackspace 团队;我希望他们中的一个能够对此有所了解。

于 2014-05-16T19:20:19.540 回答