33
33
class ImageInstaller(Installer.Installer):
34
34
"""Installer for image-based guests"""
35
35
def __init__(self, image, capabilities=None, boot_index=None, conn=None):
36
Installer.Installer.__init__(self, conn=conn)
36
Installer.Installer.__init__(self, conn=conn, caps=capabilities)
39
39
self._image = image
43
self._capabilities = Cap.parse(self.conn.getCapabilities())
45
if not isinstance(capabilities, Cap.Capabilities):
46
raise ValueError(_("'capabilities' must be a "
47
"Capabilities instance."))
48
self._capabilities = capabilities
41
if not (self.conn or self._get_caps()):
50
42
raise ValueError(_("'conn' or 'capabilities' must be specified."))
52
44
# Set boot _boot_caps/_boot_parameters
53
45
if boot_index is None:
54
self._boot_caps = match_boots(self._capabilities,
46
self._boot_caps = match_boots(self._get_caps(),
55
47
self.image.domain.boots)
56
48
if self._boot_caps is None:
57
49
raise ImageInstallerException(_("Could not find suitable boot "
63
55
self._boot_caps = image.domain.boots[boot_index]
65
57
# Set up internal caps.guest object
66
self._guest = self._capabilities.guestForOSType(self.boot_caps.type,
58
self._guest = self._get_caps().guestForOSType(self.boot_caps.type,
68
60
if self._guest is None:
69
61
raise PlatformMatchException(_("Unsupported virtualization type: "
70
62
"%s %s" % (self.boot_caps.type,
95
87
# General Installer methods
97
def prepare(self, guest, meter, distro = None):
98
self._make_disks(guest)
89
def prepare(self, guest, meter):
100
94
for f in ['pae', 'acpi', 'apic']:
101
95
if self.boot_caps.features[f] & Cap.FEATURE_ON:
103
97
elif self.boot_caps.features[f] & Cap.FEATURE_OFF:
104
98
guest.features[f] = False
106
def get_install_xml(self, guest, isinstall):
108
kernel = { "kernel" : self.boot_caps.kernel,
109
"initrd" : self.boot_caps.initrd,
110
"extrargs" : self.boot_caps.cmdline }
112
if self.boot_caps.kernel:
117
# FYI: self.boot_caps.loader is _not_ analagous to guest loader tag
119
return self._get_osblob_helper(guest, isinstall=isinstall,
121
bootdev=self.boot_caps.bootdev)
100
self.bootconfig.kernel = self.boot_caps.kernel
101
self.bootconfig.initrd = self.boot_caps.initrd
102
self.bootconfig.kernel_args = self.boot_caps.cmdline
123
104
def post_install_check(self, guest):
107
def has_install_phase(self):
127
110
# Private methods
111
def _get_bootdev(self, isinstall, guest):
112
return self.boot_caps.bootdev
129
def _make_disks(self, guest):
130
for m in self.boot_caps.drives:
131
p = self._abspath(m.disk.file)
133
if m.disk.size is not None:
134
s = float(m.disk.size)/1024
114
def _make_disks(self):
115
for drive in self.boot_caps.drives:
116
path = self._abspath(drive.disk.file)
118
if drive.disk.size is not None:
119
size = float(drive.disk.size) / 1024
136
121
# FIXME: This is awkward; the image should be able to express
137
122
# whether the disk is expected to be there or not independently
138
123
# of its classification, especially for user disks
139
124
# FIXME: We ignore the target for the mapping in m.target
140
if (m.disk.use == ImageParser.Disk.USE_SYSTEM and
141
not os.path.exists(p)):
125
if (drive.disk.use == ImageParser.Disk.USE_SYSTEM and
126
not os.path.exists(path)):
142
127
raise ImageInstallerException(_("System disk %s does not exist")
144
130
device = VirtualDisk.DEVICE_DISK
145
if m.disk.format == ImageParser.Disk.FORMAT_ISO:
131
if drive.disk.format == ImageParser.Disk.FORMAT_ISO:
146
132
device = VirtualDisk.DEVICE_CDROM
147
d = VirtualDisk(p, s,
149
type = VirtualDisk.TYPE_FILE)
152
guest._add_install_dev(d)
135
disk = VirtualDisk(conn=self.conn,
139
format=drive.disk.format)
140
disk.target = drive.target
142
self.install_devices.append(disk)
154
144
def _abspath(self, p):
155
145
return self.image.abspath(p)