Bug 558160 - RFE: guest rename: Support renaming of guests
RFE: guest rename: Support renaming of guests
Status: CLOSED NEXTRELEASE
Product: Virtualization Tools
Classification: Community
Component: libvirt (Show other bugs)
unspecified
All Linux
low Severity medium
: ---
: ---
Assigned To: Peter Krempa
: FutureFeature
: 827346 1044564 1070746 (view as bug list)
Depends On:
Blocks: libvirtTodoHV
  Show dependency treegraph
 
Reported: 2010-01-23 20:39 EST by Jens Petersen
Modified: 2016-04-26 11:13 EDT (History)
11 users (show)

See Also:
Fixed In Version:
Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-08-14 07:04:12 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Jens Petersen 2010-01-23 20:39:32 EST
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 08:56:31 EDT
*** Bug 827346 has been marked as a duplicate of this bug. ***
Comment 2 Eric Blake 2012-06-03 09:01:59 EDT
*** Bug 827346 has been marked as a duplicate of this bug. ***
Comment 3 Eric Blake 2012-06-05 08:32:07 EDT
*** Bug 827346 has been marked as a duplicate of this bug. ***
Comment 4 Eric Blake 2012-06-05 08:32:53 EDT
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 08:35:53 EDT
(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-05 21:30:20 EDT
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-11 22:25:33 EDT
Sounds like a good idea to me.
Comment 8 Cole Robinson 2014-01-18 14:24:14 EST
*** Bug 1044564 has been marked as a duplicate of this bug. ***
Comment 9 Cole Robinson 2014-01-18 14:25:29 EST
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 09:11:57 EST
*** Bug 1070746 has been marked as a duplicate of this bug. ***
Comment 11 Tomáš Hozza 2014-02-27 10:26:56 EST
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 07:04:12 EDT
Upstream added the feature recently:

commit b5d63e997bb4cbaa3c9d5e35e38998b0c1e78fd1
Author: Tomas Meszaros <exo@tty.sk>
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@tty.sk>
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

commit 9877d8406cd32864278dfa7bb040c542782d4cfb
Author: Tomas Meszaros <exo@tty.sk>
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@tty.sk>

commit 28257dc2bee84f386c51f647a1824789e3b11862
Author: Tomas Meszaros <exo@tty.sk>
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@tty.sk>

commit ff486e0d29a7c08e7131447ca3c878ed791def4e
Author: Tomas Meszaros <exo@tty.sk>
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@tty.sk>

commit 9f7a559a6d1ab4103de238d59910baefa7b425ff
Author: Tomas Meszaros <exo@tty.sk>
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@tty.sk>
    Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Note You need to log in before you can comment on or make changes to this bug.