Allow overriding stages in some commands

This allows them to be called by autobackup commands while still
preserving the current Celery report flow.
This commit is contained in:
Joshua Boniface 2024-08-23 11:21:02 -04:00
parent fc89f4f2f5
commit f6c009beac
1 changed files with 39 additions and 15 deletions

View File

@ -2074,14 +2074,21 @@ def vm_worker_detach_device(zkhandler, celery, domain, xml_spec):
def vm_worker_create_snapshot( def vm_worker_create_snapshot(
zkhandler, celery, domain, snapshot_name=None, zk_only=False zkhandler,
celery,
domain,
snapshot_name=None,
zk_only=False,
override_current_stage=0,
override_total_stages=1,
): ):
if snapshot_name is None: if snapshot_name is None:
now = datetime.now() now = datetime.now()
snapshot_name = now.strftime("%Y%m%d%H%M%S") snapshot_name = now.strftime("%Y%m%d%H%M%S")
current_stage = 0 # This allows these to be called inside another run while still updating celery
total_stages = 1 current_stage = override_current_stage
total_stages = override_total_stages
start( start(
celery, celery,
f"Creating snapshot '{snapshot_name}' of VM '{domain}'", f"Creating snapshot '{snapshot_name}' of VM '{domain}'",
@ -2117,7 +2124,8 @@ def vm_worker_create_snapshot(
# Get the list of all RBD volumes # Get the list of all RBD volumes
rbd_list = zkhandler.read(("domain.storage.volumes", dom_uuid)).split(",") rbd_list = zkhandler.read(("domain.storage.volumes", dom_uuid)).split(",")
total_stages = 2 + len(rbd_list) if override_total_stages == 1:
total_stages += 1 + len(rbd_list)
snap_list = list() snap_list = list()
@ -2218,9 +2226,17 @@ def vm_worker_create_snapshot(
) )
def vm_worker_remove_snapshot(zkhandler, celery, domain, snapshot_name): def vm_worker_remove_snapshot(
current_stage = 0 zkhandler,
total_stages = 1 celery,
domain,
snapshot_name,
override_current_stage=0,
override_total_stages=1,
):
# This allows these to be called inside another run while still updating celery
current_stage = override_total_stages
total_stages = override_total_stages
start( start(
celery, celery,
f"Removing snapshot '{snapshot_name}' of VM '{domain}'", f"Removing snapshot '{snapshot_name}' of VM '{domain}'",
@ -2251,6 +2267,7 @@ def vm_worker_remove_snapshot(zkhandler, celery, domain, snapshot_name):
) )
rbd_snapshots = _snapshots.split(",") rbd_snapshots = _snapshots.split(",")
if override_total_stages == 1:
total_stages = 2 + len(rbd_snapshots) total_stages = 2 + len(rbd_snapshots)
for snap in rbd_snapshots: for snap in rbd_snapshots:
@ -2398,10 +2415,18 @@ def vm_worker_rollback_snapshot(zkhandler, celery, domain, snapshot_name):
def vm_worker_export_snapshot( def vm_worker_export_snapshot(
zkhandler, celery, domain, snapshot_name, export_path, incremental_parent=None zkhandler,
celery,
domain,
snapshot_name,
export_path,
incremental_parent=None,
override_current_stage=0,
override_total_stages=1,
): ):
current_stage = 0 # This allows these to be called inside another run while still updating celery
total_stages = 1 current_stage = override_current_stage
total_stages = override_total_stages
start( start(
celery, celery,
f"Exporting snapshot '{snapshot_name}' of VM '{domain}' to '{export_path}'", f"Exporting snapshot '{snapshot_name}' of VM '{domain}' to '{export_path}'",
@ -2492,6 +2517,7 @@ def vm_worker_export_snapshot(
) )
snapshot_rbdsnaps = snapshot_rbdsnaps.split(",") snapshot_rbdsnaps = snapshot_rbdsnaps.split(",")
if override_total_stages == 1:
total_stages = 2 + len(snapshot_rbdsnaps) total_stages = 2 + len(snapshot_rbdsnaps)
# Create destination directory # Create destination directory
@ -2674,9 +2700,7 @@ def vm_worker_import_snapshot(
# Ensure that the archives are present # Ensure that the archives are present
export_source_snapshot_file = f"{vm_import_path}/{snapshot_name}/snapshot.json" export_source_snapshot_file = f"{vm_import_path}/{snapshot_name}/snapshot.json"
if not os.path.isfile(export_source_snapshot_file): if not os.path.isfile(export_source_snapshot_file):
fail( fail(celery, f"The specified source export '{snapshot_name}' do not exist")
celery, f"The specified source export '{snapshot_name}' do not exist"
)
return False return False
# Read the export file and get VM details # Read the export file and get VM details