Ask Your Question
0

Problem using python-novaclient

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

CDOT gravatar image

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

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/apiTest.py", line 25, in <module>
    print nova.servers.list()
  File "/usr/lib/python2.7/dist-packages/novaclient/v2/servers.py", line 835, in list
    "servers")
  File "/usr/lib/python2.7/dist-packages/novaclient/base.py", line 249, in _list
    resp, body = self.api.client.get(url)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 480, in get
    return self._cs_request(url, 'GET', **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 436, in _cs_request
    self.authenticate()
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 619, in authenticate
    self._v2_auth(auth_url)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 684, in _v2_auth
    return self._authenticate(url, body)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 697, in _authenticate
    **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", line 431, in _time_request
    resp, body = self.request(url, method, **kwargs)
  File "/usr/lib/python2.7/dist-packages/novaclient/client.py", 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
0

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

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 = 'http://192.168.10.11:5000/v3', try to ping 192.168.10.11 from command line,

edit flag offensive delete link more
0

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

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

AUTH_URL = 'http://192.168.10.11:5000/v3'
USERNAME = 'demo'
PASSWORD = 'password'
PROJECT_NAME = 'demo'
USER_DOMAIN_NAME = 'Default'
PROJECT_DOMAIN_NAME = 'Default'
NOVA_API_VERSION = '2'


def get_creds():
    credentials = {'auth_url': AUTH_URL, 'username': USERNAME,
                   'password': PASSWORD, 'project_name': PROJECT_NAME,
                   'user_domain_name': USER_DOMAIN_NAME,
                   'project_domain_name':PROJECT_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

Stats

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

Seen: 57 times

Last updated: Aug 09