Ask Your Question

Problem using python-novaclient

asked 2017-08-07 04:48:18 -0500

CDOT gravatar image

updated 2017-08-07 04:49:32 -0500

I am using Openstack Newton and am currently learning to use the Python APIs. Here is the code I wrote

#!/usr/bin/env python

from novaclient import client as novaclient
import os

def get_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['api_key'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['project_domain_name'] = os.environ['OS_PROJECT_DOMAIN_NAME']
    d['user_domain_name'] = os.environ['OS_USER_DOMAIN_NAME']
    d['project_name'] = os.environ['OS_PROJECT_NAME']
    d['keystone_api'] = os.environ['OS_IDENTITY_API_VERSION']
    d['glance_api'] = os.environ['OS_IMAGE_API_VERSION']
    return d

credentials = get_creds()

# for x in credentials:
#     print (x+' : '+credentials[x])

nova = novaclient.Client(version=2,**credentials)

print nova.servers.list()

Running which I get the error :

Traceback (most recent call last):
  File "/home/cdot/PycharmProjects/Openstack/", line 25, in <module>
    print nova.servers.list()
  File "/usr/lib/python2.7/dist-packages/novaclient/v2/", line 835, in list
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 249, in _list
    resp, body = self.api.client.get(url)
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 480, in get
    return self._cs_request(url, 'GET', **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 436, in _cs_request
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 619, in authenticate
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 684, in _v2_auth
    return self._authenticate(url, body)
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 697, in _authenticate
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 431, in _time_request
    resp, body = self.request(url, method, **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/", line 425, in request
    raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.NotFound: The resource could not be found. (HTTP 404)

Process finished with exit code 1

What am I doing wrong here? I am using Python 2.7 interpreter.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2017-08-09 07:38:51 -0500

Mohit gravatar image

According to the error code - (HTTP 404) it looks like the destination ip address is not reachable from your machine , on your python code , try to print d['auth_url'] and attempt it to ping from the same machine where you are running your python code. Example - if AUTH_URL = '', try to ping from command line,

edit flag offensive delete link more

answered 2017-08-08 02:12:40 -0500

teju gravatar image

I am not sure exactly what is wrong with the above code, however the below code works for me in the OpenStack Newton setup

from keystoneauth1 import loading
from keystoneauth1 import session

from novaclient import client as nova_client

USERNAME = 'demo'
PASSWORD = 'password'

def get_creds():
    credentials = {'auth_url': AUTH_URL, 'username': USERNAME,
                   'password': PASSWORD, 'project_name': PROJECT_NAME,
                   'user_domain_name': USER_DOMAIN_NAME,
    return credentials

loader = loading.get_plugin_loader('password')
credentials = get_creds()
auth = loader.load_from_options(**credentials)
sess = session.Session(auth=auth)
nova = nova_client.Client(NOVA_API_VERSION, session=sess)

print nova.servers.list()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2017-08-07 04:48:18 -0500

Seen: 24 times

Last updated: Aug 09