AttributeError: 'Libvirt' object has no attribute 'vm'

Bug #562189 reported by Marcus Bointon
72
This bug affects 16 people
Affects Status Importance Assigned to Milestone
vm-builder (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

Running vmbuilder with this command:

vmbuilder kvm ubuntu \
--suite lucid \
--flavour virtual \
--arch amd64 \
-o \
--libvirt qemu:///system \
--part vmbuilder.partition \
--user user \
--name user \
--pass default \
--ip 192.168.176.100 \
--mirror http://192.168.176.19:9999/ubuntu \
--dest /root/vm1

and this partition file:

root 8000
swap 2000
/home 1000
/var 8000
/var/log 2000

Results in this output and error:

2010-04-13 09:57:30,587 INFO : Calling hook: preflight_check
2010-04-13 09:57:30,625 INFO : Calling hook: set_defaults
2010-04-13 09:57:30,626 INFO : Calling hook: bootstrap
2010-04-13 09:59:42,333 INFO : Calling hook: configure_os
2010-04-13 10:01:19,098 INFO :
2010-04-13 10:01:19,098 INFO : Current default time zone: 'Etc/UTC'
2010-04-13 10:01:19,101 INFO : Local time is now: Tue Apr 13 09:01:19 UTC 2010.
2010-04-13 10:01:19,101 INFO : Universal Time is now: Tue Apr 13 09:01:19 UTC 2010.
2010-04-13 10:01:19,101 INFO :
2010-04-13 10:03:01,863 INFO : Calling hook: post_install
2010-04-13 10:03:01,892 INFO : Calling hook: preflight_check
Traceback (most recent call last):
  File "/usr/bin/vmbuilder", line 24, in <module>
    cli.main()
  File "/usr/lib/python2.6/dist-packages/VMBuilder/contrib/cli.py", line 116, in main
    hypervisor.install_os()
  File "/usr/lib/python2.6/dist-packages/VMBuilder/hypervisor.py", line 59, in install_os
    self.call_hooks('preflight_check')
  File "/usr/lib/python2.6/dist-packages/VMBuilder/distro.py", line 66, in call_hooks
    call_hooks(self, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/VMBuilder/util.py", line 158, in call_hooks
    getattr(plugin, func, log_no_such_method)(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/VMBuilder/plugins/libvirt/__init__.py", line 54, in preflight_check
    if hostname in self.all_domains() and not self.vm.overwrite:
AttributeError: 'Libvirt' object has no attribute 'vm'

I'm running 2.6.32-20-server with libvirt 0.7.5-5ubuntu21, python-vm-builder 0.12.3-0ubuntu1 (all latest lucid packages).

Related branches

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

I noticed that libvirt got updated to 0.7.5-5ubuntu22 today, and it's possible that this bug has been fixed by it, however, I'm not sure as I've got another bug instead that may just be obscuring it...

Thierry Carrez (ttx)
Changed in vm-builder (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

Unfortunately it was just hiding, and it's back again with libvirt 0.7.5-5ubuntu23. Same config, same error.

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

Still there with libvirt 0.7.5-5ubuntu24.

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

Still there with libvirt 0.7.5-5ubuntu25

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

I've now tried this without the -o option (having spotted the self.vm.overwrite is the root of the problem), but that didn't make any difference. Any chance of getting some attention to this as it's a complete showstopper for me. It means my entire UEC / JeOS virtualization plans are on hold. Unless there's some other minimal VM builder that I don't know about?

Revision history for this message
BlueT - Matthew Lien - 練喆明 (bluet) wrote :

I got the same problem.

matthew@0xB1uE7:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu lucid (development branch)
Release: 10.04
Codename: lucid
matthew@0xB1uE7:~$ uname -a
Linux 0xB1uE7 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:09:38 UTC 2010 x86_64 GNU/Linux

ii kvm 1:84+dfsg-0ubuntu16+0.12.3+noroms+0ubuntu6 dummy transitional pacakge from kvm to qemu-kvm
ii libvirt-bin 0.7.5-5ubuntu25 the programs for the libvirt library
ii libvirt0 0.7.5-5ubuntu25 library for interfacing with different virtualization sy
ii python-libvirt 0.7.5-5ubuntu25 libvirt Python bindings
ii python-vm-builder 0.12.3-0ubuntu1 VM builder
ii qemu-kvm 0.12.3+noroms-0ubuntu6 Full virtualization on i386 and amd64 hardware
ii qemu-kvm-extras 0.12.3+noroms-0ubuntu6 fast processor emulator binaries for non-x86 architectur
ii ubuntu-virt-mgmt 1.2 Common packages useful for managing virtual machines gra
ii ubuntu-virt-server 1.2 Common packages necessary for hosting virtual machines
ii ubuntu-vm-builder 0.12.3-0ubuntu1 Ubuntu VM builder
ii virt-manager 0.8.2-2ubuntu8 desktop application for managing virtual machines
ii virt-viewer 0.0.3-6ubuntu7.xul191.1 Displaying the graphical console of a virtual machine

Revision history for this message
Simon Huerlimann (huerlisi) wrote :

Got the same on a Lucid. In my case the problem was that I already had a virtual host with the same name.

Marcus, it looks like you've called vmbuilder with no --hostname. Don't know what is taken as hostname in this case, but probably the same on each invocation.

So I see this as actually being two bugs:
* vmbuilder not tellung you that you need --hostname
* vmbuilder having a broken handling for checking the overwrite option.

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

Yay! That did it! I added a --hostname and it just worked, so thanks very much.
I don't think it's to do with whether a VM already exists as I have none in my folder and have been wiping /tmp files between each build (because it doesn't clean up after dying). In my case it should have nothing to clash with as I'd never had a successful build before! It's curious that the lack of a hostname should provoke an overwrite check when the --dest param deals with where the VM will be put.
I'll report it as a documentation bug as well since the official docs on using vmbuilder don't even mention the hostname property: http://doc.ubuntu.com/ubuntu/serverguide/C/jeos-and-vmbuilder.html

Revision history for this message
Nick Barcet (nijaba) wrote : Re: [Bug 562189] Re: AttributeError: 'Libvirt' object has no attribute 'vm'

Feel free to fix it in the wiki
https://help.ubuntu.com/community/JeOSVMBuilder which was used as the
source for the doc if you have time.

Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

I'm wary of making changes there as that page is for the older shell script version of vmbuilder and I don't know if the same things apply - I don't want to break things for Intrepid users just because Lucid is different.

I also noticed that hostname is missing from the man page too.

I'm also not clear on whether hostname really is mandatory or just a means of avoiding this bug, in which case this bug report is probably good enough to be found by those that need it. I'm guessing it's just a workaround for this bug as otherwise the docs would have mentioned it.

Revision history for this message
Simon Huerlimann (huerlisi) wrote :

AFAIK the check is not if an image directory exists, but if there's some virtual machine with this name is defined in libvirt. --dest doesn't help for this reason...

@Marcus Bointon: please check if there is some .xml file in /etc/libvirt/qemu/ that looks like having no, or some kind of default (ubuntu-kvm or similar) name. This would support my theory...

Changed in vm-builder (Ubuntu):
status: New → Confirmed
Revision history for this message
Marcus Bointon (marcus-synchromedia) wrote :

There are two files in there. One called ubuntu.xml that refers to an image file created in a folder called ubuntu-kvm (i.e. a default, as you suspected), the other called vm1.xml, which is what I specified as my hostname.
I'm also curious that that file is in the libvirt folder instead of bundled with the VM image since it contains a hard-coded path to the drive image which I can see breaking very easily. The run.sh file generated by vmbuilder also contains runtime config info for the VM, but only uses a relative path, so why is it duplicated like this? Would it not be better to name run.sh <hostname>.sh and put it in the libvirt folder?

Revision history for this message
Simon Huerlimann (huerlisi) wrote :

IMHO the run.sh script should not be generated at all if the VM is registered with libvirt. As in this case 'virsh start VM' is the way to go.

Revision history for this message
Simon Huerlimann (huerlisi) wrote :

It looks like each supported hypervisor uses it's own policy regarding startup script:
* Xen => none
* VMWare => none
* VirtualBox => $DESTDIR/deploy_$hostname.sh
* KVM => $DESTDIR/run.sh

While the KVM one will get ownership set to the calling user, the VirtualBox one will not.

Revision history for this message
Herbert Roitblat (herb-orcatec) wrote :

I got this same error. I did have a previously working vm. I did set hostname.

I am working on Ubuntu 10.04 64-bit.

I moved ubuntu-kvm.

mv ubuntu-kvm old-ubuntu-kvm

I also moved othost.xml

sudo mv /etc/libvirt/qemu/othost.xml oldothost.xml

 After killing libvirtd it worked.

$ sudo vmbuilder kvm ubuntu -c otserver.cfg

Revision history for this message
Anthony O. (netangel+launchpad) wrote :

Same here. (Ubuntu 10.04 LTS / 2.6.32-22-server / x86_64)
I've tried with and without "-o", with and without extra --addpkg, and with and without --install-mirror and I removed the generated /etc/libvirt/qemu/machine.xml and I always have that error :

administrateur@master-server:~$ sudo vmbuilder kvm ubuntu --suite=lucid --flavour=virtual --arch=amd64 --hostname=test-vm --libvirt=qemu:///system --ip=192.168.0.123 --gw=192.168.0.1 --bridge=br0 --rootsize=40960 -m 512 --user=admin --name=Administrator --install-mirror=http://192.168.0.2:9999/ubuntu
2010-06-15 17:08:30,505 INFO : Calling hook: preflight_check
2010-06-15 17:08:30,508 INFO : Calling hook: set_defaults
2010-06-15 17:08:30,508 INFO : Calling hook: bootstrap
2010-06-15 17:13:03,105 INFO : Calling hook: configure_os
2010-06-15 17:13:17,118 INFO :
2010-06-15 17:13:17,118 INFO : Current default time zone: 'Etc/UTC'
2010-06-15 17:13:17,120 INFO : Local time is now: Tue Jun 15 15:13:17 UTC 2010.
2010-06-15 17:13:17,120 INFO : Universal Time is now: Tue Jun 15 15:13:17 UTC 2010.
2010-06-15 17:13:17,121 INFO :
2010-06-15 17:13:35,868 INFO :
2010-06-15 17:13:35,869 INFO : Current default time zone: 'Etc/UTC'
2010-06-15 17:13:35,871 INFO : Local time is now: Tue Jun 15 15:13:35 UTC 2010.
2010-06-15 17:13:35,871 INFO : Universal Time is now: Tue Jun 15 15:13:35 UTC 2010.
2010-06-15 17:13:35,871 INFO : Run 'dpkg-reconfigure tzdata' if you wish to change it.
2010-06-15 17:13:35,871 INFO :
2010-06-15 17:13:58,051 INFO : Calling hook: post_install
2010-06-15 17:13:58,052 INFO : Calling hook: preflight_check

Traceback (most recent call last):
  File "/usr/bin/vmbuilder", line 24, in <module>
    cli.main()
  File "/usr/lib/python2.6/dist-packages/VMBuilder/contrib/cli.py", line 116, in main
    hypervisor.install_os()
  File "/usr/lib/python2.6/dist-packages/VMBuilder/hypervisor.py", line 59, in install_os
    self.call_hooks('preflight_check')
  File "/usr/lib/python2.6/dist-packages/VMBuilder/distro.py", line 66, in call_hooks
    call_hooks(self, *args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/VMBuilder/util.py", line 158, in call_hooks
    getattr(plugin, func, log_no_such_method)(*args, **kwargs)
  File "/usr/lib/python2.6/dist-packages/VMBuilder/plugins/libvirt/__init__.py", line 54, in preflight_check
    if hostname in self.all_domains() and not self.vm.overwrite:
AttributeError: 'Libvirt' object has no attribute 'vm'

Revision history for this message
Anthony O. (netangel+launchpad) wrote :

Well, I've restarted the server, and run
administrateur@master-server:~$ sudo vmbuilder kvm ubuntu --suite=lucid --flavour=virtual --arch=amd64 --hostname=test-vm -o --libvirt=qemu:///system --ip=192.168.0.123 --gw=192.168.0.1 --bridge=br0 --rootsize=40960 -m 512 --user=admin --name=Administrator --install-mirror=http://192.168.0.2:9999/ubuntu --addpkg=unattended-upgrades --addpkg=acpid --addpkg=apt-proxy

and all goes well. I think it was due to the fact I removed the /etc/libvirt/qemu/test-vm.xml directly, without calling "sudo virsh undefine vs-test" ...

Revision history for this message
Steven Wagner (stevenwagner) wrote :

Fix on comment #7 worked for me. Just needed --hostname

Revision history for this message
Lennart Karssen (l.c.karssen) wrote :

I ran into this same problem (Ubuntu 10.04). As the successful use of the --hostname option already suggests, this has to do with the hostname given to the VM. This hostname is also used in the xml files that are placed in the /etc/libvirt/qemu directory as noted in comments #11/#12/#15. If one wants to (re-)create a VM with a name that has been used previously, it is not only necessary to remove the .xml file in /etc/libvirt/qemu/ (comment #15), but also that libvirtd is told to remove the VM definition (basically what comment #15 did by restarting libvirtd).

The simplest way to tell libvirtd to forget about the old VM host is to run virsh --connect qemu:///system undefine your_hostname (this also removes the .xml file from /etc/libvirt/qemu).

So I guess the simplest fix for this bug is outputting an error message if the hostname of the new VM already exists.

Revision history for this message
Jerome Potts (jerome-potts) wrote :

Yes, when recreating a VM, first do a "virsh undefine <vm name>", then run your vmbuilder command.

It's too bad that you hit that error 28 mn in the game : a verification could be added to vmbuilder's preflight_check, or, vmbuilder could perform the undefine itself.

Revision history for this message
Daryl Lublink (dlublink) wrote :

I also got this error message. In the ubuntu-vm-builder, I had "--hostname 'test-vm' ", I changed it to "--hostname 'testvm' " and the problem disappears. So I believe the issue has to do with the minus sign in the hostname parameter.

Revision history for this message
Walt Corey (waltc) wrote :

I also got this error on 10.10 and, to David's comment, changing the name of the --hostname bypassed the problem as you created a new vm. But using virsh or virt-manager to delete the pre-existing image resolved the problem. However, my question is this. Is the -o option intended to remove any files, including a preexisting image or does it just remove other transient files that may exist but is NOT intended to delete what may be a functioning production VM?

For myself, I am totally fine with Lennart's suggestion of an error message if the vm exists already. Would someone clarify what the purpose of the -o is in that case?

Revision history for this message
Richard C (richard-c) wrote :
Download full text (8.6 KiB)

In current Natty, I get a slightly different version of this (output below). The same error occurs, but at the cleaning up step. The "make_vm.sh" blow contains the same vmbuilder command as above. Should this be raised as a separate bug?

Thanks,

Richard

(example run)

user@host:~$ ./make_vm.sh
2011-06-08 13:11:13,044 INFO : Calling hook: preflight_check
2011-06-08 13:11:13,046 INFO : Calling hook: set_defaults
2011-06-08 13:11:13,046 INFO : Calling hook: bootstrap
2011-06-08 13:14:02,506 INFO : Calling hook: configure_os
2011-06-08 13:14:27,787 INFO : Updating certificates in /etc/ssl/certs... WARNING: Skipping duplicate certificate brasil.gov.br.pem
2011-06-08 13:14:27,787 INFO : 141 added, 0 removed; done.
2011-06-08 13:14:27,790 INFO : Running hooks in /etc/ca-certificates/update.d....done.
2011-06-08 13:14:28,450 INFO : Creating SSH2 RSA key; this may take some time ...
2011-06-08 13:14:28,655 INFO : Creating SSH2 DSA key; this may take some time ...
2011-06-08 13:14:28,660 INFO : Creating SSH2 ECDSA key; this may take some time ...
2011-06-08 13:14:28,743 INFO :
2011-06-08 13:14:28,743 INFO : Warning: Fake initctl called, doing nothing
2011-06-08 13:14:28,744 INFO :
2011-06-08 13:14:28,744 INFO : Warning: Fake initctl called, doing nothing
2011-06-08 13:14:29,658 INFO :
2011-06-08 13:14:29,659 INFO : Current default time zone: 'Etc/UTC'
2011-06-08 13:14:29,665 INFO : Local time is now: Wed Jun 8 03:14:29 UTC 2011.
2011-06-08 13:14:29,666 INFO : Universal Time is now: Wed Jun 8 03:14:29 UTC 2011.
2011-06-08 13:14:29,666 INFO :
2011-06-08 13:14:35,096 INFO : gpg: key 437D05B5: "Ubuntu Archive Automatic Signing Key <email address hidden>" not changed
2011-06-08 13:14:35,099 INFO : gpg: key FBB75451: "Ubuntu CD Image Automatic Signing Key <email address hidden>" not changed
2011-06-08 13:14:35,099 INFO : gpg: Total number processed: 2
2011-06-08 13:14:35,099 INFO : gpg: unchanged: 2
2011-06-08 13:14:35,686 INFO :
2011-06-08 13:14:35,687 INFO : Current default time zone: 'Etc/UTC'
2011-06-08 13:14:35,694 INFO : Local time is now: Wed Jun 8 03:14:35 UTC 2011.
2011-06-08 13:14:35,694 INFO : Universal Time is now: Wed Jun 8 03:14:35 UTC 2011.
2011-06-08 13:14:35,694 INFO : Run 'dpkg-reconfigure tzdata' if you wish to change it.
2011-06-08 13:14:35,694 INFO :
2011-06-08 13:14:41,491 INFO : Calling hook: post_install
2011-06-08 13:14:41,493 INFO : Cleaning up
2011-06-08 13:14:41,496 INFO : Calling hook: preflight_check
2011-06-08 13:14:42,506 INFO : Calling hook: configure_networking
2011-06-08 13:14:42,528 INFO : Calling hook: configure_mounting
2011-06-08 13:14:42,533 INFO : Calling hook: mount_partitions
2011-06-08 13:14:42,533 INFO : Mounting target filesystems
2011-06-08 13:14:42,533 INFO : Creating disk image: "/tmp/tmpVCe1ie" of size: 12001MB
2011-06-08 13:14:42,542 INFO : Adding partition table to disk image: /tmp/tmpVCe1ie
2011-06-08 13:14:42,563 INFO : Adding type 4 partition to disk image: /tmp/tmpVCe1ie
2011-06-08 13:14:42,564 INFO : Partition at beginning of disk - reserving first cylind...

Read more...

Revision history for this message
Richard C (richard-c) wrote :

For the issue I reported above, I believe this is a bug. There are two checks for pre-existing VMs, and they differ:
/usr/lib/python2.7/dist-packages/VMBuilder/plugins/libvirt/__init__.py
line 54: if hostname in self.all_domains() and not self.context.overwrite:
line 80: if hostname in self.all_domains() and not self.vm.overwrite:

Changing line 80 to match line 54 prevents this error.

Line 80 throws an error when run:
Traceback (most recent call last):
  File "/usr/bin/vmbuilder", line 24, in <module>
    cli.main()
  File "/usr/lib/python2.7/dist-packages/VMBuilder/contrib/cli.py", line 227, in main
    hypervisor.finalise(destdir)
  File "/usr/lib/python2.7/dist-packages/VMBuilder/hypervisor.py", line 78, in finalise
    self.call_hooks('deploy', destdir)
  File "/usr/lib/python2.7/dist-packages/VMBuilder/distro.py", line 67, in call_hooks
    call_hooks(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/VMBuilder/util.py", line 158, in call_hooks
    getattr(plugin, func, log_no_such_method)(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/VMBuilder/plugins/libvirt/__init__.py", line 80, in deploy
    if hostname in self.all_domains() and not self.vm.overwrite:
AttributeError: 'Libvirt' object has no attribute 'vm'

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.