user2521791 user2521791 - 7 months ago 49
Python Question

Openstack python API: how to download image from glance using the python api

I am trying to write a python program to download images from glance service. However, I could not find a way to download images from the cloud using the API. In the documentation which can be found here:

they explain how to upload images, but not to download them.

The following code shows how to get image object, but I don't now what to do with this object:

import novaclient.v1_1.client as nvclient
name = "cirros"
nova = nvclient.Client(...)
image = nova.images.find(name=name)

is there any way to download the image file and save it on disk using this object "image"?


Without installing glance cli you can download image via HTTP call as described here:

For the python client you can use

img = client.images.get(IMAGE_ID) 

and then call # or

to retrieve generator by which you can access raw data of image.

Full example (saving image from glance to disk):

img = client.images.find(name='cirros-0.3.2-x86_64-uec')

file_name = "%s.img" %
image_file = open(file_name, 'w+')

for chunk in