1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-01-12 08:25:18 +00:00

external snapshot logs and bug fixes

This commit is contained in:
cserma 2023-04-04 16:38:12 +03:00 committed by catborise
parent fd6b2ec4bf
commit 68b0494350
2 changed files with 55 additions and 85 deletions

View file

@ -1028,8 +1028,8 @@ def create_external_snapshot(request, pk):
name = request.POST.get("name", "") name = request.POST.get("name", "")
desc = request.POST.get("description", "") desc = request.POST.get("description", "")
instance.proxy.create_external_snapshot(name, instance, desc=desc) instance.proxy.create_external_snapshot(name, instance, desc=desc)
#msg = _("Create snapshot: %(snap)s") % {"snap": name} msg = _("Create external snapshot: %(snap)s") % {"snap": name}
#addlogmsg(request.user.username, instance.compute.name, instance.name, msg) addlogmsg(request.user.username, instance.compute.name, instance.name, msg)
return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots") return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots")
def get_external_snapshots(request, pk): def get_external_snapshots(request, pk):
@ -1042,8 +1042,6 @@ def get_external_snapshots(request, pk):
"instances.snapshot_instances" "instances.snapshot_instances"
): ):
external_snapshots = instance.proxy.get_external_snapshots() external_snapshots = instance.proxy.get_external_snapshots()
#msg = _("Create snapshot: %(snap)s") % {"snap": name}
#addlogmsg(request.user.username, instance.compute.name, instance.name, msg)
return external_snapshots return external_snapshots
def revert_external_snapshot(request, pk): def revert_external_snapshot(request, pk):
@ -1059,8 +1057,8 @@ def revert_external_snapshot(request, pk):
date = request.POST.get("date", "") date = request.POST.get("date", "")
desc = request.POST.get("desc", "") desc = request.POST.get("desc", "")
instance.proxy.revert_external_snapshot(name, instance, date, desc) instance.proxy.revert_external_snapshot(name, instance, date, desc)
#msg = _("Create snapshot: %(snap)s") % {"snap": name} msg = _("Revert external snapshot: %(snap)s") % {"snap": name}
#addlogmsg(request.user.username, instance.compute.name, instance.name, msg) addlogmsg(request.user.username, instance.compute.name, instance.name, msg)
return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots") return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots")
def delete_external_snapshot(request, pk): def delete_external_snapshot(request, pk):
@ -1074,8 +1072,8 @@ def delete_external_snapshot(request, pk):
): ):
name = request.POST.get("name", "") name = request.POST.get("name", "")
instance.proxy.delete_external_snapshot(name, instance) instance.proxy.delete_external_snapshot(name, instance)
#msg = _("Create snapshot: %(snap)s") % {"snap": name} msg = _("Delete external snapshot: %(snap)s") % {"snap": name}
#addlogmsg(request.user.username, instance.compute.name, instance.name, msg) addlogmsg(request.user.username, instance.compute.name, instance.name, msg)
return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots") return redirect(request.META.get("HTTP_REFERER") + "#manageExternalSnapshots")
@superuser_only @superuser_only

View file

