Ask Your Question

use nova context to get image details

asked 2015-04-14 02:44:52 -0500

Ritesh Paiboina gravatar image

updated 2015-04-14 02:45:36 -0500

Hi All, I am writing a code to get the image details by passing image uuid. There is an existing function in nova image api. The function requires a context object. I am creating a context object, but it seems that context object does not have keystone authentication.

Following is my code :

    from nova import context
    ctxt = context.get_admin_context()
    image = self.image_api.get(ctxt, image_href)

Following is my error :

2015-04-14 09:46:56.222 DEBUG urllib3.util.retry [req-0993a85a-3875-4ed2-80ec-494684e91ac0 admin admin] Converted retries value: 0 -> Retry(total=0, connect=None, read=None, redirect=0) from (pid=735) from_int /usr/local/lib/python2.7/dist-packages/urllib3/util/ * ImageNotAuthorized: Not authorized for image 18a9c0a9-d715-415a-9361-0dc8c87f8db8.

Could you please tell me the correct way to get a context object with keystone auth plugin.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2015-04-14 07:20:08 -0500

The nova client will do the authentication with keystone for you. Try this example:

from novaclient.client import Client

NOVA_API_URI = "http://%s:5000/v2.0/"
IMAGE_NAME = "cirros-0.3.3-x86_64-disk.img"  # change accordingly
CONTROLLER_IP = ""             # change accordingly

def get_nova_client(ip, tenant="demo", user="admin", password="openstack"):
    uri = NOVA_API_URI % ip
    nova = Client(NOVA_API_VERSION, user, password, tenant, uri)
    return nova

nova = get_nova_client(CONTROLLER_IP)

image = nova.images.find(name=TESTIMAGE_NAME)
print("found image: %s" % image)

More information can be found here:

edit flag offensive delete link more

answered 2015-04-16 08:58:03 -0500

Ritesh Paiboina gravatar image

updated 2015-04-16 08:58:57 -0500

Hi Markus,

As we have discussed earlier, I have tried in a different way, which is working. Here we need to give predefined values of the admin user.

    from nova import context
    from keystoneclient.v2_0 import client
    keystone2 = client.Client(username="admin",
    ctx = context.RequestContext(user_id=keystone2.user_id,is_admin=True,
    image = self.image_api.get(ctx, image_href)

In this it is working fine but I need to fill the values of admin user's tenant name and password. Can we do any over here without passing values or getting form oslo conf would be a better option.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2015-04-14 02:44:52 -0500

Seen: 504 times

Last updated: Apr 16 '15