3 # Copyright (C) 2014 Red Hat Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 # Generate libvirt XML. Would be nice to use virt-install here, but
24 # it doesn't work: RHBZ#1095789
25 def generate_libvirt_xml (vm_name, memory, vcpus, virtio, output):
26 network_model = "virtio"
28 network_model = "e1000"
30 # Give the network a fixed MAC address, otherwise libvirt will
31 # generate a random one on every guest restart.
32 network_mac = "52:54:00:%02x:%02x:%02x" % (random.randint (0, 0xff),
33 random.randint (0, 0xff),
34 random.randint (0, 0xff))
36 # XXX Quoting, and we should use a real XML generator.
40 <memory unit='MiB'>%d</memory>
41 <currentMemory unit='MiB'>%d</currentMemory>
52 <cpu mode='host-model' fallback='allow' />
54 <timer name='rtc' tickpolicy='catchup'/>
55 <timer name='pit' tickpolicy='delay'/>
56 <timer name='hpet' present='no'/>
58 <on_poweroff>destroy</on_poweroff>
59 <on_reboot>restart</on_reboot>
60 <on_crash>restart</on_crash>
62 <interface type='bridge'>
64 <source bridge='br0'/>
68 <target type='virtio' port='0'/>
70 <input type='tablet' bus='usb'/>
71 <input type='mouse' bus='ps2'/>
72 <!-- <input type='keyboard' bus='ps2'/> -->
73 <graphics type='vnc' autoport='yes'/>
75 <model type='cirrus' vram='9216' heads='1'/>
77 """ % (vm_name, memory, memory, vcpus, network_mac, network_model)
79 # virtio-scsi or IDE disk:
82 <controller type="scsi" index="0" model="virtio-scsi"/>
83 <disk type='file' device='disk'>
84 <driver name='qemu' type='qcow2' cache='none' io='native'/>
86 <target dev='sda' bus='scsi'/>
91 <disk type='file' device='disk'>
92 <driver name='qemu' type='qcow2' cache='none' io='native'/>
94 <target dev='sda' bus='ide'/>