@ -23,6 +23,9 @@ try:
VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY, VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY,
VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL, VIR_DOMAIN_SNAPSHOT_LIST_INTERNAL,
VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL, VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL,
VIR_DOMAIN_BLOCK_COMMIT_DELETE,
VIR_DOMAIN_BLOCK_COMMIT_ACTIVE,
VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT,
libvirtError, libvirtError,
) )
from libvirt_qemu import VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, qemuAgentCommand from libvirt_qemu import VIR_DOMAIN_QEMU_AGENT_COMMAND_DEFAULT, qemuAgentCommand
@ -453,6 +456,7 @@ class wvmInstance(wvmConnect):
disk_format = used_size = disk_size = None disk_format = used_size = disk_size = None
disk_cache = disk_io = disk_discard = disk_zeroes = "default" disk_cache = disk_io = disk_discard = disk_zeroes = "default"
readonly = shareable = serial = None readonly = shareable = serial = None
backing_file = None
device = disk.xpath("@device")[0] device = disk.xpath("@device")[0]
if device == "disk": if device == "disk":
@ -484,6 +488,9 @@ class wvmInstance(wvmConnect):
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
disk_zeroes = disk.xpath("driver/@detect_zeroes")[0] disk_zeroes = disk.xpath("driver/@detect_zeroes")[0]
with contextlib.suppress(Exception):
backing_file = disk.xpath("backingStore/source/@file")[0]
readonly = bool(disk.xpath("readonly")) readonly = bool(disk.xpath("readonly"))
shareable = bool(disk.xpath("shareable")) shareable = bool(disk.xpath("shareable"))
serial = ( serial = (
@ -513,6 +520,7 @@ class wvmInstance(wvmConnect):
"storage": storage, "storage": storage,
"path": src_file, "path": src_file,
"format": disk_format, "format": disk_format,
"backing_file": backing_file,
"size": disk_size, "size": disk_size,
"used": used_size, "used": used_size,
"cache": disk_cache, "cache": disk_cache,
@ -1309,21 +1317,15 @@ class wvmInstance(wvmConnect):
xml += self._XMLDesc(VIR_DOMAIN_XML_SECURE) xml += self._XMLDesc(VIR_DOMAIN_XML_SECURE)
xml += """<active>0</active> xml += """<active>0</active>
</domainsnapshot>""" </domainsnapshot>"""
#
# flag number for libvirt.VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY
# is 16 (0x10; 1 << 4)
#
self._snapshotCreateXML(xml, VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) self._snapshotCreateXML(xml, VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
tree = ElementTree.fromstring(self._XMLDesc(0)) disk_info = self.get_disk_devices()
for disks in tree.findall("devices/disk"): for disk in disk_info:
if disks.get('device') == "disk": backing_file = disk["backing_file"]
backingStore = disks.find("backingStore") vol_base = self.get_volume_by_path(backing_file)
if backingStore is not None: pool = vol_base.storagePoolLookupByVolume()
temp_backing_file = backingStore.find('source').get('file') pool.refresh(0)
vol_base = self.get_volume_by_path(temp_backing_file)
pool = vol_base.storagePoolLookupByVolume()
pool.refresh(0)
def get_external_snapshots(self): def get_external_snapshots(self):
external_snapshots = [] external_snapshots = []
@ -1337,52 +1339,20 @@ class wvmInstance(wvmConnect):
return external_snapshots return external_snapshots
def delete_external_snapshot(self, name, instance): def delete_external_snapshot(self, name, instance):
disk_info = self.get_disk_devices()
base_xml = ElementTree.fromstring(self._XMLDesc(0)) for disk in disk_info:
for disk in base_xml.findall('devices/disk'): target_dev = disk["dev"]
if disk.get('device') == 'disk': backing_file = disk["backing_file"]
backingStore = disk.find('backingStore') source_file = disk["path"]
if backingStore is not None: self.instance.blockCommit(target_dev, backing_file, source_file,
if backingStore.find('source') is not None: flags=VIR_DOMAIN_BLOCK_COMMIT_DELETE|VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)
target_dev = disk.find('target').get('dev') while True:
backing_file = backingStore.find('source').get('file') info = self.instance.blockJobInfo(target_dev, 0)
source_file = disk.find('source').get('file') if info.get('cur') == info.get('end'):
self.instance.blockCommit(target_dev, backing_file, source_file, flags=4|2) self.instance.blockJobAbort(target_dev,flags=VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT)
while True: break
info = self.instance.blockJobInfo(target_dev, 0)
if info.get('cur') == info.get('end'):
self.instance.blockJobAbort(target_dev,flags=2)
break
snap = self.instance.snapshotLookupByName(name, 0)
snapXML = ElementTree.fromstring(snap.getXMLDesc(0))
disks = []
for disk_backup in snapXML.findall('inactiveDomain/devices/disk'):
if disk_backup.get('device') == 'disk':
disk_dict = {}
if disk_backup.find('source') is not None:
disk_dict['backing_file'] = disk_backup.find('source').get('file')
if disk_backup.find('driver') is not None:
disk_dict['driver_name'] = disk_backup.find('driver').get('name')
disk_dict['driver_type'] = disk_backup.find('driver').get('type')
if disk_backup.find('target') is not None:
disk_dict['target_dev'] = disk_backup.find('target').get('dev')
disk_dict['target_bus'] = disk_backup.find('target').get('bus')
if disk_backup.find('boot') is not None:
disk_dict['boot_order'] = disk_backup.find('boot').get('order')
disks.append(disk_dict)
for disk in disks:
self.instance.updateDeviceFlags("""<disk type='file' device='disk'>
<driver name='{}' type='{}'/>
<source file='{}'/>
<target dev='{}' bus='{}'/>
<boot order='{}'/>
</disk>""".format(disk["driver_name"],disk["driver_type"],disk["backing_file"],disk["target_dev"],disk["target_bus"],disk["boot_order"]))
snap = self.instance.snapshotLookupByName(name, 0) snap = self.instance.snapshotLookupByName(name, 0)
# flag number for delete snapshot metadata only
# is 2 (0x2; 1 << 1)
snap.delete(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY) snap.delete(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)
def revert_external_snapshot(self, name, instance, date, desc): def revert_external_snapshot(self, name, instance, date, desc):
@ -1404,29 +1374,31 @@ class wvmInstance(wvmConnect):
disk_dict['boot_order'] = disk_backup.find('boot').get('order') disk_dict['boot_order'] = disk_backup.find('boot').get('order')
disks.append(disk_dict) disks.append(disk_dict)
# flag number for delete snapshot metadata only
# is 2 (0x2; 1 << 1)
snap.delete(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY) snap.delete(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY)
base_xml = ElementTree.fromstring(self._XMLDesc(0)) disk_info = self.get_disk_devices()
for disk in base_xml.findall('devices/disk'): for disk in disk_info:
if disk.get('device') == 'disk': source_file = disk["path"]
backingStore = disk.find('backingStore') backing_file = disk["backing_file"]
if backingStore is not None: vol_base = self.get_volume_by_path(backing_file)
if backingStore.find('source') is not None: pool = vol_base.storagePoolLookupByVolume()
vol_base = self.get_volume_by_path(backingStore.find('source').get('file')) pool.refresh(0)
pool = vol_base.storagePoolLookupByVolume() vol_snap = self.get_volume_by_path(source_file)
pool.refresh(0) vol_snap.wipe(0)
vol_snap = self.get_volume_by_path(disk.find('source').get('file')) vol_snap.delete(0)
vol_snap.wipe(0)
vol_snap.delete(0)
for disk in disks: for disk in disks:
self.instance.updateDeviceFlags("""<disk type='file' device='disk'> self.instance.updateDeviceFlags(
<driver name='{}' type='{}'/> """<disk type='file' device='disk'>
<source file='{}'/> <driver name='{}' type='{}'/>
<target dev='{}' bus='{}'/> <source file='{}'/>
<boot order='{}'/> <target dev='{}' bus='{}'/>
</disk>""".format(disk["driver_name"],disk["driver_type"],disk["backing_file"],disk["target_dev"],disk["target_bus"],disk["boot_order"])) <boot order='{}'/>
</disk>""".format(disk["driver_name"],
disk["driver_type"],
disk["backing_file"],
disk["target_dev"],
disk["target_bus"],
disk["boot_order"]))
self.create_external_snapshot(name, instance, date, desc) self.create_external_snapshot(name, instance, date, desc)