Set snapshot name before start

This commit is contained in:
Joshua Boniface 2024-08-20 23:01:52 -04:00
parent 0bf9cc6b06
commit 565011b277
1 changed files with 18 additions and 18 deletions

View File

@ -2076,6 +2076,10 @@ 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
): ):
if snapshot_name is None:
now = datetime.now()
snapshot_name = now.strftime("%Y%m%d%H%M%S")
current_stage = 0 current_stage = 0
total_stages = 1 total_stages = 1
start( start(
@ -2094,25 +2098,21 @@ def vm_worker_create_snapshot(
) )
return False return False
if snapshot_name is None: reg = re.compile("^[a-z0-9.-_]+$")
now = datetime.now() if not reg.match(snapshot_name):
snapshot_name = now.strftime("%Y%m%d%H%M%S") fail(
else: celery,
reg = re.compile("^[a-z0-9.-_]+$") "Snapshot name '{snapshot_name}' contains invalid characters; only alphanumeric, '.', '-', and '_' characters are allowed",
if not reg.match(snapshot_name): )
fail( return False
celery,
"Snapshot name '{snapshot_name}' contains invalid characters; only alphanumeric, '.', '-', and '_' characters are allowed",
)
return False
current_snapshots = zkhandler.children(("domain.snapshots", dom_uuid)) current_snapshots = zkhandler.children(("domain.snapshots", dom_uuid))
if current_snapshots and snapshot_name in current_snapshots: if current_snapshots and snapshot_name in current_snapshots:
fail( fail(
celery, celery,
f"Snapshot name '{snapshot_name}' already exists for VM '{domain}'!", f"Snapshot name '{snapshot_name}' already exists for VM '{domain}'!",
) )
return False return False
# 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(",")