~ubuntu-branches/ubuntu/maverick/vm-builder/maverick

« back to all changes in this revision

Viewing changes to VMBuilder/plugins/libvirt/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2010-02-24 23:52:03 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20100224235203-v513a24nfv66160q
Tags: 0.12.1-0ubuntu1
New upstream, bugfix-only release. (LP: #303882, #523589, #261702,
#284620, #527240, #527253)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
        if not libvirt_uri:
38
38
            return True
39
39
 
 
40
        if not self.context.name == 'KVM':
 
41
            raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')
 
42
 
40
43
        import libvirt
 
44
        import xml.etree.ElementTree
41
45
 
42
46
        self.conn = libvirt.open(libvirt_uri)
43
47
 
44
 
        hostname = self.context.get_setting('hostname')
 
48
        e = xml.etree.ElementTree.fromstring(self.conn.getCapabilities())
 
49
 
 
50
        if not 'hvm' in [x.text for x in e.getiterator('os_type')]:
 
51
            raise VMBuilderUserError('libvirt does not seem to want to accept hvm domains')
 
52
 
 
53
        hostname = self.context.distro.get_setting('hostname')
45
54
        if hostname in self.all_domains() and not self.vm.overwrite:
46
55
            raise VMBuilderUserError('Domain %s already exists at %s' % (hostname, libvirt_uri))
47
56
        
48
 
        if not self.context.hypervisor.name == 'KVM':
49
 
            raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')
50
 
 
51
57
    def deploy(self, destdir):
52
58
        libvirt_uri = self.get_setting('libvirt')
53
59
        if not libvirt_uri:
54
60
            # Not for us
55
61
            return False
56
62
 
 
63
        hostname = self.context.distro.get_setting('hostname')
57
64
        tmpl_ctxt = { 'mem': self.context.get_setting('mem'),
58
 
                      'cpus' : self.context.get_setting('cpus'),
 
65
                      'cpus': self.context.get_setting('cpus'),
59
66
                      'bridge' : self.context.get_setting('bridge'),
60
67
                      'mac' : self.context.get_setting('mac'),
61
68
                      'network' : self.context.get_setting('network'),
62
 
                      'virtio_net' : self.context.get_setting('virtio-net'),
 
69
                      'mac' : self.context.get_setting('mac'),
 
70
                      'virtio_net' : self.context.distro.use_virtio_net(),
63
71
                      'disks' : self.context.disks,
64
 
                      'filesystems' : self.context.filesystems }
 
72
                      'filesystems' : self.context.filesystems,
 
73
                      'hostname' : hostname }
65
74
        if self.context.preferred_storage == VMBuilder.hypervisor.STORAGE_FS_IMAGE:
66
75
            vmxml = VMBuilder.util.render_template('libvirt', self.context, 'libvirtxml_fsimage', tmpl_ctxt)
67
76
        else:
68
77
            vmxml = VMBuilder.util.render_template('libvirt', self.context, 'libvirtxml', tmpl_ctxt)
69
78
 
70
 
        hostname = self.context.get_setting('hostname')
71
79
        if hostname in self.all_domains() and not self.vm.overwrite:
72
80
            raise VMBuilderUserError('Domain %s already exists at %s' % (hostname, libvirt_uri))
73
81
        else: