def start(self):
# Start thread to generate tgz and write tgz data into tarpipe_in.
with tarfile.open(fileobj=self.tarpipe_in, mode='w|gz') as tar_file:
# only need export the leaf vdi.
vdi_uuid = self.vdi_uuids[0]
vdi_ref = self.session.VDI.get_by_uuid(vdi_uuid)
vhd_stream = self._connect_request(vdi_ref)
tar_info = tarfile.TarInfo('0.vhd')
try:
# the VHD must be dynamical hard disk, otherwise it will raise
# VhdDiskTypeNotSupported exception when parsing VDH file.
vhd_DynDisk = vhd_utils.VHDDynDiskParser(vhd_stream)
tar_info.size = vhd_DynDisk.get_vhd_file_size()
LOG.debug("VHD size for tarfile is %d" % tar_info.size)
vhdpipe_out, vhdpipe_in = utils.create_pipe()
pool = eventlet.GreenPool()
pool.spawn(self.convert_vhd_to_tar, vhdpipe_out,
tar_file, tar_info)
try:
self._vhd_to_pipe(vhd_DynDisk, vhdpipe_in)
finally:
vhdpipe_in.close()
pool.waitall()
finally:
self._clean()
评论列表
文章目录