Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 6ec28e3

Browse files
committed
osdict: Use variables for common device settings
Improves readability a bit.
1 parent a298b00 commit 6ec28e3

3 files changed

Lines changed: 152 additions & 57 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<domain type='xen'>
2+
<name>TestGuest</name>
3+
<currentMemory>204800</currentMemory>
4+
<memory>409600</memory>
5+
<uuid>12345678-1234-1234-1234-123456789012</uuid>
6+
<os>
7+
<type arch='i686'>hvm</type>
8+
<loader>/usr/lib/xen/boot/hvmloader</loader>
9+
<boot dev='hd'/>
10+
</os>
11+
<features>
12+
<acpi/><apic/>
13+
</features>
14+
<clock offset="utc"/>
15+
<on_poweroff>destroy</on_poweroff>
16+
<on_reboot>restart</on_reboot>
17+
<on_crash>restart</on_crash>
18+
<vcpu>5</vcpu>
19+
<devices>
20+
<emulator>/usr/lib/xen/bin/qemu-dm</emulator>
21+
<disk type='file' device='floppy'>
22+
<source file='/default-pool/testvol1.img'/>
23+
<target dev='fda' bus='fdc'/>
24+
</disk>
25+
<disk type='file' device='disk'>
26+
<source file='/tmp/test.img'/>
27+
<target dev='hda' bus='ide'/>
28+
</disk>
29+
<disk type='block' device='disk'>
30+
<source dev='/dev/loop0'/>
31+
<target dev='hdb' bus='ide'/>
32+
</disk>
33+
<disk type='file' device='cdrom'>
34+
<source file='/default-pool/default-vol'/>
35+
<target dev='hdc' bus='ide'/>
36+
<readonly/>
37+
</disk>
38+
<interface type='network'>
39+
<source network='default'/>
40+
<mac address='11:22:33:44:55:66'/>
41+
</interface>
42+
<input type='tablet' bus='usb'/>
43+
<graphics type='sdl' display=':3.4' xauth='/tmp/.Xauthority'/>
44+
<console type='pty'/>
45+
</devices>
46+
</domain>

tests/xmlconfig.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,20 @@ def testF11(self):
345345
g.nics.append(get_virtual_network())
346346
self._compare(g, "install-f11", False)
347347

348+
def testF11Xen(self):
349+
g = get_basic_fullyvirt_guest("xen")
350+
g.os_type = "linux"
351+
g.os_variant = "fedora11"
352+
g.installer = virtinst.DistroInstaller(type="xen", os_type="hvm",
353+
conn=g.conn,
354+
location="/default-pool/default-vol")
355+
g.installer.cdrom = True
356+
g.disks.append(get_floppy())
357+
g.disks.append(get_filedisk())
358+
g.disks.append(get_blkdisk())
359+
g.nics.append(get_virtual_network())
360+
self._compare(g, "install-f11-xen", False)
361+
348362
def testBootWindows(self):
349363
g = get_basic_fullyvirt_guest("kvm")
350364
g.os_type = "windows"

virtinst/osdict.py

Lines changed: 92 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import libvirt
2323

2424
import _util
25+
from virtinst import _virtinst as _
2526

