Trying to follow a simple tutorial for the openstack python API I found at http://docs.openstack.org/developer/python-novaclient/api.html but doesn't seem to be working. When I try to run
nova.servers.list()
or
nova.flavors.list()
from the tutorial on the python interpreter, I get following error:
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/novaclient/v2/servers.py", line 617, in list
return self._list("/servers%s%s" % (detail, query_string), "servers")
File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 64, in _list
_resp, body = self.api.client.get(url)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 440, in get
return self._cs_request(url, 'GET', **kwargs)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 399, in _cs_request
self.authenticate()
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 569, in authenticate
self._v2_auth(auth_url)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 634, in _v2_auth
return self._authenticate(url, body)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 647, in _authenticate
**kwargs)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 392, in _time_request
resp, body = self.request(url, method, **kwargs)
File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 386, in request
raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.NotFound: The resource could not be found. (HTTP 404)
I'm using the same credentials as admin_openrc.sh, which works. Can't figure out what might be the problem.
Solved the issue: not sure why, openstack complained of missing user domain in auth (don't remember the exactly message error). Couldn't find how to inform user domain in nova, but I do found it on keystone!
from keystoneclient.auth.identity import v3
from keystoneclient import session
from keystoneclient.v3 import client
auth_url = 'http://10.37.135.89:5000/v3/'
username = 'admin'
user_domain_name = 'Default'
project_name = 'admin'
project_domain_name = 'Default'
password = '123456'
auth = v3.Password(auth_url=auth_url,
username=username,
password=password,
project_id='d5eef1aae54742e787d0653eea57254b',
user_domain_name=user_domain_name)
sess = session.Session(auth=auth)
keystone = client.Client(session=sess)
keystone.projects.list()
and after that I used keystone for authenticating in nova:
from novaclient import client
nova = client.Client(2, session=keystone.session)
nova.flavors.list()
Some usefull links that I used for this answer:
http://docs.openstack.org/developer/python-keystoneclient/authentication-plugins.html http://docs.openstack.org/developer/python-keystoneclient/using-api-v3.html http://docs.openstack.org/developer/python-novaclient/api.html