def copy_directory(self, host_path, guest_path):
"""
Copies a directory from host_path (pathlib.Path) to guest_path (pathlib.PurePath).
This is natively supported since LXD 2.2 but we have to support 2.0+
Refs: https://github.com/lxc/lxd/issues/2401
Uses tar to pack/unpack the directory.
"""
guest_tar_path = self._guest_temporary_tar_path
self.run(['mkdir', '-p', str(guest_path)])
with tempfile.NamedTemporaryFile() as f:
logger.debug("Creating tar file from {}".format(host_path))
tar = tarfile.open(f.name, 'w')
tar.add(str(host_path), arcname='.')
tar.close()
self.copy_file(Path(f.name), PurePosixPath(guest_tar_path))
self.run(['tar', '-xf', guest_tar_path, '-C', str(guest_path)])
self.run(['rm', '-f', str(guest_tar_path)])
##################################
# PRIVATE METHODS AND PROPERTIES #
##################################
评论列表
文章目录