Ask Your Question
0

novaclient Python API not working

asked 2015-11-12 12:51:03 -0500

Vini.g.fer gravatar image

Trying to follow a simple tutorial for the python API found at http://docs.openstack.org/developer/python-novaclient/api.html (http://docs.openstack.org/developer/p...) but doesn't seem to be working. When I try to run

nova.servers.list()

or

nova.flavors.list()

on 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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2016-02-01 12:52:10 -0500

dbaxps gravatar image

updated 2016-02-02 14:30:57 -0500

See
1. https://albertomolina.wordpress.com/2...
2. http://stackoverflow.com/questions/27...
Code bellow works for me
[root@ip-192-169-142-127 ~(keystone_demo)]# cat startInstance4.py

#!/usr/bin/env python
import os
import time
import novaclient.v2  as nvclient
from credentials import get_nova_creds

def get_keystone_creds():
    d = {}
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    return d

def get_nova_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_id'] = os.environ['OS_TENANT_NAME']
    return d

creds = get_nova_creds()
nova = nvclient.client.Client(**creds)
if not nova.keypairs.findall(name="oskeydvr3node"):
    with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
        nova.keypairs.create(name="oskeydvr3node", public_key=fpubkey.read())
image = nova.images.find(name="cirros")
flavor = nova.flavors.find(name="m1.small")

nova.networks.list()
network = nova.networks.find(label="demo_network1")
nics = [{'net-id': network.id}]

block_dev_mapping = {'vda': '10451763-d614-437e-937b-59002603af1c' }

instance = nova.servers.create(name="UbuntuWereWolf", image='', flavor=flavor, key_name="oskeydvr3node", nics=nics, block_device_mapping=block_dev_mapping)

# Poll at 5 second intervals, until the status is no longer 'BUILD'
status = instance.status
while status == 'BUILD':
    time.sleep(5)
    # Retrieve the instance again so the status field updates
    instance = nova.servers.get(instance.id)
    status = instance.status
print "status: %s" % status

Then

[root@ip-192-169-142-127 ~(keystone_demo)]# python  startInstance4.py
/usr/lib/python2.7/site-packages/novaclient/v2/client.py:109: UserWarning: 'novaclient.v2.client.Client' is not designed to be initialized directly. It is inner class of novaclient. Please, use 'novaclient.client.Client' instead. Related lp bug-report: 1493576
  _LW("'novaclient.v2.client.Client' is not designed to be "
status: ACTIVE

If credentials.py per http://www.ibm.com/developerworks/clo...
is already in current directory, there is no need to redefine get_nova_creds() due to

from credentials import get_nova_creds
edit flag offensive delete link more
0

answered 2016-02-01 19:19:05 -0500

Mohit gravatar image
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: 2015-11-12 12:51:03 -0500

Seen: 1,843 times

Last updated: Feb 02 '16