2627
"""
2728
Default values for OS_TYPES keys. Can be overwritten at os_type or
@@ -38,10 +39,26 @@
3839
"devices" : {
3940
# "devname" : { "attribute" : [( ["applicable", "hv-type", list"],
4041
# "recommended value for hv-types" ),]},
41-
"input" : { "type" : [ (["all"], "mouse") ],
42-
"bus" : [ (["all"], "ps2") ] },
43-
"disk" : { "bus" : [ (["all"], None) ] },
44-
"net" : { "model": [ (["all"], None) ] },
42+
"input" : {
43+
"type" : [
44+
(["all"], "mouse")
45+
],
46+
"bus" : [
47+
(["all"], "ps2")
48+
],
49+
},
50+
51+
"disk" : {
52+
"bus" : [
53+
(["all"], None)
54+
],
55+
},
56+
57+
"net" : {
58+
"model": [
59+
(["all"], None)
60+
],
61+
},
4562
}
4663
}
4764

@@ -75,6 +92,7 @@ def parse_key_entry(conn, hv_type, key_entry):
7592
except:
7693
drvver = 0
7794

95+
ret = None
7896
if type(key_entry) == list:
7997
# List of tuples with hv_type, version, etc. mappings
8098
for tup in key_entry:
@@ -99,9 +117,12 @@ def parse_key_entry(conn, hv_type, key_entry):
99117
if exp_lib_ver and libver > exp_lib_ver:
100118
continue
101119

102-
return val
120+
ret = val
121+
break
103122
else:
104-
return key_entry
123+
ret = key_entry
124+
125+
return ret
105126

106127
def lookup_osdict_key(conn, hv_type, os_type, var, key):
107128

@@ -129,12 +150,33 @@ def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
129150
raise RuntimeError(_("Invalid dictionary entry for device '%s %s'" %
130151
(device_key, param)))
131152

153+
VIRTIO_DISK = {
154+
"bus" : [
155+
(["kvm"], "virtio"),
156+
]
157+
}
158+
159+
VIRTIO_NET = {
160+
"model" : [
161+
(["kvm"], "virtio"),
162+
]
163+
}
164+
165+
USB_TABLET = {
166+
"type" : [
167+
(["all"], "tablet"),
168+
],
169+
"bus" : [
170+
(["all"], "usb"),
171+
]
172+
}
173+
132174
# NOTE: keep variant keys using only lowercase so we can do case
133175
# insensitive checks on user passed input
134-
OS_TYPES = {\
135-
"linux": { \
176+
OS_TYPES = {
177+
"linux": {
136178
"label": "Linux",
137-
"variants": { \
179+
"variants": {
138180
"rhel2.1": { "label": "Red Hat Enterprise Linux 2.1",
139181
"distro": "rhel" },
140182
"rhel3": { "label": "Red Hat Enterprise Linux 3",
@@ -157,100 +199,95 @@ def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
157199
# Apparently F9 has selinux errors when installing
158200
# with virtio:
159201
# https://bugzilla.redhat.com/show_bug.cgi?id=470386
160-
#"disk" : { "bus" : [ (["kvm"], "virtio") ] },
161-
"net" : { "model" : [ (["kvm"], "virtio") ] }
202+
#"disk" : VIRTIO_DISK,
203+
"net" : VIRTIO_NET,
162204
}},
163205
"fedora10": { "label": "Fedora 10", "distro": "fedora",
164206
"devices" : {
165-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
166-
"net" : { "model" : [ (["kvm"], "virtio") ] }
207+
"disk" : VIRTIO_DISK,
208+
"net" : VIRTIO_NET,
167209
}},
168210
"fedora11": { "label": "Fedora 11", "distro": "fedora",
169211
"devices" : {
170-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
171-
"net" : { "model" : [ (["kvm"], "virtio") ] },
172-
"input" : { "type" : [ (["all"], "tablet") ],
173-
"bus" : [ (["all"], "usb"), ] },
212+
"disk" : VIRTIO_DISK,
213+
"net" : VIRTIO_NET,
214+
"input": USB_TABLET,
174215
}},
175216
"fedora12": { "label": "Fedora 12", "distro": "fedora",
176217
"devices" : {
177-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
178-
"net" : { "model" : [ (["kvm"], "virtio") ] },
179-
"input" : { "type" : [ (["all"], "tablet") ],
180-
"bus" : [ (["all"], "usb"), ] },
218+
"disk" : VIRTIO_DISK,
219+
"net" : VIRTIO_NET,
220+
"input": USB_TABLET,
181221
}},
182222
"fedora12": { "label": "Fedora 12", "distro": "fedora",
183223
"devices" : {
184-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
185-
"net" : { "model" : [ (["kvm"], "virtio") ] },
186-
"input" : { "type" : [ (["all"], "tablet") ],
187-
"bus" : [ (["all"], "usb"), ] },
224+
"disk" : VIRTIO_DISK,
225+
"net" : VIRTIO_NET,
226+
"input": USB_TABLET,
188227
}},
189228
"sles10": { "label": "Suse Linux Enterprise Server",
190229
"distro": "suse" },
191230
"sles11": { "label": "Suse Linux Enterprise Server 11",
192231
"distro": "suse",
193232
"devices" : {
194-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
195-
"net" : { "model" : [ (["kvm"], "virtio") ] },
196-
},
233+
"disk" : VIRTIO_DISK,
234+
"net" : VIRTIO_NET,
235+
},
197236
},
198237
"debianetch": { "label": "Debian Etch", "distro": "debian" },
199238
"debianlenny": { "label": "Debian Lenny", "distro": "debian",
200239
"devices" : {
201-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
202-
"net" : { "model" : [ (["kvm"], "virtio") ] }
240+
"disk" : VIRTIO_DISK,
241+
"net" : VIRTIO_NET,
203242
}},
204243
"debiansqueeze": { "label": "Debian Squeeze", "distro": "debian",
205244
"devices" : {
206-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
207-
"net" : { "model" : [ (["kvm"], "virtio") ] },
208-
"input" : { "type" : [ (["all"], "tablet") ],
209-
"bus" : [ (["all"], "usb"), ] },
245+
"disk" : VIRTIO_DISK,
246+
"net" : VIRTIO_NET,
247+
"input": USB_TABLET,
210248
}},
211249
"ubuntuhardy": { "label": "Ubuntu 8.04 LTS (Hardy Heron)",
212250
"distro": "ubuntu",
213251
"devices" : {
214-
"net" : { "model" : [ (["kvm"], "virtio") ] }
252+
"net" : VIRTIO_NET,
215253
}},
216254
"ubuntuintrepid": { "label": "Ubuntu 8.10 (Intrepid Ibex)",
217255
"distro": "ubuntu",
218256
"devices" : {
219-
"net" : { "model" : [ (["kvm"], "virtio") ] }
257+
"net" : VIRTIO_NET,
220258
}},
221259
"ubuntujaunty": { "label": "Ubuntu 9.04 (Jaunty Jackalope)",
222260
"distro": "ubuntu",
223261
"devices" : {
224-
"net" : { "model" : [ (["kvm"], "virtio") ] },
225-
"disk" : { "bus" : [ (["kvm"], "virtio") ] }
262+
"disk" : VIRTIO_DISK,
263+
"net" : VIRTIO_NET,
226264
}},
227265
"ubuntukarmic": { "label": "Ubuntu 9.10 (Karmic Koala)",
228266
"distro": "ubuntu",
229267
"devices" : {
230-
"net" : { "model" : [ (["kvm"], "virtio") ] },
231-
"disk" : { "bus" : [ (["kvm"], "virtio") ] }
268+
"disk" : VIRTIO_DISK,
269+
"net" : VIRTIO_NET,
232270
}},
233271
"generic24": { "label": "Generic 2.4.x kernel" },
234272
"generic26": { "label": "Generic 2.6.x kernel" },
235273
"virtio26": { "sortby": "genericvirtio26",
236274
"label": "Generic 2.6.25 or later kernel with virtio",
237275
"devices" : {
238-
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
239-
"net" : { "model" : [ (["kvm"], "virtio") ] }
276+
"disk" : VIRTIO_DISK,
277+
"net" : VIRTIO_NET,
240278
}},
241279

242280
},
243281
},
244282

245-
"windows": { \
283+
"windows": {
246284
"label": "Windows",
247285
"clock": "localtime",
248286
"continue": True,
249287
"devices" : {
250-
"input" : { "type" : [ (["all"], "tablet") ],
251-
"bus" : [ (["all"], "usb"), ] },
288+
"input" : USB_TABLET,
252289
},
253-
"variants": { \
290+
"variants": {
254291
"winxp":{ "label": "Microsoft Windows XP (x86)",
255292
"acpi": [ ("xen", 3001000, False),
256293
("all", True ), ],
@@ -276,23 +313,21 @@ def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
276313
"variants": {
277314
"solaris9": { "label": "Sun Solaris 9", },
278315
"solaris10": { "label": "Sun Solaris 10",
279-
"devices" : { "input" : {
280-
"type" : [ (["all"], "tablet") ],
281-
"bus" : [ (["all"], "usb"), ]
282-
} },
316+
"devices" : {
317+
"input" : USB_TABLET,
318+
},
283319
},
284320
"opensolaris": { "label": "Sun OpenSolaris",
285-
"devices" : { "input" : {
286-
"type" : [ (["all"], "tablet") ],
287-
"bus" : [ (["all"], "usb"), ]
288-
} },
321+
"devices" : {
322+
"input" : USB_TABLET,
323+
},
289324
},
290325
},
291326
},
292327

293328
"unix": {
294329
"label": "UNIX",
295-
"variants": { \
330+
"variants": {
296331
"freebsd6": { "label": "Free BSD 6.x" ,
297332
# http://www.nabble.com/Re%3A-Qemu%3A-bridging-on-FreeBSD-7.0-STABLE-p15919603.html
298333
"devices" : {
@@ -311,9 +346,9 @@ def lookup_device_param(conn, hv_type, os_type, var, device_key, param):
311346
},
312347
},
313348

314-
"other": { \
349+
"other": {
315350
"label": "Other",
316-
"variants": { \
351+
"variants": {
317352
"msdos": { "label": "MS-DOS", "acpi": False, "apic": False },
318353
"netware4": { "label": "Novell Netware 4" },
319354
"netware5": { "label": "Novell Netware 5" },

0 commit comments

Comments
 (0)