Add admin.vm.volume.Clear call (QubesOS/qubes-issues#5946)

This commit is contained in:
WillyPillow 2020-07-14 01:44:36 +08:00
parent e13fde07fd
commit 5c7b57e690
No known key found for this signature in database
GPG Key ID: 3839E194B1415A9C

View File

@ -27,6 +27,7 @@ import itertools
import os import os
import string import string
import subprocess import subprocess
import pathlib
import libvirt import libvirt
import lxml.etree import lxml.etree
@ -486,6 +487,32 @@ class QubesAdminAPI(qubes.api.AbstractQubesAPI):
finally: # even if calling qubes.ResizeDisk inside the VM failed finally: # even if calling qubes.ResizeDisk inside the VM failed
self.app.save() self.app.save()
@qubes.api.method('admin.vm.volume.Clear', no_payload=True,
scope='local', write=True)
@asyncio.coroutine
def vm_volume_clear(self):
self.enforce(self.arg in self.dest.volumes.keys())
self.fire_event_for_permission()
volume = self.dest.volumes[self.arg]
size = volume.size
# Clear the volume by importing empty data into it
path = yield from volume.import_data(size)
self.dest.fire_event('domain-volume-import-begin',
volume=self.arg, size=size)
pathlib.Path(path).touch()
try:
yield from volume.import_data_end(True)
except:
self.dest.fire_event('domain-volume-import-end',
volume=self.arg, success=False)
raise
self.dest.fire_event('domain-volume-import-end',
volume=self.arg, success=True)
self.app.save()
@qubes.api.method('admin.vm.volume.Set.revisions_to_keep', @qubes.api.method('admin.vm.volume.Set.revisions_to_keep',
scope='local', write=True) scope='local', write=True)
@asyncio.coroutine @asyncio.coroutine