161
167
# Private helper methods
163
def _prepare_cdrom(self, guest, distro, meter):
169
def _prepare_cdrom(self, guest, meter):
170
transient = not self.livecd
164
171
if not self._location_is_path:
165
172
# Xen needs a boot.iso if its a http://, ftp://, or nfs: url
166
cdrom = OSDistro.acquireBootDisk(self.location,
168
scratchdir = self.scratchdir,
173
(store_ignore, os_type_ignore, os_variant_ignore, media) = \
174
OSDistro.acquireBootDisk(guest, self.location, meter,
170
178
self._tmpfiles.append(cdrom)
172
181
cdrom = self.location
174
self._install_disk = VirtualDisk(path=cdrom,
176
device=VirtualDisk.DEVICE_CDROM,
180
def _prepare_kernel_and_initrd(self, guest, distro, meter):
181
if self.boot is not None:
182
# Got a local kernel/initrd already
183
self.install["kernel"] = self.boot["kernel"]
184
self.install["initrd"] = self.boot["initrd"]
185
if not self.extraargs is None:
186
self.install["extraargs"] = self.extraargs
188
# Need to fetch the kernel & initrd from a remote site, or
189
# out of a loopback mounted disk image/device
191
((kernelfn, initrdfn, args),
192
os_type, os_variant) = OSDistro.acquireKernel(guest,
193
self.location, meter, guest.arch, scratchdir=self.scratchdir,
194
type=self.os_type, distro=distro)
196
if guest.get_os_autodetect():
198
logging.debug("Auto detected OS type as: %s" % os_type)
199
guest.os_type = os_type
201
if (os_variant and guest.os_type == os_type):
202
logging.debug("Auto detected OS variant as: %s" %
204
guest.os_variant = os_variant
206
self.install["kernel"] = kernelfn
207
self.install["initrd"] = initrdfn
208
self.install["extraargs"] = args
210
self._tmpfiles.append(kernelfn)
212
self._tmpfiles.append(initrdfn)
214
# If they're installing off a local file/device, we map it
215
# through to a virtual CD or disk
216
if (self.location is not None and self._location_is_path
217
and not os.path.isdir(self.location)):
183
disk = VirtualDisk(path=cdrom,
185
device=VirtualDisk.DEVICE_CDROM,
188
self.install_devices.append(disk)
190
def _perform_initrd_injections(self):
192
Insert files into the root directory of the initial ram disk
194
initrd = self._install_bootconfig.initrd
195
tempdir = tempfile.mkdtemp(dir=self.scratchdir)
196
os.chmod(tempdir, 0775)
198
for filename in self._initrd_injections:
199
logging.debug("Copying %s to the initrd." % filename)
200
shutil.copy(filename, tempdir)
202
logging.debug("Appending to the initrd.")
203
find_proc = subprocess.Popen(['find', '.', '-print0'],
204
stdout=subprocess.PIPE,
205
stderr=sys.stderr, cwd=tempdir)
206
cpio_proc = subprocess.Popen(['cpio', '-o', '--null', '-Hnewc', '--quiet'],
207
stdin=find_proc.stdout,
208
stdout=subprocess.PIPE,
209
stderr=sys.stderr, cwd=tempdir)
210
f = open(initrd, 'ab')
211
gzip_proc = subprocess.Popen(['gzip'], stdin=cpio_proc.stdout,
212
stdout=f, stderr=sys.stderr)
217
shutil.rmtree(tempdir)
219
def _prepare_kernel_and_initrd(self, guest, meter):
222
# If installing off a local path, map it through to a virtual CD/disk
223
if (self.location is not None and
224
self._location_is_path and
225
not os.path.isdir(self.location)):
218
226
device = VirtualDisk.DEVICE_DISK
219
227
if guest._lookup_osdict_key('pv_cdrom_install'):
220
228
device = VirtualDisk.DEVICE_CDROM
222
self._install_disk = VirtualDisk(conn=guest.conn,
230
disk = VirtualDisk(conn=guest.conn,
236
# Make sure we always fetch kernel here if required
237
if self._install_bootconfig.kernel and not self.scratchdir_required():
240
# Need to fetch the kernel & initrd from a remote site, or
241
# out of a loopback mounted disk image/device
242
ignore, os_type, os_variant, media = OSDistro.acquireKernel(guest,
243
self.location, meter,
246
(kernelfn, initrdfn, args) = media
248
if guest.get_os_autodetect():
250
logging.debug("Auto detected OS type as: %s" % os_type)
251
guest.os_type = os_type
253
if (os_variant and guest.os_type == os_type):
254
logging.debug("Auto detected OS variant as: %s" % os_variant)
255
guest.os_variant = os_variant
257
self._install_bootconfig.kernel = kernelfn
258
self._install_bootconfig.initrd = initrdfn
259
self._install_bootconfig.kernel_args = args
261
self._tmpfiles.append(kernelfn)
263
self._tmpfiles.append(initrdfn)
265
if self._initrd_injections:
266
self._perform_initrd_injections()
270
def _persistent_cd(self):
271
return (self._location_is_path and self.cdrom and self.livecd)
273
def _get_bootdev(self, isinstall, guest):
274
if isinstall or self._persistent_cd():
275
bootdev = self.bootconfig.BOOT_DEVICE_CDROM
277
bootdev = self.bootconfig.BOOT_DEVICE_HARDDISK
228
280
# General Installer methods
230
282
def scratchdir_required(self):
231
return bool(not self._location_is_path)
233
def prepare(self, guest, meter, distro = None):
283
if not self.location:
286
is_url = not self._location_is_path
287
mount_dvd = self._location_is_path and not self.cdrom
289
return bool(is_url or mount_dvd)
291
def prepare(self, guest, meter):
243
296
if self.location:
244
self._prepare_cdrom(guest, distro, meter)
297
dev = self._prepare_cdrom(guest, meter)
246
299
# Booting from a cdrom directly allocated to the guest
249
self._prepare_kernel_and_initrd(guest, distro, meter)
251
def get_install_xml(self, guest, isinstall):
302
dev = self._prepare_kernel_and_initrd(guest, meter)
305
self.install_devices.append(dev)
307
def check_location(self):
308
if self._location_is_path:
309
# We already mostly validated this
257
return self._get_osblob_helper(isinstall=isinstall, guest=guest,
258
kernel=self.install, bootdev=bootdev)
312
# This will throw an error for us
313
OSDistro.detectMediaDistro(location=self.location, arch=self.arch)
260
316
def detect_distro(self):