255
255
disk.extend(target, size)
257
# Download the unmodified base image unless we already have a copy.
257
258
if not os.path.exists(base):
258
259
prepare_template(target=base, *args, **kwargs)
261
legacy_backing_size = None
264
# Determine whether an existing qcow2 disk uses a legacy backing by
265
# actually looking at the image itself and parsing the output of the
266
# backing file it expects to be using.
267
if os.path.exists(self.path):
268
backing_path = libvirt_utils.get_disk_backing_file(self.path)
269
if backing_path is not None:
270
backing_file = os.path.basename(backing_path)
271
backing_parts = backing_file.rpartition('_')
272
if backing_file != backing_parts[-1] and \
273
backing_parts[-1].isdigit():
274
legacy_backing_size = int(backing_parts[-1])
275
legacy_base += '_%d' % legacy_backing_size
276
legacy_backing_size *= 1024 * 1024 * 1024
278
# Create the legacy backing file if necessary.
279
if legacy_backing_size:
280
if not os.path.exists(legacy_base):
281
with utils.remove_path_on_error(legacy_base):
282
libvirt_utils.copy_image(base, legacy_base)
283
disk.extend(legacy_base, legacy_backing_size)
259
285
# NOTE(cfb): Having a flavor that sets the root size to 0 and having
260
286
# nova effectively ignore that size and use the size of the
261
287
# image is considered a feature at this time, not a bug.