'Copy image (flat extent or sparse vmdk) to datastore.'

def _copy_image(self, context, dc_ref, image_service, image_id, image_size_in_bytes, ds_name, upload_file_path):

    timeout = self.configuration.vmware_image_transfer_timeout_secs
    host_ip = self.configuration.vmware_host_ip
    port = self.configuration.vmware_host_port
    ca_file = self.configuration.vmware_ca_file
    insecure = self.configuration.vmware_insecure
    cookies = self.session.vim.client.options.transport.cookiejar
    dc_name = self.volumeops.get_entity_name(dc_ref)
    LOG.debug('Copying    image:    %(image_id)s    to    %(path)s.', {'image_id': image_id, 'path': upload_file_path})
    cacerts = (ca_file if ca_file else (not insecure))
    tmp_images = image_utils.TemporaryImages.for_image_service(image_service)
    tmp_image = tmp_images.get(context, image_id)
    if tmp_image:
        LOG.debug('Using    temporary    image.')
        with open(tmp_image) as read_handle:
            image_transfer.download_file(read_handle, host_ip, port, dc_name, ds_name, cookies, upload_file_path, image_size_in_bytes, cacerts, timeout)
    else:
        image_transfer.download_flat_image(context, timeout, image_service, image_id, image_size=image_size_in_bytes, host=host_ip, port=port, data_center_name=dc_name, datastore_name=ds_name, cookies=cookies, file_path=upload_file_path, cacerts=cacerts)
    LOG.debug('Image:    %(image_id)s    copied    to    %(path)s.', {'image_id': image_id, 'path': upload_file_path})
