1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 09:26:03 +00:00

feat(storages): a volume downloads from its pool page

The volume menu of a pool page gets Download: the host reads the volume
with libvirt's download stream and the panel passes it on in chunks, so
a disk image never sits in the panel's memory. The file is the volume as
stored: a qcow2 volume comes as its qcow2 file. A volume a running VM
uses is refused, as for a copy; the refusal is a message on the pool
page. Each download is a row in the audit log.

gunicorn's worker exits when a request runs past its timeout (600 s), to
end requests stuck on a host. A download of a large disk runs longer, so
each chunk sent starts the request's timeout again: a download that stops
sending is still ended. nginx passes the chunks on as they come
(X-Accel-Buffering: no) instead of spooling them to a file.
This commit is contained in:
catborise 2026-11-15 00:31:42 +03:00
parent 44b6e42f8f
commit c9fef349d5
13 changed files with 239 additions and 52 deletions

View file

@ -375,6 +375,27 @@ class wvmStorage(wvmConnect):
raise util.OperationError(gettext_noop("The running VMs %(vms)s use volume %(name)s; shut them down to copy it"),
vms=", ".join(vms), name=name)
def read_volume(self, name):
"""The size of volume name and its bytes, read in chunks: a running
guest's volume is refused, as for a copy."""
self.refuse_running_copy(name)
vol = self.get_volume(name)
size = vol.infoFlags(libvirt.VIR_STORAGE_VOL_GET_PHYSICAL)[2] # a file's length, not its capacity
stream = self.wvm.newStream(0)
vol.download(stream, 0, 0, 0)
def chunks():
try:
while data := stream.recv(1 << 20):
yield data
stream.finish()
except BaseException: # also a download the browser left (GeneratorExit)
with contextlib.suppress(libvirt.libvirtError):
stream.abort()
raise
return size, chunks()
def clone_volume(self, vol, target_file, vol_fmt=None, metadata=False, mode="0644", disk_owner_uid=0, disk_owner_gid=0):
"""A copy named target_file in this pool of vol, a volume of this pool
or another; its path. clone_name gives a dir pool's name its suffix."""