I'm trying to get a list of the block storage volumes that I have on my Rackspace account using the novaclient Python API. Here's the code that I'm using:
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()
All of the libraries were installed using pip install --upgrade rackspace-novaclient
so I should be using the lastest version of the libraries. Here's the results of running the above code:
$ 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)
The server list API call works, so I'm pretty sure that I'm authenticating properly. The CLI command nova volume-list
works properly so it would appear that I'm missing something from my code.
Since the Cloud Block Storage API is under a different endpoint, you have to specify the 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()
I've tested this and confirmed that novaclient behaves differently when using its CLI and when using its Python module. I've forwarded this issue to the team in Rackspace that works on novaclient; I hope that one of them will be able to shed more light on this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.