26
26
import DistroManager
31
from VirtualDisk import VirtualDisk
32
from DistroManager import PXEInstaller
29
33
from virtinst import _virtinst as _
32
36
class FullVirtGuest(Guest.XenGuest):
33
OS_TYPES = { "linux": { "label": "Linux", \
38
"input": [ "mouse", "ps2"],
39
"variants": { "rhel2.1": { "label": "Red Hat Enterprise Linux 2.1", "distro": "rhel" }, \
40
"rhel3": { "label": "Red Hat Enterprise Linux 3", "distro": "rhel" }, \
41
"rhel4": { "label": "Red Hat Enterprise Linux 4", "distro": "rhel" }, \
42
"rhel5": { "label": "Red Hat Enterprise Linux 5", "distro": "rhel" }, \
43
"fedora5": { "label": "Fedora Core 5", "distro": "fedora" }, \
44
"fedora6": { "label": "Fedora Core 6", "distro": "fedora" }, \
45
"fedora7": { "label": "Fedora 7", "distro": "fedora" }, \
46
"fedora8": { "label": "Fedora 8", "distro": "fedora" }, \
47
"sles10": { "label": "Suse Linux Enterprise Server", "distro": "suse" }, \
48
"debianEtch": { "label": "Debian Etch", "distro": "debian" }, \
49
"debianLenny": { "label": "Debian Lenny", "distro": "debian" }, \
50
"generic24": { "label": "Generic 2.4.x kernel" }, \
51
"generic26": { "label": "Generic 2.6.x kernel" }, \
54
"windows": { "label": "Windows", \
57
"clock": "localtime",\
59
"input": [ "tablet", "usb"],
60
"variants": { "winxp": { "label": "Microsoft Windows XP", \
63
"win2k": { "label": "Microsoft Windows 2000", \
66
"win2k3": { "label": "Microsoft Windows 2003" }, \
67
"vista": { "label": "Microsoft Windows Vista" }, \
70
"unix": { "label": "UNIX", \
75
"input": [ "mouse", "ps2"],
76
"variants": { "solaris9": { "label": "Sun Solaris 9" }, \
77
"solaris10": { "label": "Sun Solaris 10" }, \
78
"freebsd6": { "label": "Free BSD 6.x" }, \
79
"openbsd4": { "label": "Open BSD 4.x" }, \
82
"other": { "label": "Other", \
87
"input": [ "mouse", "ps2"],
88
"variants": { "msdos": { "label": "MS-DOS", \
91
"netware4": { "label": "Novell Netware 4" }, \
92
"netware5": { "label": "Novell Netware 5" }, \
93
"netware6": { "label": "Novell Netware 6" }, \
94
"generic": { "label": "Generic" }, \
39
Default values for OS_TYPES keys. Can be overwritten at os_type or
50
# "devname" : { "attribute" : [( ["applicable", "hv-type", list"],
51
# "recommended value for hv-types" ),]},
52
"input" : { "type" : [ (["all"], "mouse") ],
53
"bus" : [ (["all"], "ps2") ] },
54
"disk" : { "bus" : [ (["all"], None) ] },
55
"net" : { "model": [ (["all"], None) ] },
60
# NOTE: keep variant keys using only lowercase so we can do case
61
# insensitive checks on user passed input
66
"rhel2.1": { "label": "Red Hat Enterprise Linux 2.1",
68
"rhel3": { "label": "Red Hat Enterprise Linux 3",
70
"rhel4": { "label": "Red Hat Enterprise Linux 4",
72
"rhel5": { "label": "Red Hat Enterprise Linux 5",
74
"fedora5": { "label": "Fedora Core 5", "distro": "fedora" },
75
"fedora6": { "label": "Fedora Core 6", "distro": "fedora" },
76
"fedora7": { "label": "Fedora 7", "distro": "fedora" },
77
"fedora8": { "label": "Fedora 8", "distro": "fedora" },
78
"fedora9": { "label": "Fedora 9", "distro": "fedora" },
79
"fedora10": { "label": "Fedora 10", "distro": "fedora",
81
"disk" : { "bus" : [ (["kvm"], "virtio") ] },
82
"net" : { "model" : [ (["kvm"], "virtio") ] }
84
"sles10": { "label": "Suse Linux Enterprise Server",
86
"debianetch": { "label": "Debian Etch", "distro": "debian" },
87
"debianlenny": { "label": "Debian Lenny", "distro": "debian" },
88
"ubuntuhardy": { "label": "Ubuntu Hardy", "distro": "ubuntu",
90
"net" : { "model" : [ (["kvm"], "virtio") ] }
92
"generic24": { "label": "Generic 2.4.x kernel" },
93
"generic26": { "label": "Generic 2.6.x kernel" },
102
"input" : { "type" : [ (["all"], "tablet") ],
103
"bus" : [ (["all"], "usb"), ] },
106
"winxp":{ "label": "Microsoft Windows XP",
107
"acpi": False, "apic": False },
108
"win2k": { "label": "Microsoft Windows 2000",
109
"acpi": False, "apic": False },
110
"win2k3": { "label": "Microsoft Windows 2003" },
111
"win2k8": { "label": "Microsoft Windows 2008" },
112
"vista": { "label": "Microsoft Windows Vista" },
119
"solaris9": { "label": "Sun Solaris 9" },
120
"solaris10": { "label": "Sun Solaris 10" },
121
"freebsd6": { "label": "Free BSD 6.x" ,
122
# http://www.nabble.com/Re%3A-Qemu%3A-bridging-on-FreeBSD-7.0-STABLE-p15919603.html
124
"net" : { "model" : [ (["all"], "ne2k_pci") ] }
126
"freebsd7": { "label": "Free BSD 7.x" ,
128
"net" : { "model" : [ (["all"], "ne2k_pci") ] }
130
"openbsd4": { "label": "Open BSD 4.x" ,
131
# http://calamari.reverse-dns.net:980/cgi-bin/moin.cgi/OpenbsdOnQemu
132
# https://www.redhat.com/archives/et-mgmt-tools/2008-June/msg00018.html
134
"net" : { "model" : [ (["all"], "pcnet") ] }
142
"msdos": { "label": "MS-DOS", "acpi": False, "apic": False },
143
"netware4": { "label": "Novell Netware 4" },
144
"netware5": { "label": "Novell Netware 5" },
145
"netware6": { "label": "Novell Netware 6" },
146
"generic": { "label": "Generic" },
99
150
def list_os_types():
100
return FullVirtGuest.OS_TYPES.keys()
151
return FullVirtGuest._OS_TYPES.keys()
101
152
list_os_types = staticmethod(list_os_types)
103
154
def list_os_variants(type):
104
return FullVirtGuest.OS_TYPES[type]["variants"].keys()
155
return FullVirtGuest._OS_TYPES[type]["variants"].keys()
105
156
list_os_variants = staticmethod(list_os_variants)
107
158
def get_os_type_label(type):
108
return FullVirtGuest.OS_TYPES[type]["label"]
159
return FullVirtGuest._OS_TYPES[type]["label"]
109
160
get_os_type_label = staticmethod(get_os_type_label)
111
162
def get_os_variant_label(type, variant):
112
return FullVirtGuest.OS_TYPES[type]["variants"][variant]["label"]
163
return FullVirtGuest._OS_TYPES[type]["variants"][variant]["label"]
113
164
get_os_variant_label = staticmethod(get_os_variant_label)
138
202
def get_os_type(self):
139
203
return self._os_type
140
204
def set_os_type(self, val):
141
if FullVirtGuest.OS_TYPES.has_key(val):
205
if type(val) is not str:
206
raise ValueError(_("OS type must be a string."))
208
if FullVirtGuest._OS_TYPES.has_key(val):
142
209
self._os_type = val
210
# Invalidate variant, since it may not apply to the new os type
211
self._os_variant = None
144
raise ValueError, _("OS type %s does not exist in our dictionary") % val
213
raise ValueError, _("OS type '%s' does not exist in our "
145
215
os_type = property(get_os_type, set_os_type)
147
217
def get_os_variant(self):
148
218
return self._os_variant
149
219
def set_os_variant(self, val):
150
if not self._os_type:
151
raise ValueError, _("An OS type must be specified before a variant.")
152
if FullVirtGuest.OS_TYPES[self._os_type]["variants"].has_key(val):
153
self._os_variant = val
220
if type(val) is not str:
221
raise ValueError(_("OS variant must be a string."))
224
if self._OS_TYPES[self._os_type]["variants"].has_key(val):
225
self._os_variant = val
227
raise ValueError, _("OS variant '%(var)s; does not exist in "
228
"our dictionary for OS type '%(ty)s'" ) % \
229
{'var' : val, 'ty' : self._os_type}
155
raise ValueError, _("OS variant %(var)s does not exist in our dictionary for OS type %(type)s") % {'var' : val, 'type' : self._os_type}
231
for ostype in self.list_os_types():
232
if self._OS_TYPES[ostype]["variants"].has_key(val):
233
logging.debug("Setting os type to '%s' for variant '%s'" %\
235
self.os_type = ostype
236
self._os_variant = val
238
raise ValueError, _("Unknown OS variant '%s'" % val)
156
239
os_variant = property(get_os_variant, set_os_variant)
158
241
def os_features(self):
271
334
# for inactive guest, or get the still running install..
272
335
return self.conn.lookupByName(self.name)
337
def _lookup_osdict_key(self, key):
339
Using self.os_type and self.os_variant to find key in OSTYPES
340
@returns: dict value, or None if os_type/variant wasn't set
343
var = self.os_variant
345
if var and self._OS_TYPES[typ]["variants"][var].has_key(key):
346
return self._OS_TYPES[typ]["variants"][var][key]
347
elif self._OS_TYPES[typ].has_key(key):
348
return self._OS_TYPES[typ][key]
349
return self._DEFAULTS[key]
351
def _lookup_device_param(self, device_key, param):
352
os_devs = self._lookup_osdict_key("devices")
353
default_devs = self._DEFAULTS["devices"]
354
for devs in [os_devs, default_devs]:
355
if not devs.has_key(device_key):
357
for ent in devs[device_key][param]:
360
if self.type in hv_types:
362
elif "all" in hv_types:
364
raise RuntimeError(_("Invalid dictionary entry for device '%s %s'" % \
365
(device_key, param)))
274
367
def _get_disk_xml(self, install = True):
275
368
"""Get the disk config in the libvirt XML format"""
279
n = "%s%c" % (self.disknode, ord('a') + i)
282
# First assign CDROM device nodes, since they're scarce resource
283
cdnode = self.disknode + "c"
284
for d in self._install_disks:
285
if d.device != Guest.VirtualDisk.DEVICE_CDROM:
289
if d.target != cdnode:
290
raise ValueError, "The CDROM must be device %s" % cdnode
294
if nodes[d.target] != None:
295
raise ValueError, "The CDROM device %s is already used" % d.target
298
# Now assign regular disk node with remainder
299
for d in self._install_disks:
300
if d.device == Guest.VirtualDisk.DEVICE_CDROM:
303
if d.target is None: # Auto-assign disk
304
for n in sorted(nodes.keys()):
310
if nodes[d.target] != None: # Verify pre-assigned
311
raise ValueError, "The disk device %s is already used" % d.target
371
for disk in self._install_disks:
374
used_targets.append(disk.generate_target(used_targets))
314
376
for d in self._install_disks:
315
377
saved_path = None
316
if d.device == Guest.VirtualDisk.DEVICE_CDROM and d.transient and not install:
317
# XXX hack. libvirt can't currently handle QEMU having an empty disk path..
318
if self.type == "xen":
378
if d.device == VirtualDisk.DEVICE_CDROM \
379
and d.transient and not install:
380
# Keep cdrom around, but with no media attached
381
# But only if we are a distro that doesn't have a multi
382
# stage install (aka not Windows)
384
if not self.get_continue_inst():
322
# .. so simply remove CDROM device completely in non-Xen
325
389
ret += d.get_xml_config(d.target)
326
390
if saved_path != None:
327
391
d.path = saved_path
395
def _set_defaults(self):
396
Guest.Guest._set_defaults(self)
398
disk_bus = self._lookup_device_param("disk", "bus")
399
net_model = self._lookup_device_param("net", "model")
402
# Only overwrite params if they weren't already specified
403
for net in self._install_nics:
404
if net_model and not net.model:
405
if net_model == "virtio":
406
# virtio net doesn't seem to support pxe, skip first interface
407
if not pxe_skipped and isinstance(self.installer, PXEInstaller):
410
net.model = net_model
411
for disk in self._install_disks:
412
if disk_bus and not disk.bus: