Fixes glance add / update / image-create / image-update on Windows
Fixes Bug #1050345 The image upload hangs if the file contains a byte with value 0x1A (EOF), due to the fact that the file or stdin streams are treated as text and not binary streams. This fix sets the proper binary mode. Change-Id: I3425cb9729a8da4d1b73fbfba06fd6f2c7e8833e
This commit is contained in:
+18
-10
@@ -15,8 +15,14 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import copy
|
import copy
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
import msvcrt
|
||||||
|
else:
|
||||||
|
msvcrt = None
|
||||||
|
|
||||||
from glanceclient.common import utils
|
from glanceclient.common import utils
|
||||||
import glanceclient.v1.images
|
import glanceclient.v1.images
|
||||||
|
|
||||||
@@ -70,6 +76,16 @@ def _image_show(image):
|
|||||||
utils.print_dict(info)
|
utils.print_dict(info)
|
||||||
|
|
||||||
|
|
||||||
|
def _set_data_field(fields, args):
|
||||||
|
if 'location' not in fields and 'copy_from' not in fields:
|
||||||
|
if args.file:
|
||||||
|
fields['data'] = open(args.file, 'rb')
|
||||||
|
else:
|
||||||
|
if msvcrt:
|
||||||
|
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
||||||
|
fields['data'] = sys.stdin
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('id', metavar='<IMAGE_ID>', help='ID of image to describe.')
|
@utils.arg('id', metavar='<IMAGE_ID>', help='ID of image to describe.')
|
||||||
def do_image_show(gc, args):
|
def do_image_show(gc, args):
|
||||||
"""Describe a specific image."""
|
"""Describe a specific image."""
|
||||||
@@ -151,11 +167,7 @@ def do_image_create(gc, args):
|
|||||||
CREATE_PARAMS = glanceclient.v1.images.CREATE_PARAMS
|
CREATE_PARAMS = glanceclient.v1.images.CREATE_PARAMS
|
||||||
fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items()))
|
fields = dict(filter(lambda x: x[0] in CREATE_PARAMS, fields.items()))
|
||||||
|
|
||||||
if 'location' not in fields and 'copy_from' not in fields:
|
_set_data_field(fields, args)
|
||||||
if args.file:
|
|
||||||
fields['data'] = open(args.file, 'r')
|
|
||||||
else:
|
|
||||||
fields['data'] = sys.stdin
|
|
||||||
|
|
||||||
image = gc.images.create(**fields)
|
image = gc.images.create(**fields)
|
||||||
_image_show(image)
|
_image_show(image)
|
||||||
@@ -222,11 +234,7 @@ def do_image_update(gc, args):
|
|||||||
UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
|
UPDATE_PARAMS = glanceclient.v1.images.UPDATE_PARAMS
|
||||||
fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))
|
fields = dict(filter(lambda x: x[0] in UPDATE_PARAMS, fields.items()))
|
||||||
|
|
||||||
if 'location' not in fields and 'copy_from' not in fields:
|
_set_data_field(fields, args)
|
||||||
if args.file:
|
|
||||||
fields['data'] = open(args.file, 'r')
|
|
||||||
else:
|
|
||||||
fields['data'] = sys.stdin
|
|
||||||
|
|
||||||
image = gc.images.update(image_id, purge_props=args.purge_props, **fields)
|
image = gc.images.update(image_id, purge_props=args.purge_props, **fields)
|
||||||
_image_show(image)
|
_image_show(image)
|
||||||
|
|||||||
Reference in New Issue
Block a user