'Copy the volume to the specified image.'

@coordination.synchronized('{self.driver_prefix}-{volume.id}')
def copy_volume_to_image(self, context, volume, image_service, image_meta):

    active_file = self.get_active_image_from_info(volume)
    active_file_path = os.path.join(self._local_volume_dir(volume), active_file)
    backing_file = self._vhdutils.get_vhd_parent_path(active_file_path)
    root_file_fmt = self.get_volume_format(volume)
    temp_path = None
    try:
        if backing_file:
            temp_file_name = ('%s.temp_image.%s.%s' % (volume.id, image_meta['id'], root_file_fmt))
            temp_path = os.path.join(self._local_volume_dir(volume), temp_file_name)
            self._vhdutils.convert_vhd(active_file_path, temp_path)
            upload_path = temp_path
        else:
            upload_path = active_file_path
        image_utils.upload_volume(context, image_service, image_meta, upload_path, root_file_fmt)
    finally:
        if temp_path:
            self._delete(temp_path)
