Bug 558160

Summary: RFE: guest rename: Support renaming of guests
Product: [Community] Virtualization Tools Reporter: Jens Petersen <petersen>
Component: libvirtAssignee: Peter Krempa <pkrempa>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: unspecifiedCC: berrange, clalance, crobinso, eblake, itamar, jeharris, jforbes, thozza, veillard, virt-maint, xen-maint
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-08-14 11:04:12 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 636033    

Description Jens Petersen 2010-01-24 01:39:32 UTC
Description of problem:
Many a time I have wanted to rename a kvm guest later to something more
appropriate or more up-to-date.

Being able to rename idle domains would be a good feature IMHO.

Comment 1 Eric Blake 2012-06-01 12:56:31 UTC
*** Bug 827346 has been marked as a duplicate of this bug. ***

Comment 2 Eric Blake 2012-06-03 13:01:59 UTC
*** Bug 827346 has been marked as a duplicate of this bug. ***

Comment 3 Eric Blake 2012-06-05 12:32:07 UTC
*** Bug 827346 has been marked as a duplicate of this bug. ***

Comment 4 Eric Blake 2012-06-05 12:32:53 UTC
Copied from bug 827346:

I am trying to use libvirt API implement. The same like virsh tools.

virsh dumpxml myvm > foo.xml

I used virDomainGetXMLDesc API to get xml description of domain, then convert to virDomainDef, and I changed def->name, the last I convert def back to xml.

virsh undefine myvm

I used virDomainUndefine.

virsh define foo.xml

I used virDomainDefineXML.

These APIs all called successed. the domain name show on virt-manager was not changed yet,but the name show on open window was changed and details changed too. the vir-manager must reconnect, then the name is correct.  

use virsh tools is ok.

Did I forget something?

Comment 5 Eric Blake 2012-06-05 12:35:53 UTC
(In reply to comment #4)
> Copied from bug 827346:
> 
> I am trying to use libvirt API implement. The same like virsh tools.
> 
> virsh dumpxml myvm > foo.xml
> 
> I used virDomainGetXMLDesc API to get xml description of domain, then
> convert to virDomainDef, and I changed def->name, the last I convert def
> back to xml.
> 
> virsh undefine myvm
> 
> I used virDomainUndefine.
> 
> virsh define foo.xml
> 
> I used virDomainDefineXML.
> 
> These APIs all called successed. the domain name show on virt-manager was
> not changed yet,but the name show on open window was changed and details
> changed too. the vir-manager must reconnect, then the name is correct.  
> 
> use virsh tools is ok.
> 
> Did I forget something?

Yes, you discovered a poor-man's workaround.  However, note that you missed a few things: if your domain had a managedsave image, you will lose that state in the process of your manual rename.  If your domain has any snapshots, you will have to manually save and delete the snapshots from the old name, then redefine them with the new domain name after creating the new name.  If you want your logs to be continuous across the rename, you will have to track down and rename log files.

That argues that libvirt really should provide an API that adjusts ALL of these aspects, automatically, as part of a single API call, rather than making you piece the steps together and possibly missing something.

Comment 6 xuanmao 2012-06-06 01:30:20 UTC
I have a new idea, I add a alias name for domain, just show on virt-manager.
The all operations are based on the real name of domain. so all questions are solved.

Comment 7 Jens Petersen 2012-06-12 02:25:33 UTC
Sounds like a good idea to me.

Comment 8 Cole Robinson 2014-01-18 19:24:14 UTC
*** Bug 1044564 has been marked as a duplicate of this bug. ***

Comment 9 Cole Robinson 2014-01-18 19:25:29 UTC
If we ever add a rename API, we need to make sure it handles snapshot and managedsave data migration as well.

Comment 10 Cole Robinson 2014-02-27 14:11:57 UTC
*** Bug 1070746 has been marked as a duplicate of this bug. ***

Comment 11 Tomáš Hozza 2014-02-27 15:26:56 UTC
From my point of view this is a BUG not a Feature request as renaming of VM works
for VMs without snapshots in virt-manager. With snapshots it does not work. The
behaviour should be consistent...

Comment 12 Peter Krempa 2015-08-14 11:04:12 UTC
Upstream added the feature recently:

commit b5d63e997bb4cbaa3c9d5e35e38998b0c1e78fd1
Author: Tomas Meszaros <exo>
Date:   Mon Aug 10 21:59:18 2015 +0200

    qemu: Implement virDomainRename
    
    Currently supports only renaming inactive domains without snapshots.
    
    Signed-off-by: Tomas Meszaros <exo>
    Signed-off-by: Michal Privoznik <mprivozn>

commit 9877d8406cd32864278dfa7bb040c542782d4cfb
Author: Tomas Meszaros <exo>
Date:   Mon Aug 10 21:59:17 2015 +0200

    Introduce new VIR_DOMAIN_EVENT_DEFINED_RENAMED event
    
    This should be emitted whenever a domain is renamed.
    
    Signed-off-by: Tomas Meszaros <exo>

commit 28257dc2bee84f386c51f647a1824789e3b11862
Author: Tomas Meszaros <exo>
Date:   Mon Aug 10 21:59:16 2015 +0200

    domain_conf: Introducde virDomainObjListRenameAddNew() & virDomainObjListRenameRemove()
    
    We just need to update the entry in the second hash table. Since commit 8728a56
    we have two hash tables for the domain list so that we can do O(1) lookup
    regardless of looking up by UUID or name. Since with renaming a domain UUID does
    not change, we only need to update the second hash table, where domains are
    referenced by their name.
    
    We will call both functions from the qemuDomainRename().
    
    Signed-off-by: Tomas Meszaros <exo>

commit ff486e0d29a7c08e7131447ca3c878ed791def4e
Author: Tomas Meszaros <exo>
Date:   Mon Aug 10 21:59:15 2015 +0200

    virsh: Implement "domrename" command
    
    This patch implements new virsh command, domrename.
    
    Using domrename, it will be possible to rename domain from the virsh shell by
    calling virRenameDomain API.
    
    It takes two arguments, current domain name and new domain name.
    
    Example:
    
    virsh # list --all
     Id    Name                           State
     ----------------------------------------------------
      -     bar                            shut off
    
    virsh # domrename bar foo
    Domain successfully renamed
    
    virsh # list --all
     Id    Name                           State
     ----------------------------------------------------
      -     foo                            shut off
    
    virsh #
    
    Signed-off-by: Tomas Meszaros <exo>

commit 9f7a559a6d1ab4103de238d59910baefa7b425ff
Author: Tomas Meszaros <exo>
Date:   Mon Aug 10 21:59:14 2015 +0200

    Introduce virDomainRename API
    
    Also, among with this new API new ACL that restricts rename
    capability is invented too.
    
    Signed-off-by: Tomas Meszaros <exo>
    Signed-off-by: Michal Privoznik <mprivozn>