Simplify VM rename to preserve data

A rename is simply a change to two values, so instead of undefining and
re-defining the VM, just edit those two fields. This ensures things like
snapshots are preserved automatically.
This commit is contained in:
Joshua Boniface 2024-08-20 11:37:28 -04:00
parent 7cc354466f
commit 8937ddf331
1 changed files with 6 additions and 20 deletions

View File

@ -618,28 +618,14 @@ def rename_vm(zkhandler, domain, new_domain):
# Get VM information # Get VM information
_b, dom_info = get_info(zkhandler, dom_uuid) _b, dom_info = get_info(zkhandler, dom_uuid)
# Undefine the old VM # Edit the VM data
undefine_vm(zkhandler, dom_uuid) zkhandler.write(
[
# Define the new VM (("domain", dom_uuid), new_domain),
define_vm( (("domain.xml", dom_uuid), vm_config_new),
zkhandler, ]
vm_config_new,
dom_info["node"],
dom_info["node_limit"],
dom_info["node_selector"],
dom_info["node_autostart"],
migration_method=dom_info["migration_method"],
migration_max_downtime=dom_info["migration_max_downtime"],
profile=dom_info["profile"],
tags=dom_info["tags"],
initial_state="stop",
) )
# If the VM is migrated, store that
if dom_info["migrated"] != "no":
zkhandler.write([(("domain.last_node", dom_uuid), dom_info["last_node"])])
return True, 'Successfully renamed VM "{}" to "{}".'.format(domain, new_domain) return True, 'Successfully renamed VM "{}" to "{}".'.format(domain, new_domain)