51
51
# checked before we got here.
52
52
(image_service, image_id) = nova.image.get_image_service(context,
54
with utils.remove_path_on_error(path):
55
55
with open(path, "wb") as image_file:
56
56
metadata = image_service.get(context, image_id, image_file)
58
with utils.save_and_reraise_exception():
62
if e.errno != errno.ENOENT:
63
LOG.warn("unable to remove stale image '%s': %s" %
68
60
def fetch_to_raw(context, image_href, path, user_id, project_id):
88
data = _qemu_img_info(path_tmp)
90
fmt = data.get("file format")
93
raise exception.ImageUnacceptable(
94
reason=_("'qemu-img info' parsing failed."), image_id=image_href)
96
if "backing file" in data:
97
backing_file = data['backing file']
99
raise exception.ImageUnacceptable(image_id=image_href,
100
reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
102
if fmt != "raw" and FLAGS.force_raw_images:
103
staged = "%s.converted" % path
104
LOG.debug("%s was %s, converting to raw" % (image_href, fmt))
105
out, err = utils.execute('qemu-img', 'convert', '-O', 'raw',
109
data = _qemu_img_info(staged)
110
if data.get('file format', None) != "raw":
80
with utils.remove_path_on_error(path_tmp):
81
data = _qemu_img_info(path_tmp)
83
fmt = data.get("file format")
85
raise exception.ImageUnacceptable(
86
reason=_("'qemu-img info' parsing failed."),
89
if "backing file" in data:
90
backing_file = data['backing file']
112
91
raise exception.ImageUnacceptable(image_id=image_href,
113
reason=_("Converted to raw, but format is now %s") %
114
data.get('file format', None))
116
os.rename(staged, path)
119
os.rename(path_tmp, path)
92
reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
94
if fmt != "raw" and FLAGS.force_raw_images:
95
staged = "%s.converted" % path
96
LOG.debug("%s was %s, converting to raw" % (image_href, fmt))
97
with utils.remove_path_on_error(staged):
98
out, err = utils.execute('qemu-img', 'convert', '-O', 'raw',
101
data = _qemu_img_info(staged)
102
if data.get('file format', None) != "raw":
103
raise exception.ImageUnacceptable(image_id=image_href,
104
reason=_("Converted to raw, but format is now %s") %
105
data.get('file format', None))
107
os.rename(staged, path)
110
os.rename(path_tmp, path)