37
37
if not libvirt_uri:
40
if not self.context.name == 'KVM':
41
raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')
44
import xml.etree.ElementTree
42
46
self.conn = libvirt.open(libvirt_uri)
44
hostname = self.context.get_setting('hostname')
48
e = xml.etree.ElementTree.fromstring(self.conn.getCapabilities())
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')
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))
48
if not self.context.hypervisor.name == 'KVM':
49
raise VMBuilderUserError('The libvirt plugin is only equiped to work with KVM at the moment.')
51
57
def deploy(self, destdir):
52
58
libvirt_uri = self.get_setting('libvirt')
53
59
if not libvirt_uri:
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)
68
77
vmxml = VMBuilder.util.render_template('libvirt', self.context, 'libvirtxml', tmpl_ctxt)
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))