This example works on Debian 13, but will likely work on other distributions too (CentOS 7).
Save a copy of the Virtual Machines configuration (replacing VMNAME with the name of your VM as shown with "virsh list --all".
virsh dumpxml VMNAME > VMNAME.xml
Edit the VMNAME.xml file and search for
and replace this with the new name for the VM and save the file.
Shutdown the VM (if the VM doesn't shutdown you can run "virsh destroy VMNAME" although data may be lost).
virsh shutdown VMNAME
To swap the server we need to undefine the old VM and define the new VM.
virsh undefine VMNAME virsh define VMNAME.xml
virsh define NEW_VMNAME VMNAME.xml # CentOS 7 may need the new name too
You can now start the VM to complete the rename.
virsh start NEW_VMNAME