Comment 0 for bug 1050345

Revision history for this message
Alessandro Pilotti (alexpilotti) wrote : glance add / image-create doesn't work on Windows

By trying to add an image to Glance on Windows with:

glance image-create --name="Image name" --container-format ovf --disk-format qcow2 --file image.img

or

glance image-create --name="Image name" --container-format ovf --disk-format qcow2 < image.img

the upload will hang if the file contains a byte with value 0x1A (EOF), due to the fact that the file and stdin streams are treated as text and not binary streams.

The same issue applies to the equivalent deprecated "glance add" command.

The fix consists in setting the streams in binary mode in both cases:

File: python-glanceclient\glanceclient\v1\shell.py

    if 'location' not in fields and 'copy_from' not in fields:
        if args.file:
            fields['data'] = open(args.file, 'rb')
        else:
            if os.name == 'nt':
                msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
            fields['data'] = sys.stdin