Ask Your Question
0

How to upload image via Python API?

asked 2017-07-26 07:18:19 -0500

FilipGontko gravatar image

Hello guys!

I have a problem with uploading Glance image via Python API. Here is my code:

def upload_image(image_name, path, desc=None):
glance = get_session(opt="glance")
image = glance.images.create(name=image_name)
glance.images.upload(image.id, open(path, 'rb'))
return 0

And when I run this I get this Error:

glanceclient.exc.CommunicationError: Error finding address for https://ostack..........................: Unable to establish connection to https://ostack..................../file: [Errno 32] Broken pipe

I thought that the session was not created but I tested it out and everything works.

Please can you help me figure this out ?

Thanks!

edit retag flag offensive close merge delete

Comments

In order to acutely determine where the error occurs, try to put each command in try...except and proper debug line to know where it fails. Not clear if it is during the images.create or images.upload?

nuriel77 gravatar imagenuriel77 ( 2017-07-27 08:08:34 -0500 )edit

I tried it and it fails during images.upload. Basically it creates an image but it is empty because it won't upload an iso file to it (not just iso).

FilipGontko gravatar imageFilipGontko ( 2017-08-02 03:22:56 -0500 )edit

Can you confirm that if you try to do _the same_ using the command line it works?

nuriel77 gravatar imagenuriel77 ( 2017-08-02 04:34:00 -0500 )edit

I figured it out thanks. I had to add 2 other params:

image = glance.images.create(name=image_name, disk_format=disk_format, container_format="bare")
FilipGontko gravatar imageFilipGontko ( 2017-08-03 11:09:08 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-08-22 01:29:00 -0500

FilipGontko gravatar image

I figured it out thanks. I had to add 2 other params:

image = glance.images.create(name=image_name, disk_format=disk_format, container_format="bare")
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-07-26 07:18:19 -0500

Seen: 510 times

Last updated: Aug 22 '17