Virsh domain has space in it, can not remove

SprintCycle asked:

I’m having trouble starting, or destroying a domain:

virsh # list --all
 Id    Name                           State
----------------------------------------------------
 1     pxe                            running
 -     Centos_6.5_64                  shut off
 -     Git Server                     shut off

I can’t start the domain:

virsh # start Git
error: failed to get domain 'Git'
error: Domain not found: no domain with matching name 'Git'

virsh # start Git Server
error: unexpected data 'Server'

Because of this I’m not able to destroy the domain.

How can I assign an ID or otherwise remove this VM?

Because it has a space in it, I’m not able to manage it like I am other domains.

I know that they are not supposed to have spaces, but then again, end users don’t always listen to what they’re told 😛

Thank you for any help you might provide.

My answer:


Kids, don’t try this at home:

Libvirt should have rejected the creation of a domain with a space in its name, so someone did something strange to create the domain to begin with. To recover from this is going to require some hand-editing of files you aren’t normally supposed to touch manually.

So this is what I would do:

  1. Stop libvirtd (your VMs will continue running).

    service libvirtd stop
    
  2. Find the offending XML file, which should be somewhere in /etc/libvirt/qemu.

    # ls /etc/libvirt/qemu
    autostart
    Centos_6.5_64.xml
    Git Server.xml
    networks
    pxe.xml
    
  3. Rename the offending file.

    # mv /etc/libvirt/qemu/Git Server.xml /etc/libvirt/qemu/Git_Server.xml
    
  4. Edit the name in the offending file.

    # vi /etc/libvirt/qemu/Git_Server.xml
    
    <domain type='kvm'>
      <name>Git_Server</name>
    ...
    
  5. Restart libvirtd.

    service libvirtd start
    

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.